Skip to content

Commit

Permalink
Merge 3cf4762 into d1bd398
Browse files Browse the repository at this point in the history
  • Loading branch information
sanomari authored Jan 23, 2021
2 parents d1bd398 + 3cf4762 commit 8cb93e0
Show file tree
Hide file tree
Showing 22 changed files with 595 additions and 216 deletions.
64 changes: 64 additions & 0 deletions sakura_core/_main/CControlProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,70 @@

//-------------------------------------------------

std::filesystem::path CControlProcess::GetIniFileName() const
{
auto privateIniFile = CProcess::GetIniFileName();
if (privateIniFile.empty()) {
return GetPrivateIniFileName();
}
return privateIniFile;
}

std::filesystem::path CControlProcess::GetPrivateIniFileName() const
{
// exe基準のiniファイルパスを得る
auto iniPath = GetExeFileName().replace_extension(L".ini");

// マルチユーザ用のiniファイルパス
// exeと同じフォルダに置かれたマルチユーザ構成設定ファイル(sakura.exe.ini)の内容
// に従ってマルチユーザ用のiniファイルパスを決める
std::filesystem::path privateIniPath;
auto exeIniPath = GetExeFileName().concat(L".ini");
if (bool isMultiUserSeggings = ::GetPrivateProfileInt(L"Settings", L"MultiUser", 0, exeIniPath.c_str()); isMultiUserSeggings) {
KNOWNFOLDERID refFolderId;
switch (int nFolder = ::GetPrivateProfileInt(L"Settings", L"UserRootFolder", 0, exeIniPath.c_str())) {
case 1:
refFolderId = FOLDERID_Profile; // ユーザのルートフォルダ
break;
case 2:
refFolderId = FOLDERID_Documents; // ユーザのドキュメントフォルダ
break;
case 3:
refFolderId = FOLDERID_Desktop; // ユーザのデスクトップフォルダ
break;
default:
refFolderId = FOLDERID_RoamingAppData; // ユーザのアプリケーションデータフォルダ
break;
}

PWSTR pFolderPath = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(refFolderId, KF_FLAG_DEFAULT, nullptr, &pFolderPath)))
{
privateIniPath.assign(pFolderPath);
}
::CoTaskMemFree(pFolderPath);

if (!privateIniPath.empty())
{
std::wstring subFolder(_MAX_DIR, L'\0');
::GetPrivateProfileString(L"Settings", L"UserSubFolder", L"sakura", subFolder.data(), (DWORD)subFolder.capacity(), exeIniPath.c_str());
if (!subFolder.empty())
{
privateIniPath.append(subFolder);
}
}
}

if (privateIniPath.empty()) {
privateIniPath = iniPath.parent_path();
}

if (const auto* pCommandLine = CCommandLine::getInstance(); pCommandLine && pCommandLine->IsSetProfile() && *pCommandLine->GetProfileName()) {
privateIniPath.append(pCommandLine->GetProfileName());
}
return privateIniPath.append(iniPath.filename().c_str());
}

