⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freeotfefrmmain.pas

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  if OTFEFreeOTFE.WarnIfNoHashOrCypherDrivers() then
    begin
    dlg:= TfrmFreeOTFECDBDump.Create(self);
    try
      dlg.LUKSDump := LUKSDump;
      dlg.OTFEFreeOTFE := OTFEFreeOTFE;
      dlg.ShowModal();
    finally
      dlg.Free();
    end;

    end;

end;


procedure TfrmFreeOTFEMain.actFreeOTFENewExecute(Sender: TObject);
begin
  if OTFEFreeOTFE.CreateFreeOTFEVolumeWizard() then
    begin
    SDUMessageDlg('FreeOTFE volume created successfully.'+SDUCRLF+
               SDUCRLF+
               'Please mount, format and overwrite this volume''s free space before use.',
               mtInformation, [mbOK], 0);
    end
  else
    begin
    if (OTFEFreeOTFE.LastErrorCode <> OTFE_ERR_USER_CANCEL) then
      begin
      SDUMessageDlg('FreeOTFE volume could not be created', mtError, [mbOK], 0);
      end;
    end;

end;

procedure TfrmFreeOTFEMain.actFreeOTFEMountFileExecute(Sender: TObject);
begin
  if OTFEFreeOTFE.WarnIfNoHashOrCypherDrivers() then
    begin
    OpenDialog.Filter     := FILE_FILTER_FLT_VOLUMES;
    OpenDialog.DefaultExt := FILE_FILTER_DFLT_NONE;

    if OpenDialog.Execute() then
      begin
      MountFiles(ftFreeOTFE, TStringList(OpenDialog.Files), (ofReadOnly in OpenDialog.Options));
      end;
    end;

end;

procedure TfrmFreeOTFEMain.actFreeOTFEMountPartitionExecute(
  Sender: TObject);
var
  selectedPartition: string;
  mountList: TStringList;
begin
  if OTFEFreeOTFE.WarnIfNoHashOrCypherDrivers() then
    begin
    selectedPartition := OTFEFreeOTFE.SelectPartition();

    if (selectedPartition <> '') then
      begin
      mountList:= TStringList.Create();
      try
        mountList.Add(selectedPartition);
        MountFiles(ftFreeOTFE, mountList, FALSE);
      finally
        mountList.Free();
      end;

      end;
    end;

end;

procedure TfrmFreeOTFEMain.actDismountExecute(Sender: TObject);
begin
  DismountSelected();

end;

procedure TfrmFreeOTFEMain.actDismountAllExecute(Sender: TObject);
begin
  DismountAll();

end;

procedure TfrmFreeOTFEMain.actLinuxNewExecute(Sender: TObject);
begin
  if OTFEFreeOTFE.CreateLinuxVolumeWizard() then
    begin
    SDUMessageDlg('Linux volume created successfully.'+SDUCRLF+
               SDUCRLF+
               'Don''t forget to mount and format this volume before use.',
               mtInformation, [mbOK], 0);
    end
  else
    begin
    if (OTFEFreeOTFE.LastErrorCode <> OTFE_ERR_USER_CANCEL) then
      begin
      SDUMessageDlg('Linux volume could not be created', mtError, [mbOK], 0);
      end;
    end;

end;

procedure TfrmFreeOTFEMain.actLinuxMountFileExecute(Sender: TObject);
begin
  if OTFEFreeOTFE.WarnIfNoHashOrCypherDrivers() then
    begin
    OpenDialog.Filter     := FILE_FILTER_FLT_VOLUMES;
    OpenDialog.DefaultExt := FILE_FILTER_DFLT_NONE;

    if OpenDialog.Execute() then
      begin
      MountFiles(ftLinux, TStringList(OpenDialog.Files), (ofReadOnly in OpenDialog.Options));
      end;
    end;

end;

procedure TfrmFreeOTFEMain.actLinuxMountPartitionExecute(Sender: TObject);
var
  selectedPartition: string;
  mountList: TStringList;
begin
  if OTFEFreeOTFE.WarnIfNoHashOrCypherDrivers() then
    begin
    selectedPartition := OTFEFreeOTFE.SelectPartition();

    if (selectedPartition <> '') then
      begin
      mountList:= TStringList.Create();
      try
        mountList.Add(selectedPartition);
        MountFiles(ftLinux, mountList, FALSE);
      finally
        mountList.Free();
      end;

      end;
    end;

