protected function getUserHomeDir()
    {
        // getenv('HOME') isn't set on Windows.
        $home = getenv('HOME');
        if (!empty($home)) {
            // home should never end with a trailing slash.
            return rtrim($home, '/');
        }
        if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
            // home on windows
            $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
            // If HOMEPATH is a root directory the path can end with a slash.
            // Make sure that doesn't happen.
            return rtrim($home, '\\/');
        }

        throw new \Exception('Could not determine the current user\'s home directory.');
    }