/*!
@brief コントロールプロセスを初期化する
Expand Down
7 changes: 7 additions & 0 deletions sakura_core/_main/CControlProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define SAKURA_CCONTROLPROCESS_AFB90808_4287_4A11_B7FB_9CD21CF8BFD6_H_
#pragma once

#include <filesystem>

#include "global.h"
#include "CProcess.h"

Expand Down Expand Up @@ -43,13 +45,18 @@ class CControlProcess final : public CProcess {
{}

~CControlProcess();

std::filesystem::path GetIniFileName() const override;

protected:
CControlProcess();
bool InitializeProcess() override;
bool MainLoop() override;
void OnExitProcess() override;

private:
std::filesystem::path GetPrivateIniFileName() const;

HANDLE m_hMutex; //!< アプリケーション実行検出用ミューテックス
HANDLE m_hMutexCP; //!< コントロールプロセスミューテックス
HANDLE m_hEventCPInitialized; //!< コントロールプロセス初期化完了イベント 2006.04.10 ryoji
Expand Down
9 changes: 9 additions & 0 deletions sakura_core/_main/CProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ CProcess::CProcess(
m_pcShareData = CShareData::getInstance();
}

std::filesystem::path CProcess::GetIniFileName() const
{
if (m_pcShareData->IsInitialized()) {
const DLLSHAREDATA *pShareData = &GetDllShareData();
return pShareData->m_szPrivateIniFile.c_str();
}
return std::filesystem::path();
}

/*!
@brief プロセスを初期化する
Expand Down
6 changes: 6 additions & 0 deletions sakura_core/_main/CProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#define SAKURA_CPROCESS_FECC5450_9096_4EAD_A6DA_C8B12C3A31B5_H_
#pragma once

#include <filesystem>

#include "global.h"
#include "util/design_template.h"
#include "env/CShareData.h"
#include "env/DLLSHAREDATA.h"

Expand All @@ -36,6 +39,9 @@ class CProcess : public TSingleInstance<CProcess> {
bool Run();
virtual ~CProcess(){}
virtual void RefreshString();

virtual std::filesystem::path GetIniFileName() const;

protected:
CProcess();
virtual bool InitializeProcess();
Expand Down
5 changes: 4 additions & 1 deletion sakura_core/config/system_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,15 @@
Version 176:
MYDEVMODE の未使用メンバを削除した為、PRINTSETTING や DLLSHAREDATA のメモリレイアウトが変更
Version 177:
WriteQuit廃止に伴い未使用となった IniFolder のメンバを削除した為、DLLSHAREDATA のメモリレイアウトが変更
-- 統合されたので元に戻す(1000~1023が使用済み) 2008.11.16 nasukoji
-- Version 1000:
-- バージョン1000以降を本家統合までの間、使わせてください。かなり頻繁に構成が変更されると思われるので。by kobake 2008.03.02
*/
#define N_SHAREDATA_VERSION 176
constexpr unsigned N_SHAREDATA_VERSION = 177;
#define STR_SHAREDATA_VERSION NUM_TO_STR(N_SHAREDATA_VERSION)
#define GSTR_SHAREDATA (L"SakuraShareData" _T(CON_SKR_MACHINE_SUFFIX_) _T(_CODE_SUFFIX_) _T(_DEBUG_SUFFIX_) _T(STR_SHAREDATA_VERSION))

Expand Down
45 changes: 17 additions & 28 deletions sakura_core/dlg/CDlgProfileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,25 @@ int CDlgProfileMgr::DoModal( HINSTANCE hInstance, HWND hwndParent, LPARAM lParam
return (int)CDialog::DoModal( hInstance, hwndParent, IDD_PROFILEMGR, lParam );
}

static std::wstring GetProfileMgrFileName(LPCWSTR profName = NULL)
std::filesystem::path GetProfileMgrFileName()
{
static WCHAR szPath[_MAX_PATH];
static WCHAR szPath2[_MAX_PATH];
static WCHAR* pszPath;
static bool bSet = false;
if( bSet == false ){
pszPath = szPath;
CFileNameManager::GetIniFileNameDirect( szPath, szPath2, L"" );
if( szPath[0] == L'\0' ){
pszPath = szPath2;
}
bSet = true;
}

WCHAR szDir[_MAX_PATH];
SplitPath_FolderAndFile( pszPath, szDir, NULL );

WCHAR szIniFile[_MAX_PATH];
if( profName == NULL ){
WCHAR szExePath[_MAX_PATH];
WCHAR szFname[_MAX_FNAME];
::GetModuleFileName( NULL, szExePath, _countof(szExePath) );
_wsplitpath( szExePath, NULL, NULL, szFname, NULL );
auto_snprintf_s( szIniFile, _MAX_PATH - 1, L"%s\\%s_prof%s", szDir, szFname, L".ini" );
}else{
auto_snprintf_s( szIniFile, _MAX_PATH - 1, L"%s\\%s", szDir, profName );
}
// プロファイルマネージャ設定ファイルのパスを生成
return GetIniFileName().replace_extension().concat(L"_prof.ini");
}

return szIniFile;
std::filesystem::path GetProfileDirectory(const std::wstring& name)
{
return GetExeFileName().parent_path().append(name).append(L"a.txt").remove_filename();
}

