OSDN Git Service

Add /inifile command line option
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 11 Jul 2021 09:13:01 +0000 (18:13 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 11 Jul 2021 09:13:01 +0000 (18:13 +0900)
Docs/Manual/EN/Command_line.xml
Docs/Manual/JP/Command_line.xml
Src/Merge.cpp
Src/MergeCmdLineInfo.cpp
Src/MergeCmdLineInfo.h

index a592874..15d8d5b 100644 (file)
       <arg choice="opt" rep="norepeat"><option>/cfg</option>
       <replaceable>name=value</replaceable></arg>
 
+      <arg choice="opt" rep="norepeat"><option>/inifile</option>
+      <replaceable>inifile</replaceable></arg>
+
       <arg choice="plain"
       rep="norepeat"><replaceable>leftpath</replaceable></arg>
 
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <indexterm>
+        <primary>ini file</primary>
+        <secondary>specifying on command line</secondary>
+      </indexterm>
+
+      <term><option>/inifile <replaceable>inifile</replaceable></option></term>
+      <listitem>
+        <para>specifies an INI file used to load and save settings instead of the registry.</para>
+      </listitem>
+    </varlistentry>
+
   </variablelist>
 </article>
index 29b1949..81a8efe 100644 (file)
       <arg choice="opt" rep="norepeat"><option>/cfg</option>
       <replaceable>name=value</replaceable></arg>
 
+      <arg choice="opt" rep="norepeat"><option>/inifile</option>
+      <replaceable>inifile</replaceable></arg>
+
       <arg choice="plain"
       rep="norepeat"><replaceable>leftpath</replaceable></arg>
 
     </varlistentry>
 
     <varlistentry>
-     <term><option>/dm</option></term>
+      <term><option>/dm</option></term>
       <listitem>
         <para><option>/dl</option>と同様に中央タイトルバーの説明を指定します。
        </para>
     </varlistentry>
 
     <varlistentry>
-     <term><option>/dr</option></term>
+      <term><option>/dr</option></term>
       <listitem>
         <para><option>/dl</option>と同様に右側タイトルバーの説明を指定します。
        </para>
       </listitem>
     </varlistentry>
 
+    <varlistentry>
+      <indexterm>
+        <primary>ini ファイル</primary>
+        <secondary>コマンドラインでの指定</secondary>
+      </indexterm>
+
+      <term><option>/inifile <replaceable>inifile</replaceable></option></term>
+      <listitem>
+        <para>レジストリの代わりに設定の読み込みと保存に使用するINIファイルを指定します。</para>
+      </listitem>
+    </varlistentry>
+
   </variablelist>
 </article>
index a9410f6..0f9d54c 100644 (file)
@@ -100,7 +100,7 @@ CMergeApp::CMergeApp() :
 , m_mainThreadScripts(nullptr)
 , m_nLastCompareResult(0)
 , m_bNonInteractive(false)
-, m_pOptions(CreateOptionManager())
+, m_pOptions(nullptr)
 , m_pGlobalFileFilter(new FileFilterHelper())
 , m_nActiveOperations(0)
 , m_pLangDlg(new CLanguageSelect())
@@ -121,17 +121,18 @@ CMergeApp::CMergeApp() :
  * @return IniOptionsMgr if initial config file exists,
  *   CRegOptionsMgr otherwise.
  */
-COptionsMgr *CreateOptionManager()
+COptionsMgr *CreateOptionManager(const MergeCmdLineInfo& cmdInfo)
 {
-       String iniFilePath = paths::ConcatPath(env::GetProgPath(), _T("winmerge.ini"));
-       if (paths::DoesPathExist(iniFilePath) == paths::IS_EXISTING_FILE)
+       String iniFilePath = cmdInfo.m_sIniFilepath;
+       if (!iniFilePath.empty())
        {
-               return new CIniOptionsMgr(iniFilePath);
-       }
-       else
-       {
-               return new CRegOptionsMgr();
+               if (paths::CreateIfNeeded(paths::GetParentPath(iniFilePath)))
+                       return new CIniOptionsMgr(iniFilePath);
        }
+       iniFilePath = paths::ConcatPath(env::GetProgPath(), _T("winmerge.ini"));
+       if (paths::DoesPathExist(iniFilePath) == paths::IS_EXISTING_FILE)
+               return new CIniOptionsMgr(iniFilePath);
+       return new CRegOptionsMgr();
 }
 
 CMergeApp::~CMergeApp()
@@ -210,6 +211,7 @@ BOOL CMergeApp::InitInstance()
 #else
        MergeCmdLineInfo cmdInfo(GetCommandLine());
 #endif
+       m_pOptions.reset(CreateOptionManager(cmdInfo));
        if (cmdInfo.m_bNoPrefs)
                m_pOptions->SetSerializing(false); // Turn off serializing to registry.
 
index 46d0e83..db138e5 100644 (file)
@@ -424,6 +424,10 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                {
                        q = SetConfig(q);
                }
+               else if (param == _T("inifile"))
+               {
+                       q = EatParam(q, m_sIniFilepath);
+               }
                else
                {
                        m_sErrorMessages.push_back(_T("Unknown option '/") + param + _T("'"));
index 7d54398..68cf101 100644 (file)
@@ -80,6 +80,8 @@ public:
        String m_sOutputpath;
        String m_sReportFile;
 
+       String m_sIniFilepath;
+
        PathContext m_Files; /**< Files (or directories) to compare. */
 
        std::map<String, String> m_Options;