<commit_before>unit kn_ConfigMng;

(****** LICENSE INFORMATION **************************************************
 
 - 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/.           
 
------------------------------------------------------------------------------
 (c) 2000-2005 <NAME> <<EMAIL>> (Poland)
 (c) 2007-2015 <NAME> <<EMAIL>> (Spain) [^]

 [^]: Changes since v. 1.7.0. Fore more information, please see 'README.md'
     and 'doc/README_SourceCode.txt' in https://github.com/dpradov/keynote-nf      
   
 *****************************************************************************) 

interface

    // config management
    procedure ReadCmdLine;
    procedure SaveOptions;
    procedure ReadOptions;
    procedure LoadToolbars;
    procedure SaveToolbars;
    procedure SaveDefaults;
    procedure LoadDefaults;
    procedure ReadFuncKeys;
    procedure SaveFuncKeys;
    procedure AdjustOptions;
//    procedure SetupToolbarButtons;
//    procedure ResolveToolbarRTFv3Dependencies;
    function LoadCustomKeyboard : boolean;
    procedure CustomizeKeyboard;


implementation

uses
   Windows, Forms, Classes, Controls, Dialogs, Menus, IniFiles, SysUtils,
   TB97Ctls, TB97Tlbr,
   kn_Main, dll_Keyboard, kn_Dllmng, kn_DLLinterface, gf_files,
   kn_global, kn_Info, kn_INI, kn_Const, kn_OptionsNew, kn_Chest,
   kn_FindReplaceMng, kn_MacroMng, kn_VCLControlsMng, kn_LanguagesMng,
   TntSysUtils;

resourcestring
  STR_KeybdError = 'Error in keyboard customization procedure: ';
  STR_TabIcons = ' Customize Tab icons (%s) ';


procedure ReadCmdLine;
var
  i : integer;
  s, ext, errstr : string;
begin
  errstr := '';
  for i := 1 to ParamCount do
  begin
    s := ansilowercase( ParamStr( i ));
    case s[1] of
      '-', '/' : begin // assume switch { BUG: if a filename begins with '-', we're screwed }
        delete( s, 1, 1 );


        if ( s = swMinimize ) then
          opt_Minimize := true
        else
        if ( s = swSetup ) then
          opt_Setup := true
        else
        if ( s = swDebug ) then
          opt_Debug := true
        else
        if ( s = swNoReadOpt ) then
          opt_NoReadOpt := true
        else
        if ( s = swNoSaveOpt ) then
          opt_NoSaveOpt := true
        else
        if ( s = swNoDefaults ) then
          opt_NoDefaults := true
        else
        if ( s = swNoReg ) then
          opt_NoRegistry := true
        else
        if ( s = swRegExt ) then
          opt_RegExt := true
        else
        if ( s = swSaveDefIcn ) then
          opt_SaveDefaultIcons := true
        else
        if ( s = swSaveToolbars ) then
          opt_SaveToolbars := true
        else
        if ( s = swSaveMenus ) then
          opt_SaveMenus := true
        else
        if ( s = swNoUserIcn ) then
          opt_NoUserIcons := true
        else
        if ( s = swUseOldFormat ) then
          _USE_OLD_KEYNOTE_FILE_FORMAT := true // GLOBAL var, used by TTabNote and TNoteFile
        else
        if ( s = swClean ) then
          opt_Clean := true
        else
        begin
          errstr := errstr + #13 + ParamStr( i );
        end;
      end;
      else
      begin
        // not a switch, so it's a filename.
        // Let's see what kind of file.
        ext := extractfileext( s );
        s:= GetAbsolutePath(WideExtractFilePath(Application.ExeName), s);
        if (( ext = ext_KeyNote ) or ( ext = ext_Encrypted ) or ( ext = ext_DART )) then
        begin
          NoteFileToLoad := s;<commit_msg>Fixed: Filename is converted to lowercase when opened from command line (or explorer)<commit_after>unit kn_ConfigMng;