/*!
既存コード互換用関数
指定したプロファイルの設定保存先ディレクトリを返す。
*/
[[nodiscard]]
std::wstring GetProfileMgrFileName(const std::wstring_view& name)
{
return GetProfileDirectory(name.data());
}

/*! ダイアログデータの設定 */
Expand Down
8 changes: 8 additions & 0 deletions sakura_core/dlg/CDlgProfileMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "dlg/CDialog.h"
#include "_main/CCommandLine.h"
#include <string>
#include <string_view>
#include <vector>

struct SProfileSettings
Expand Down Expand Up @@ -82,4 +83,11 @@ class CDlgProfileMgr final : public CDialog
static bool ReadProfSettings(SProfileSettings& settings);
static bool WriteProfSettings(SProfileSettings& settings);
};

std::filesystem::path GetProfileMgrFileName();
std::filesystem::path GetProfileDirectory(const std::wstring& name);

[[nodiscard]]
std::wstring GetProfileMgrFileName(const std::wstring_view& name);

#endif /* SAKURA_CDLGPROFILEMGR_E77A329C_4D06_436A_84E3_01B4D8F34A9A_H_ */
102 changes: 0 additions & 102 deletions sakura_core/env/CFileNameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/

#include "StdAfx.h"
#include <ShlObj.h> //CSIDL_PROFILE等

#include "DLLSHAREDATA.h"
#include "CFileNameManager.h"
Expand All @@ -38,7 +37,6 @@
#include "util/string_ex2.h"
#include "util/file.h"
#include "util/window.h"
#include "_main/CCommandLine.h"

// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
// ファイル名管理 //
Expand Down Expand Up @@ -481,103 +479,3 @@ bool CFileNameManager::GetMenuFullLabel(
);
return 0 < ret;
}

/**
構成設定ファイルからiniファイル名を取得する
sakura.exe.iniからsakura.iniの格納フォルダを取得し、フルパス名を返す
@param[out] pszPrivateIniFile マルチユーザ用のiniファイルパス
@param[out] pszIniFile EXE基準のiniファイルパス
@author ryoji
@date 2007.09.04 ryoji 新規作成
@date 2008.05.05 novice GetModuleHandle(NULL)→NULLに変更
*/
void CFileNameManager::GetIniFileNameDirect( LPWSTR pszPrivateIniFile, LPWSTR pszIniFile, LPCWSTR pszProfName )
{
WCHAR szPath[_MAX_PATH];
WCHAR szDrive[_MAX_DRIVE];
WCHAR szDir[_MAX_DIR];
WCHAR szFname[_MAX_FNAME];
WCHAR szExt[_MAX_EXT];

::GetModuleFileName(
NULL,
szPath, _countof(szPath)
);
_wsplitpath( szPath, szDrive, szDir, szFname, szExt );

if( pszProfName[0] == '\0' ){
auto_snprintf_s( pszIniFile, _MAX_PATH - 1, L"%s%s%s%s", szDrive, szDir, szFname, L".ini" );
}else{
auto_snprintf_s( pszIniFile, _MAX_PATH - 1, L"%s%s%s\\%s%s", szDrive, szDir, pszProfName, szFname, L".ini" );
}

// マルチユーザ用のiniファイルパス
// exeと同じフォルダに置かれたマルチユーザ構成設定ファイル(sakura.exe.ini)の内容
// に従ってマルチユーザ用のiniファイルパスを決める
pszPrivateIniFile[0] = L'\0';
{
auto_snprintf_s( szPath, _MAX_PATH - 1, L"%s%s%s%s", szDrive, szDir, szFname, L".exe.ini" );
int nEnable = ::GetPrivateProfileInt(L"Settings", L"MultiUser", 0, szPath );
if( nEnable ){
int nFolder = ::GetPrivateProfileInt(L"Settings", L"UserRootFolder", 0, szPath );
switch( nFolder ){
case 1:
nFolder = CSIDL_PROFILE; // ユーザのルートフォルダ
break;
case 2:
nFolder = CSIDL_PERSONAL; // ユーザのドキュメントフォルダ
break;
case 3:
nFolder = CSIDL_DESKTOPDIRECTORY; // ユーザのデスクトップフォルダ
break;
default:
nFolder = CSIDL_APPDATA; // ユーザのアプリケーションデータフォルダ
break;
}
::GetPrivateProfileString(L"Settings", L"UserSubFolder", L"sakura", szDir, _MAX_DIR, szPath );
if( szDir[0] == L'\0' )
::lstrcpy( szDir, L"sakura" );
if( GetSpecialFolderPath( nFolder, szPath ) ){
if( pszProfName[0] == '\0' ){
auto_snprintf_s( pszPrivateIniFile, _MAX_PATH - 1, L"%s\\%s\\%s%s", szPath, szDir, szFname, L".ini" );
}else{
auto_snprintf_s( pszPrivateIniFile, _MAX_PATH - 1, L"%s\\%s\\%s\\%s%s", szPath, szDir, pszProfName, szFname, L".ini" );
}
}
}
}
}