end;

procedure TfrmFreeOTFEMain.actPropertiesExecute(Sender: TObject);
begin
  DriveProperties();

end;

// Function required for both close and minimize to system tray icon
procedure TfrmFreeOTFEMain.actExitExecute(Sender: TObject);
begin
  // Either:
  //   Application.Terminate();
  // Or:
  SDUSystemTrayIcon1.Active := FALSE;
  Close();
end;

procedure TfrmFreeOTFEMain.miOptionsClick(Sender: TObject);
var
  dlg: TfrmOptions;
begin
  dlg := TfrmOptions.Create(self);
  try
    if (dlg.ShowModal() = mrOK) then
      begin
      SetupHotKeys();
      EnableDisableControls();
      end;
      
  finally
    dlg.Free();
  end;

end;

// Function required for both close and minimize to system tray icon
procedure TfrmFreeOTFEMain.actDisplayConsoleExecute(Sender: TObject);
begin
  SDUSystemTrayIcon1.DoRestore();

end;


procedure TfrmFreeOTFEMain.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
var
  userConfirm: WORD;
  oldActive: boolean;
  closingDrivesMounted: integer;
begin
  CanClose := TRUE;

  closingDrivesMounted := 0;

  // This code segment is required to handle the case when Close() is called
  // programatically
  // Only carry out this action if closing to SystemTrayIcon
  // Note the MainForm test; if it was not the main form, setting Action would
  // in FormClose would do the minimise
  if (
      not(EndSessionFlag) and
      SDUSystemTrayIcon1.Active and
      Settings.OptSystemTrayIconCloseTo and
      (Application.MainForm = self)
     ) then
    begin
    CanClose := FALSE;
    SDUSystemTrayIcon1.DoMinimizeToIcon();
    end;

  if (CanClose) then
    begin
    oldActive := OTFEFreeOTFE.Active;
    // We (quite reasonably) assume that if the FreeOTFE component is *not*
    // active, and we can't activate it, then no FreeOTFE volumes are mounted
    if not(OTFEFreeOTFE.Active) then
      begin
      // Prevent any warnings...
      ShuttingDownFlag := TRUE;
      ActivateFreeOTFEComponent(FALSE);
      // Reset flag
      ShuttingDownFlag := FALSE;
      end;

    if (OTFEFreeOTFE.Active) then
      begin
      if (OTFEFreeOTFE.CountDrivesMounted() > 0) then
        begin
        userConfirm := SDUMessageDlg(
                                  'One or volumes are still mounted.'+SDUCRLF+
                                  SDUCRLF+
                                  'Do you wish to dismount all volumes before exiting?',
                                  mtConfirmation, [mbYes, mbNo, mbCancel], 0
                                 );

        if (userConfirm = mrCancel) then
          begin
          CanClose := FALSE;
          end
        else if (userConfirm = mrYes) then
          begin
          CanClose := DismountAll();
          end
        else
          begin
          CanClose := TRUE;
          end;

        end;

      closingDrivesMounted := OTFEFreeOTFE.CountDrivesMounted();
      end;  // if (OTFEFreeOTFE.Active) then

    if not(oldActive) then
      begin
      // Prevent any warnings...
      ShuttingDownFlag := TRUE;
      DeactivateFreeOTFEComponent();
      // Reset flag
      ShuttingDownFlag := FALSE;
      end;

    end;


  if (CanClose) then
    begin
    // If there's no drives mounted, and running in portable mode, prompt for
    // portable mode shutdown
    if (
        (closingDrivesMounted <= 0) and
        (OTFEFreeOTFE.DriversInPortableMode() > 0)
       ) then
      begin
      userConfirm := SDUMessageDlg(
                                 'One or more FreeOTFE drivers is running in portable mode.'+SDUCRLF+
                                 SDUCRLF+
                                 'Do you wish to shutdown portable mode before exiting?',
                                 mtConfirmation, [mbYes, mbNo, mbCancel], 0);

      if (userConfirm = mrCancel) then
        begin
        CanClose := FALSE;
        end
      else if (userConfirm = mrYes) then
        begin
        ShuttingDownFlag := TRUE;
        CanClose := PortableModeSet(pmaStop, FALSE);
        ShuttingDownFlag := CanClose;
        end
      else
        begin
        CanClose := TRUE;
        end;

      end;

    end;  // if (CanClose) then

  if CanClose then
    begin
    DestroySysTrayIconMenuitems();
    Application.ProcessMessages();
    Application.UnhookMainWindow(MessageHook);
    OTFEFreeOTFE.Active := FALSE;
    end;