(****** LICENSE INFORMATION **************************************************
 
 - 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/.           
 
------------------------------------------------------------------------------
 (c) 2000-2005 <NAME> <<EMAIL>> (Poland)
 (c) 2007-2015 <NAME> <<EMAIL>> (Spain) [^]

 [^]: Changes since v. 1.7.0. Fore more information, please see 'README.md'
     and 'doc/README_SourceCode.txt' in https://github.com/dpradov/keynote-nf      
   
 *****************************************************************************) 

interface

    // config management
    procedure ReadCmdLine;
    procedure SaveOptions;
    procedure ReadOptions;
    procedure LoadToolbars;
    procedure SaveToolbars;
    procedure SaveDefaults;
    procedure LoadDefaults;
    procedure ReadFuncKeys;
    procedure SaveFuncKeys;
    procedure AdjustOptions;
//    procedure SetupToolbarButtons;
//    procedure ResolveToolbarRTFv3Dependencies;
    function LoadCustomKeyboard : boolean;
    procedure CustomizeKeyboard;


implementation

uses
   Windows, Forms, Classes, Controls, Dialogs, Menus, IniFiles, SysUtils,
   TB97Ctls, TB97Tlbr,
   kn_Main, dll_Keyboard, kn_Dllmng, kn_DLLinterface, gf_files,
   kn_global, kn_Info, kn_INI, kn_Const, kn_OptionsNew, kn_Chest,
   kn_FindReplaceMng, kn_MacroMng, kn_VCLControlsMng, kn_LanguagesMng,
   TntSysUtils;

resourcestring
  STR_KeybdError = 'Error in keyboard customization procedure: ';
  STR_TabIcons = ' Customize Tab icons (%s) ';


procedure ReadCmdLine;
var
  i : integer;
  s, ext, errstr : string;
begin
  errstr := '';
  for i := 1 to ParamCount do
  begin
    s := ansilowercase( ParamStr( i ));
    case s[1] of
      '-', '/' : begin // assume switch { BUG: if a filename begins with '-', we're screwed }
        delete( s, 1, 1 );


        if ( s = swMinimize ) then
          opt_Minimize := true
        else
        if ( s = swSetup ) then
          opt_Setup := true
        else
        if ( s = swDebug ) then
          opt_Debug := true
        else
        if ( s = swNoReadOpt ) then
          opt_NoReadOpt := true
        else
        if ( s = swNoSaveOpt ) then
          opt_NoSaveOpt := true
        else
        if ( s = swNoDefaults ) then
          opt_NoDefaults := true
        else
        if ( s = swNoReg ) then
          opt_NoRegistry := true
        else
        if ( s = swRegExt ) then
          opt_RegExt := true
        else
        if ( s = swSaveDefIcn ) then
          opt_SaveDefaultIcons := true
        else
        if ( s = swSaveToolbars ) then
          opt_SaveToolbars := true
        else
        if ( s = swSaveMenus ) then
          opt_SaveMenus := true
        else
        if ( s = swNoUserIcn ) then
          opt_NoUserIcons := true
        else
        if ( s = swUseOldFormat ) then
          _USE_OLD_KEYNOTE_FILE_FORMAT := true // GLOBAL var, used by TTabNote and TNoteFile
        else
        if ( s = swClean ) then
          opt_Clean := true
        else
        begin
          errstr := errstr + #13 + ParamStr( i );
        end;
      end;
      else
      begin
        // not a switch, so it's a filename.
        // Let's see what kind of file.
        ext := extractfileext(s);
        s:= GetAbsolutePath(WideExtractFilePath(Application.ExeName), ParamStr(i));
        if (( ext = ext_KeyNote ) or ( ext = ext_Encrypted ) or ( ext = ext_DART )) then
        begin
          NoteFileToLoad := s;
{'fraction_non_alphanumeric': 0.13894191437142078, 'fraction_numerical': 0.009271884374147804, 'mean_word_length': 2.0858224652923854, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5252367', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2147, 'n_words': 652}