/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
# include <windows.h> # include <stdlib.h> # include <stdio.h> # include <string.h> # include <direct.h> # include <shlobj.h> # include <knownfolders.h> # include <guiddef.h>
#elifdefined(XP_UNIX)
# include <limits.h> # include <unistd.h> # include <stdlib.h> # include <sys/param.h> # include "prenv.h" # ifdefined(MOZ_WIDGET_COCOA) # include "CFTypeRefPtr.h" # include "CocoaFileUtils.h" # endif # ifdefined(MOZ_WIDGET_GTK) # include "mozilla/WidgetUtilsGtk.h" # endif
/** * Provides a fallback for getting the path to APPDATA or LOCALAPPDATA by * querying the registry when the call to SHGetSpecialFolderPathW is unable to * provide these paths (Bug 513958).
*/ static nsresult GetRegWindowsAppDataFolder(bool aLocal, nsIFile** aFile) {
HKEY key;
LPCWSTR keyName =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName, 0, KEY_READ, &key); if (res != ERROR_SUCCESS) { return NS_ERROR_FAILURE;
}
WCHAR path[MAX_PATH + 2];
DWORD type, size;
res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"), nullptr,
&type, (LPBYTE)&path, &size);
::RegCloseKey(key); // The call to RegQueryValueExW must succeed, the type must be REG_SZ, the // buffer size must not equal 0, and the buffer size be a multiple of 2. if (res != ERROR_SUCCESS || type != REG_SZ || size == 0 || size % 2 != 0) { return NS_ERROR_FAILURE;
}
// Append the trailing slash int len = wcslen(path); if (len > 1 && path[len - 1] != L'\\') {
path[len] = L'\\';
path[++len] = L'\0';
}
#ifdefined(XP_UNIX) static nsresult GetUnixHomeDir(nsIFile** aFile) { # ifdefined(ANDROID) // XXX no home dir on android; maybe we should return the sdcard if present? return NS_ERROR_FAILURE; # else return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), aFile); # endif
}
nsDependentCString sysConfigDir; if (PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR")) { constchar* mozSystemConfigDir = PR_GetEnv("MOZ_SYSTEM_CONFIG_DIR"); if (mozSystemConfigDir) {
sysConfigDir.Assign(nsDependentCString(mozSystemConfigDir));
}
} # ifdefined(MOZ_WIDGET_GTK) if (sysConfigDir.IsEmpty() && mozilla::widget::IsRunningUnderFlatpak()) {
sysConfigDir.Assign(nsLiteralCString("/app/etc"));
} # endif if (sysConfigDir.IsEmpty()) {
sysConfigDir.Assign(nsLiteralCString("/etc"));
}
MOZ_TRY(NS_NewNativeLocalFile(sysConfigDir, aFile));
MOZ_TRY((*aFile)->AppendNative(appName)); return NS_OK; # endif
}
/* The following license applies to the xdg_user_dir_lookup function:
Copyright (c) 2007 Red Hat, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
rv = file->Exists(&exists); if (NS_FAILED(rv)) { return rv;
}
if (!exists) {
rv = file->Create(nsIFile::DIRECTORY_TYPE, 0755); if (NS_FAILED(rv)) { return rv;
}
}
} elseif (Unix_XDG_Desktop == aSystemDirectory) { // for the XDG desktop dir, fall back to HOME/Desktop // (for historical compatibility)
nsCOMPtr<nsIFile> home;
rv = GetUnixHomeDir(getter_AddRefs(home)); if (NS_FAILED(rv)) { return rv;
}
rv = home->Clone(getter_AddRefs(file)); if (NS_FAILED(rv)) { return rv;
}
rv = file->AppendNative("Desktop"_ns); if (NS_FAILED(rv)) { return rv;
}
rv = file->Exists(&exists); if (NS_FAILED(rv)) { return rv;
}
// fallback to HOME only if HOME/Desktop doesn't exist if (!exists) {
file = home;
}
} else { // no fallback for the other XDG dirs return NS_ERROR_FAILURE;
}
case Win_ProgramFiles: { return GetWindowsFolder(CSIDL_PROGRAM_FILES, aFile);
}
case Win_HomeDirectory: {
nsresult rv = GetWindowsFolder(CSIDL_PROFILE, aFile); if (NS_SUCCEEDED(rv)) { return rv;
}
int32_t len; if ((len = ::GetEnvironmentVariableW(L"HOME", path, MAX_PATH)) > 0) { // Need enough space to add the trailing backslash if (len > MAX_PATH - 2) { break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.