end;


// Function required for close to system tray icon
// Note: This is *only* required in your application is you intend to call
//       Close() to hide/close the window. Calling Hide() instead is preferable
procedure TfrmFreeOTFEMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  // This code segment is required to handle the case when Close() is called
  // programatically
  // Only carry out this action if closing to SystemTrayIcon
  // Note the MainForm test; if it was the main form, setting Action would have
  // no effect
  if (
      not(EndSessionFlag) and
      SDUSystemTrayIcon1.Active and
      Settings.OptSystemTrayIconCloseTo and
      (Application.MainForm <> self)
     ) then
    begin
    Action := caMinimize;
    end
  else
    begin
    IconMounted.Free();
    IconMounted := nil;
    IconUnmounted.Free();
    IconUnmounted := nil;
    end;

end;


// This is used to ensure that only one copy of FreeOTFE is running at any
// given time
function TfrmFreeOTFEMain.MessageHook(var msg: TMessage): boolean;
var
  retVal: boolean;
  hotKeyMsg: TWMHotKey;
begin
  retVal := FALSE;
  if (msg.Msg = GLOBAL_VAR_WM_FREEOTFE_RESTORE) then
    begin
    // Restore application
    actDisplayConsole.Execute();

    msg.Result := 0;
    retVal := TRUE;
    end
  else if (msg.Msg = GLOBAL_VAR_WM_FREEOTFE_REFRESH) then
    begin
    actRefreshExecute(nil);
    end
  else if (msg.Msg = WM_HOTKEY) then
    begin
    // Hotkey window message handler
    hotKeyMsg := TWMHotKey(msg);
    
    if OTFEFreeOTFE.Active then
      begin
      if (hotKeyMsg.HotKey = HOTKEY_IDENT_DISMOUNT) then
        begin
        // We'll allow errors in dismount to be reported to the user; it's just
        // a normal dismount
        DismountAll(FALSE);
        end
      else if (hotKeyMsg.HotKey = HOTKEY_IDENT_DISMOUNTEMERG) then
        begin
        // Panic! The user pressed the emergency dismount hotkey! Better not
        // report any errors to the user
        DismountAll(TRUE);
        end;
      end;
    end;

  Result := retVal;
end;



// Cleardown and setup hotkeys
procedure TfrmFreeOTFEMain.SetupHotKeys();
begin
  // Cleardown any existing hotkeys...
  DisableHotkey(HOTKEY_IDENT_DISMOUNT);
  DisableHotkey(HOTKEY_IDENT_DISMOUNTEMERG);

  // ...And setup hotkeys again
  if Settings.OptHKeyEnableDismount then
    begin
    EnableHotkey(
                 Settings.OptHKeyKeyDismount,
                 HOTKEY_IDENT_DISMOUNT
                );
    end;

  if Settings.OptHKeyEnableDismountEmerg then
    begin
    EnableHotkey(
                 Settings.OptHKeyKeyDismountEmerg,
                 HOTKEY_IDENT_DISMOUNT
                );
    end;

end;

// Enable the specified shortcut as a hotkey, which will callback using the
// given identifier
procedure TfrmFreeOTFEMain.EnableHotkey(hotKey: TShortCut; hotKeyIdent: integer);
var
  modifiers : integer;
  vk  : word;
  shiftState : TShiftState;
begin
  if (hotkey = TextToShortCut(HOTKEY_TEXT_NONE)) then
    begin
    DisableHotkey(hotkeyIdent);
    end
  else
    begin
    // Obtain the virtual keycode and shiftState
    ShortCutToKey(hotkey, vk, shiftState);

    // Convet TShiftState into a modifier value for RegisterHotKey
    modifiers := 0;
    if (ssCtrl in shiftState) then
      begin
      modifiers := modifiers OR MOD_CONTROL;
      end;
    if (ssAlt in shiftState) then
      begin
      modifiers := modifiers OR MOD_ALT;
      end;
    if (ssShift in shiftState) then
      begin
      modifiers := modifiers OR MOD_SHIFT;
      end;

    DisableHotkey(hotkeyIdent);
    i

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -