Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

マルチユーザー設定ファイルの不具合修正 #1865

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sakura_core/_main/CControlProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ std::filesystem::path CControlProcess::GetIniFileName() const
*/
std::filesystem::path CControlProcess::GetPrivateIniFileName(const std::wstring& exeIniPath, const std::wstring& filename) const
{
const auto nFolder = ::GetPrivateProfileInt(L"Settings", L"UserRootFolder", 0, exeIniPath.c_str());
KNOWNFOLDERID refFolderId;
switch (int nFolder = ::GetPrivateProfileInt(L"Settings", L"UserRootFolder", 0, exeIniPath.c_str())) {
switch (nFolder) {
case 1:
case 3:
refFolderId = FOLDERID_Profile; // ユーザーのルートフォルダー
break;
case 2:
refFolderId = FOLDERID_Documents; // ユーザーのドキュメントフォルダー
break;
case 3:
refFolderId = FOLDERID_Desktop; // ユーザーのデスクトップフォルダー
break;

default:
refFolderId = FOLDERID_RoamingAppData; // ユーザーのアプリケーションデータフォルダー
break;
}

PWSTR pFolderPath = nullptr;
::SHGetKnownFolderPath(refFolderId, KF_FLAG_DEFAULT, nullptr, &pFolderPath);
::SHGetKnownFolderPath(refFolderId, KF_FLAG_DEFAULT_PATH, NULL, &pFolderPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第二引数を変更して、取得されるパスがユーザー設定の変更を受けないようにしています。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ne-shlobj_core-known_folder_flag

を見ると下記のように書かれていたので、きっとそれでユーザー設定の変更を受けないデフォルトのパスってことなんですね。

KF_FLAG_DEFAULT_PATH
Value: 0x00000400
0x00000400. Gets the default path for a known folder. If this flag is not set, the function retrieves the current—and possibly redirected—path of the folder. The execution of this flag includes a verification of the folder's existence unless KF_FLAG_DONT_VERIFY is set.

std::filesystem::path privateIniPath(pFolderPath);
::CoTaskMemFree(pFolderPath);

Expand All @@ -92,6 +92,9 @@ std::filesystem::path CControlProcess::GetPrivateIniFileName(const std::wstring&
{
subFolder = L"sakura";
}
if (nFolder == 3) {
privateIniPath.append("Desktop");
}
privateIniPath.append(subFolder);

if (const auto* pCommandLine = CCommandLine::getInstance(); pCommandLine->IsSetProfile() && *pCommandLine->GetProfileName()) {
Expand Down