/**
iniファイル名の取得
共有データからsakura.iniの格納フォルダを取得し、フルパス名を返す
(共有データ未設定のときは共有データ設定を行う)
@param[out] pszIniFileName iniファイル名(フルパス)
@param[in] bRead true: 読み込み / false: 書き込み
@author ryoji
@date 2007.05.19 ryoji 新規作成
*/
void CFileNameManager::GetIniFileName( LPWSTR pszIniFileName, LPCWSTR pszProfName, BOOL bRead/*=FALSE*/ )
{
auto &iniFolder = m_pShareData->m_sFileNameManagement.m_IniFolder;
if( !iniFolder.m_bInit ){
iniFolder.m_bInit = true; // 初期化済フラグ
iniFolder.m_bReadPrivate = false; // マルチユーザ用iniからの読み出しフラグ
iniFolder.m_bWritePrivate = false; // マルチユーザ用iniへの書き込みフラグ

GetIniFileNameDirect( iniFolder.m_szPrivateIniFile, iniFolder.m_szIniFile, pszProfName );
if( iniFolder.m_szPrivateIniFile[0] != L'\0' ){
iniFolder.m_bReadPrivate = true;
iniFolder.m_bWritePrivate = true;
}
}

bool bPrivate = bRead ? iniFolder.m_bReadPrivate : iniFolder.m_bWritePrivate;
::lstrcpy( pszIniFileName, bPrivate ? iniFolder.m_szPrivateIniFile : iniFolder.m_szIniFile );
}
17 changes: 0 additions & 17 deletions sakura_core/env/CFileNameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@

struct EditInfo;

//! iniフォルダ設定 // 2007.05.31 ryoji
struct IniFolder {
bool m_bInit; // 初期化済フラグ
bool m_bReadPrivate; // マルチユーザ用iniからの読み出しフラグ
bool m_bWritePrivate; // マルチユーザ用iniへの書き込みフラグ
WCHAR m_szIniFile[_MAX_PATH]; // EXE基準のiniファイルパス
WCHAR m_szPrivateIniFile[_MAX_PATH]; // マルチユーザ用のiniファイルパス
}; /* iniフォルダ設定 */

//共有メモリ内構造体
struct SShare_FileNameManagement{
IniFolder m_IniFolder; /**** iniフォルダ設定 ****/
};

//!ファイル名管理
class CFileNameManager : public TSingleton<CFileNameManager>{
friend class TSingleton<CFileNameManager>;
Expand Down Expand Up @@ -89,9 +75,6 @@ class CFileNameManager : public TSingleton<CFileNameManager>{

static WCHAR GetAccessKeyByIndex(int index, bool bZeroOrigin);

static void GetIniFileNameDirect( LPWSTR pszPrivateIniFile, LPWSTR pszIniFile, LPCWSTR pszProfName ); /* 構成設定ファイルからiniファイル名を取得する */ // 2007.09.04 ryoji
void GetIniFileName( LPWSTR pszIniFileName, LPCWSTR pszProfName, BOOL bRead = FALSE ); /* iniファイル名の取得 */ // 2007.05.19 ryoji

private:
DLLSHAREDATA* m_pShareData;

Expand Down
Loading

0 comments on commit 8cb93e0

Please sign in to comment.