X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2FEditor.lpr;h=052fbb8208ff350fd50036d09ce796b92bd4459e;hb=9d717c612a7756b30839103d1d6e8d89e2596393;hp=3889b5109fd514598830302435c888ccfe509be8;hpb=91e1fe7e58aec7404a6029cb757dbe27677ebbb6;p=d2df-editor.git diff --git a/src/editor/Editor.lpr b/src/editor/Editor.lpr index 3889b51..052fbb8 100644 --- a/src/editor/Editor.lpr +++ b/src/editor/Editor.lpr @@ -52,6 +52,7 @@ uses ImagingTypes, Imaging, ImagingUtility, + g_options in 'g_options.pas', g_language in 'g_language.pas', f_selectlang in 'f_selectlang.pas' {SelectLanguageForm}; @@ -65,7 +66,8 @@ uses end; var - H: THandlerObject; + LogFileName: AnsiString = ''; + ParamFileIndex: Integer = 1; procedure THandlerObject.ExceptionHandler (Sender: TObject; e: Exception); begin @@ -73,17 +75,72 @@ uses MessageDlg('Unhandled exception: ' + e.message + ' (see Editor.log for more information)', mtError, [mbOK], 0); end; + procedure CheckParamOptions; + var i: Integer; p: AnsiString; + begin + i := 1; + while (i <= ParamCount) and (Length(ParamStr(i)) > 0) and (ParamStr(i)[1] = '-') do + begin + p := ParamStr(i); + if p = '--log-file' then + begin + if i + 1 <= ParamCount then + begin + Inc(i); + LogFileName := ParamStr(i); + end; + end + else if p = '--config' then + begin + if i + 1 <= ParamCount then + begin + Inc(i); + CfgFileName := ParamStr(i); + end; + end; + Inc(i); + end; + ParamFileIndex := i; + end; + + procedure CheckParamFiles; + var i: Integer; path: AnsiString; + begin + i := ParamFileIndex; + if i <= ParamCount then + begin + path := ParamStr(i); + if path <> '' then + OpenMap(path, ''); + end; + end; + + procedure InitLogs; + begin + if LogFileName = '' then + LogFileName := 'Editor.log'; + + if LogFileName <> '' then + e_InitLog(LogFileName, WM_NEWFILE); + + {$IF DECLARED(UseHeapTrace)} + (* http://wiki.freepascal.org/heaptrc *) + GlobalSkipIfNoLeaks := True; + //SetHeapTraceOutput('EditorLeaks.log'); + //HaltOnError := False; + {$ENDIF} + end; + begin Application.ExceptionDialog := aedOkMessageBox; - Application.AddOnExceptionHandler(H.ExceptionHandler, True); + Application.AddOnExceptionHandler(THandlerObject.ExceptionHandler, True); Application.Initialize(); -{$IF DECLARED(UseHeapTrace)} - (* http://wiki.freepascal.org/heaptrc *) - GlobalSkipIfNoLeaks := True; - //SetHeapTraceOutput('EditorLeaks.log'); - //HaltOnError := False; -{$ENDIF} + EditorDir := ExtractFilePath(Application.ExeName); + CfgFileName := EditorDir + DirectorySeparator + 'Editor.cfg'; + + CheckParamOptions; + InitLogs; Application.CreateForm(TMainForm, MainForm); Application.CreateForm(TOptionsForm, OptionsForm); @@ -105,6 +162,7 @@ begin Application.CreateForm(TChooseTypeForm, ChooseTypeForm); Application.CreateForm(TSelectLanguageForm, SelectLanguageForm); - if ParamStr(1) <> '' then OpenMap(ParamStr(1), ''); + CheckParamFiles; + Application.Run(); end.