Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.2 KiB

3 years ago
  1. unit DataModule;
  2. {$mode delphi}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Dialogs, ActnList,
  6. // Units needed for file info reading
  7. fileinfo, winpeimagereader, elfreader, machoreader,
  8. // App units
  9. Options;
  10. type
  11. { TModule }
  12. TModule = class(TDataModule)
  13. ActShowAdvOptions: TAction;
  14. OpenDialogMulti: TOpenDialog;
  15. OpenDialogSingle: TOpenDialog;
  16. SelectDirectoryDialog: TSelectDirectoryDialog;
  17. procedure ActShowAdvOptionsExecute(Sender: TObject);
  18. procedure DataModuleCreate(Sender: TObject);
  19. procedure DataModuleDestroy(Sender: TObject);
  20. private
  21. FOptionsFilePath: string;
  22. procedure SaveOptions;
  23. procedure LoadOptions;
  24. procedure ReadVersionInfo;
  25. public
  26. Options: TOptions;
  27. VersionString: string;
  28. end;
  29. var
  30. Module: TModule;
  31. implementation
  32. uses
  33. IniFiles, Forms, ImagingUtility, AdvOptionsForm, Utils, Config;
  34. {$R *.lfm}
  35. const
  36. SOptionsFileName = 'deskewgui.ini';
  37. { TModule }
  38. procedure TModule.DataModuleCreate(Sender: TObject);
  39. begin
  40. Application.Title := Config.ApplicationTitle;
  41. ReadVersionInfo;
  42. // Prefers "portable mode": config in the folder as exe if it is writable,
  43. // standard OS location otherwise.
  44. FOptionsFilePath := ConcatPaths([Utils.DetermineConfigFolder, SOptionsFileName]);
  45. Options := TOptions.Create;
  46. LoadOptions;
  47. end;
  48. procedure TModule.DataModuleDestroy(Sender: TObject);
  49. begin
  50. SaveOptions;
  51. Options.Free;
  52. end;
  53. procedure TModule.LoadOptions;
  54. var
  55. Ini: TIniFile;
  56. begin
  57. Ini := TIniFile.Create(FOptionsFilePath, [ifoFormatSettingsActive]);
  58. try
  59. Options.LoadFromIni(Ini);
  60. finally
  61. Ini.Free;
  62. end;
  63. end;
  64. procedure TModule.SaveOptions;
  65. var
  66. Ini: TIniFile;
  67. begin
  68. Ini := TIniFile.Create(FOptionsFilePath, [ifoFormatSettingsActive]);
  69. try
  70. Options.SaveToIni(Ini);
  71. finally
  72. Ini.Free;
  73. end;
  74. end;
  75. procedure TModule.ReadVersionInfo;
  76. var
  77. FileVerInfo: TFileVersionInfo;
  78. begin
  79. FileVerInfo := TFileVersionInfo.Create(nil);
  80. try
  81. FileVerInfo.ReadFileInfo;
  82. VersionString := FileVerInfo.VersionStrings.Values['FileVersion'];
  83. VersionString := Copy(VersionString, 1, PosEx('.', VersionString, 3) - 1);
  84. finally
  85. FileVerInfo.Free;
  86. end;
  87. end;
  88. procedure TModule.ActShowAdvOptionsExecute(Sender: TObject);
  89. begin
  90. FormAdvOptions.ShowModal;
  91. end;
  92. end.