📄 freeotfefrmoptions.pas
字号:
unit FreeOTFEfrmOptions;
// Description:
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW: http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls,
FreeOTFESettings;
type
TfrmOptions = class(TForm)
pbOK: TButton;
pbCancel: TButton;
gbSystemTrayIcon: TGroupBox;
ckUseSystemTrayIcon: TCheckBox;
ckMinToIcon: TCheckBox;
ckCloseToIcon: TCheckBox;
GroupBox1: TGroupBox;
ckAllowMultipleInstances: TCheckBox;
GroupBox2: TGroupBox;
hkDismount: THotKey;
ckHotkeyDismount: TCheckBox;
ckHotkeyDismountEmerg: TCheckBox;
hkDismountEmerg: THotKey;
Label1: TLabel;
Label2: TLabel;
ckDisplayToolbar: TCheckBox;
ckDisplayStatusbar: TCheckBox;
cbDragDrop: TComboBox;
Label3: TLabel;
ckAutoStartPortable: TCheckBox;
cbSettingsLocation: TComboBox;
lblSettingsLocation: TLabel;
ckAssociateFiles: TCheckBox;
procedure pbOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure pbCancelClick(Sender: TObject);
procedure ControlChanged(Sender: TObject);
private
FOrigAssociateFiles: boolean;
procedure EnableDisableControls();
function GetSettingsLocation(): TSettingsSaveLocation;
public
{ Public declarations }
end;
implementation
{$R *.DFM}
uses
ShlObj, // Required for CSIDL_PROGRAMS
SDUGeneral,
SDUDialogs,
OTFEFreeOTFE_U;
const
SHELL_VERB = 'Open';
function TfrmOptions.GetSettingsLocation(): TSettingsSaveLocation;
var
retval: TSettingsSaveLocation;
sl: TSettingsSaveLocation;
begin
retval := Settings.OptSaveSettings;
for sl:=low(SettingsSaveLocationTitle) to high(SettingsSaveLocationTitle) do
begin
if (SettingsSaveLocationTitle[sl] = cbSettingsLocation.Items[cbSettingsLocation.ItemIndex]) then
begin
retval := sl;
break;
end;
end;
Result := retval;
end;
procedure TfrmOptions.pbOKClick(Sender: TObject);
var
allOK: boolean;
ft: TDragDropFileType;
oldSettingsLocation: TSettingsSaveLocation;
newSettingsLocation: TSettingsSaveLocation;
msgSegment: string;
vistaProgFilesDirWarn: boolean;
programFilesDir: string;
filename: string;
prevSDUDialogsStripSingleCRLF: boolean;
begin
allOK := TRUE;
// Decode settings save location
oldSettingsLocation := Settings.OptSaveSettings;
newSettingsLocation := GetSettingsLocation();
if allOK then
begin
// If user tried to save settings under C:\Program Files\... while
// running under Vista, let the user know that Vista's security
// system screws this up (it maps the save to somewhere in the user's
// profile)
vistaProgFilesDirWarn:= FALSE;
if (
SDUOSVistaOrLater() and
(newSettingsLocation = slExeDir)
) then
begin
programFilesDir := SDUGetSpecialFolderPath(SDU_CSIDL_PROGRAM_FILES);
filename := Settings.GetSettingsFilename(newSettingsLocation);
vistaProgFilesDirWarn := (Pos(
uppercase(programFilesDir),
uppercase(filename)
) > 0);
end;
allOK := not(vistaProgFilesDirWarn);
if not(allOK) then
begin
prevSDUDialogsStripSingleCRLF := SDUDialogsStripSingleCRLF; // Don't do special processing on this message
SDUDialogsStripSingleCRLF := FALSE; // Don't do special processing on this message
SDUMessageDlg(
'Under Windows Vista, you cannot save your settings file anywhere under:'+SDUCRLF+
SDUCRLF+
programFilesDir+SDUCRLF+
SDUCRLF+
'due to Vista''s security/mapping system.'+SDUCRLF+
SDUCRLF+
'Please either select another location for storing your settings (e.g. your user profile), or move the FreeOTFE executable such that it is not stored underneath the directory shown above.',
mtWarning,
[mbOK],
0
);
SDUDialogsStripSingleCRLF := prevSDUDialogsStripSingleCRLF; // Don't do special processing on this message
end;
end;
if allOK then
begin
Settings.OptSaveSettings := newSettingsLocation;
// General...
Settings.OptAllowMultipleInstances := ckAllowMultipleInstances.checked;
Settings.OptDisplayToolbar := ckDisplayToolbar.checked;
Settings.OptDisplayStatusbar := ckDisplayStatusbar.checked;
Settings.OptAutoStartPortable := ckAutoStartPortable.checked;
// Decode drag drop filetype
Settings.OptDragDropFileType := ftPrompt;
for ft:=low(DragDropFileTypeTitle) to high(DragDropFileTypeTitle) do
begin
if (DragDropFileTypeTitle[ft] = cbDragDrop.Items[cbDragDrop.ItemIndex]) then
begin
Settings.OptDragDropFileType := ft;
break;
end;
end;
// System tray icon related...
Settings.OptSystemTrayIconDisplay := ckUseSystemTrayIcon.checked;
Settings.OptSystemTrayIconMinTo := ckMinToIcon.checked;
Settings.OptSystemTrayIconCloseTo := ckCloseToIcon.checked;
// Hotkeys...
Settings.OptHKeyEnableDismount := ckHotkeyDismount.checked;
Settings.OptHKeyKeyDismount := hkDismount.HotKey;
Settings.OptHKeyEnableDismountEmerg := ckHotkeyDismountEmerg.checked;
Settings.OptHKeyKeyDismountEmerg := hkDismountEmerg.HotKey;
if (Settings.OptSaveSettings <> slNone) then
begin
allOK := Settings.Save();
end;
end;
if allOK then
begin
// If the save settings location has been changed, and we previously
// saved settings to a file, ask the user if they want to delete their
// old settings file
if (
(oldSettingsLocation <> newSettingsLocation) and
(oldSettingsLocation <> slNone)
) then
begin
if (newSettingsLocation = slNone) then
begin
msgSegment := 'You have opted not to save your settings';
end
else
begin
msgSegment := 'You have changed the location where your settings will be saved';
end;
if (SDUMessageDlg(
msgSegment+SDUCRLF+
SDUCRLF+
'Would you like FreeOTFE to delete your previous settings file?',
mtConfirmation,
[mbYes, mbNo],
0
) = mrYes) then
begin
if not(Settings.DestroySettingsFile(oldSettingsLocation)) then
begin
SDUMessageDlg(
'Your previous settings file stored at:'+SDUCRLF+
SDUCRLF+
Settings.GetSettingsFilename(oldSettingsLocation)+SDUCRLF+
SDUCRLF+
'could not be deleted. Please remove this file manually.',
mtInformation,
[mbOK],
0
);
end;
end
else
begin
SDUMessageDlg(
'Your previous settings will remain stored at:'+SDUCRLF+
SDUCRLF+
Settings.GetSettingsFilename(oldSettingsLocation),
mtInformation,
[mbOK],
0
);
end;
end;
end;
if allOK then
begin
if (ckAssociateFiles.checked <> FOrigAssociateFiles) then
begin
if ckAssociateFiles.checked then
begin
SDUFileExtnRegCmd(
VOL_FILE_EXTN,
SHELL_VERB,
'"'+ParamStr(0)+'" /mount /volume "%1"'
);
SDUFileExtnRegIcon(
VOL_FILE_EXTN,
ParamStr(0),
0
);
end
else
begin
SDUFileExtnUnregIcon(VOL_FILE_EXTN);
SDUFileExtnUnregCmd(
VOL_FILE_EXTN,
SHELL_VERB
);
end;
FOrigAssociateFiles := ckAssociateFiles.checked;
end;
end;
if allOK then
begin
ModalResult := mrOK;
end;
end;
procedure TfrmOptions.FormCreate(Sender: TObject);
var
ft: TDragDropFileType;
idx: integer;
useIdx: integer;
sl: TSettingsSaveLocation;
begin
// Populate and set settings location dropdown
cbSettingsLocation.Items.Clear();
idx := -1;
useIdx := -1;
for sl := low(SettingsSaveLocationTitle) to high(SettingsSaveLocationTitle) do
begin
inc(idx);
cbSettingsLocation.Items.Add(SettingsSaveLocationTitle[sl]);
if (Settings.OptSaveSettings = sl) then
begin
useIdx := idx;
end;
end;
cbSettingsLocation.ItemIndex := useIdx;
// General...
ckAllowMultipleInstances.checked := Settings.OptAllowMultipleInstances;
ckDisplayToolbar.checked := Settings.OptDisplayToolbar;
ckDisplayStatusbar.checked := Settings.OptDisplayStatusbar;
ckAutoStartPortable.checked := Settings.OptAutoStartPortable;
// Populate and set drag drop filetype dropdown
cbDragDrop.Items.Clear();
idx := -1;
useIdx := -1;
for ft:=low(DragDropFileTypeTitle) to high(DragDropFileTypeTitle) do
begin
inc(idx);
cbDragDrop.Items.Add(DragDropFileTypeTitle[ft]);
if (Settings.OptDragDropFileType = ft) then
begin
useIdx := idx;
end;
end;
cbDragDrop.ItemIndex := useIdx;
// System tray icon related...
ckUseSystemTrayIcon.checked := Settings.OptSystemTrayIconDisplay;
ckMinToIcon.checked := Settings.OptSystemTrayIconMinTo;
ckCloseToIcon.checked := Settings.OptSystemTrayIconCloseTo;
// Hotkeys...
ckHotkeyDismount.checked := Settings.OptHKeyEnableDismount;
hkDismount.HotKey := Settings.OptHKeyKeyDismount;
ckHotkeyDismountEmerg.checked := Settings.OptHKeyEnableDismountEmerg;
hkDismountEmerg.HotKey := Settings.OptHKeyKeyDismountEmerg;
FOrigAssociateFiles := SDUFileExtnIsRegCmd(
VOL_FILE_EXTN,
SHELL_VERB,
ExtractFilename(ParamStr(0))
);
ckAssociateFiles.checked := FOrigAssociateFiles;
EnableDisableControls();
end;
procedure TfrmOptions.EnableDisableControls();
const
CONTROL_MARGIN = 10;
begin
SDUEnableControl(ckMinToIcon, ckUseSystemTrayIcon.checked);
SDUEnableControl(ckCloseToIcon, ckUseSystemTrayIcon.checked);
SDUEnableControl(hkDismount, ckHotkeyDismount.checked);
SDUEnableControl(hkDismountEmerg, ckHotkeyDismountEmerg.checked);
if (GetSettingsLocation() = slNone) then
begin
lblSettingsLocation.font.style := [fsBold];
end
else
begin
lblSettingsLocation.font.style := [];
end;
// Adjust "Save settings to:" label
lblSettingsLocation.Left := (
cbSettingsLocation.left -
lblSettingsLocation.Width -
CONTROL_MARGIN
);
end;
procedure TfrmOptions.pbCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TfrmOptions.ControlChanged(Sender: TObject);
begin
EnableDisableControls();
end;
END.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -