Skip to content

Commit

Permalink
Added sleep prevention feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyhamster committed Mar 11, 2023
1 parent 7aaac7f commit b5457fc
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 38 deletions.
37 changes: 0 additions & 37 deletions source/FarCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ enum HashOutputTargets
OT_SEPARATEDIRS = 3 // One hash file per one directory
};

// Plugin settings
static bool optDetectHashFiles = true;
static bool optClearSelectionOnComplete = true;
static bool optConfirmAbort = true;
static bool optAutoExtension = true;
static int optDefaultAlgo = RHASH_MD5;
static int optDefaultOutputTarget = OT_SINGLEFILE;
static bool optUsePrefix = true;
static bool optHashUppercase = false;
static int optListDefaultCodepage = CP_UTF8;
static bool optRememberLastUsedAlgo = false;
static wchar_t optPrefix[32] = L"check";

#define EDR_SKIP 0
#define EDR_SKIPALL 1
#define EDR_RETRY 2
Expand Down Expand Up @@ -175,30 +162,6 @@ struct RectSize
}
};

struct HashGenerationParams
{
rhash_ids Algorithm;
bool Recursive;
HashOutputTargets OutputTarget;
bool StoreAbsPaths;
HANDLE FileFilter;

std::wstring OutputFileName;
UINT OutputFileCodepage;

HashGenerationParams()
{
Algorithm = (rhash_ids) optDefaultAlgo;
Recursive = true;
OutputTarget = (HashOutputTargets) optDefaultOutputTarget;
StoreAbsPaths = false;
FileFilter = INVALID_HANDLE_VALUE;

OutputFileName = L"hashlist";
OutputFileCodepage = optListDefaultCodepage;
}
};

typedef bool (*FARSIZECALLBACK)(RectSize &farSize);

static bool FindBestListBoxSize(std::vector<std::wstring> listItems, FARSIZECALLBACK sizeFunc, RectSize &listBoxSize)
Expand Down
60 changes: 59 additions & 1 deletion source/IntChecker2-Far3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,47 @@

#include "FarCommon.h"

// Plugin settings
static bool optDetectHashFiles = true;
static bool optClearSelectionOnComplete = true;
static bool optConfirmAbort = true;
static bool optAutoExtension = true;
static int optDefaultAlgo = RHASH_MD5;
static int optDefaultOutputTarget = OT_SINGLEFILE;
static bool optUsePrefix = true;
static bool optHashUppercase = false;
static int optListDefaultCodepage = CP_UTF8;
static bool optRememberLastUsedAlgo = false;
static bool optPreventSleepOnCalc = false;
static wchar_t optPrefix[32] = L"check";

static std::wstring AnsiPageName = FormatString(L"ANSI (%d)", GetACP());
static std::wstring OemPageName = FormatString(L"OEM (%d)", GetOEMCP());

struct HashGenerationParams
{
rhash_ids Algorithm;
bool Recursive;
HashOutputTargets OutputTarget;
bool StoreAbsPaths;
HANDLE FileFilter;

std::wstring OutputFileName;
UINT OutputFileCodepage;

HashGenerationParams()
{
Algorithm = (rhash_ids)optDefaultAlgo;
Recursive = true;
OutputTarget = (HashOutputTargets)optDefaultOutputTarget;
StoreAbsPaths = false;
FileFilter = INVALID_HANDLE_VALUE;

OutputFileName = L"hashlist";
OutputFileCodepage = optListDefaultCodepage;
}
};

// --------------------------------------- Service functions -------------------------------------------------

static intptr_t FarAdvControl(enum ADVANCED_CONTROL_COMMANDS command, intptr_t param1 = 0, void* param2 = NULL)
Expand Down Expand Up @@ -97,6 +135,18 @@ static bool GetMacroBoolValue(OpenMacroInfo *macroInfo, size_t index, bool defau
return defaultValue;
}

static void StopSleep()
{
if (optPreventSleepOnCalc)
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
}

static void RestoreSleep()
{
if (optPreventSleepOnCalc)
SetThreadExecutionState(ES_CONTINUOUS);
}

// --------------------------------------- Local functions ---------------------------------------------------

static void LoadSettings()
Expand All @@ -113,6 +163,7 @@ static void LoadSettings()
optRememberLastUsedAlgo = ps.Get(0, L"RememberLastAlgorithm", optRememberLastUsedAlgo);
optListDefaultCodepage = ps.Get(0, L"DefaultListCodepage", optListDefaultCodepage);
optDefaultOutputTarget = ps.Get(0, L"DefaultOutput", optDefaultOutputTarget);
optPreventSleepOnCalc = ps.Get(0, L"PreventSleepOnCalc", optPreventSleepOnCalc);

const wchar_t* prefixVal = ps.Get(0, L"Prefix", optPrefix);
if (prefixVal != optPrefix)
Expand All @@ -136,6 +187,7 @@ static void SaveSettings()
ps.Set(0, L"RememberLastAlgorithm", optRememberLastUsedAlgo);
ps.Set(0, L"DefaultListCodepage", optListDefaultCodepage);
ps.Set(0, L"DefaultOutput", optDefaultOutputTarget);
ps.Set(0, L"PreventSleepOnCalc", optPreventSleepOnCalc);
}

static std::wstring FileSizeToString(int64_t fileSize, bool keepBytes)
Expand Down Expand Up @@ -390,6 +442,7 @@ static bool RunValidateFiles(const wchar_t* hashListPath, bool silent, bool show
int64_t totalFilesSize = 0;

FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_INDETERMINATE, NULL);
StopSleep();

// Prepare files list
{
Expand Down Expand Up @@ -457,6 +510,7 @@ static bool RunValidateFiles(const wchar_t* hashListPath, bool silent, bool show
DisplayMessage(GetLocMsg(MSG_DLG_NOFILES_TITLE), GetLocMsg(MSG_DLG_NOFILES_TEXT), NULL, true, true);
}

RestoreSleep();
FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_NOPROGRESS, NULL);
FarAdvControl(ACTL_PROGRESSNOTIFY, 0, NULL);

Expand Down Expand Up @@ -691,8 +745,8 @@ static void RunGenerateHashes(Far3Panel& panel)
HashList hashes;
std::wstring strPanelDir = panel.GetPanelDirectory();

// Win7 only feature
FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_INDETERMINATE, NULL);
StopSleep();

// Prepare files list
{
Expand Down Expand Up @@ -728,6 +782,7 @@ static void RunGenerateHashes(Far3Panel& panel)
}
}

RestoreSleep();
FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_NOPROGRESS, NULL);
FarAdvControl(ACTL_PROGRESSNOTIFY, 0, NULL);

Expand Down Expand Up @@ -885,6 +940,7 @@ static void RunComparePanels()
std::vector<PanelFileInfo> vSelectedFiles;

FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_INDETERMINATE, NULL);
StopSleep();

// Prepare files list
{
Expand Down Expand Up @@ -957,6 +1013,7 @@ static void RunComparePanels()
}
}

RestoreSleep();
FarAdvControl(ACTL_SETPROGRESSSTATE, TBPS_NOPROGRESS, NULL);
FarAdvControl(ACTL_PROGRESSNOTIFY, 0, NULL);
}
Expand Down Expand Up @@ -1403,6 +1460,7 @@ intptr_t WINAPI ConfigureW(const ConfigureInfo* Info)
dlgBuilder.AddCheckbox(MSG_CONFIG_CLEAR_SELECTION, &optClearSelectionOnComplete);
dlgBuilder.AddCheckbox(MSG_CONFIG_AUTOEXT, &optAutoExtension);
dlgBuilder.AddCheckbox(MSG_CONFIG_UPPERCASE, &optHashUppercase);
dlgBuilder.AddCheckbox(MSG_CONFIG_PREVENT_SLEEP, &optPreventSleepOnCalc);
auto cpBox = dlgBuilder.AddComboBox(&selectedCP, NULL, 8, codePageNames, ARRAY_SIZE(codePageNames), DIF_DROPDOWNLIST);
dlgBuilder.AddTextBefore(cpBox, MSG_CONFIG_DEFAULT_CP);

Expand Down
1 change: 1 addition & 0 deletions source/Lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum
MSG_CONFIG_OUTPUT_SEPARATE_FILE,
MSG_CONFIG_OUTPUT_DISPLAY,
MSG_CONFIG_OUTPUT_SEPARATE_DIRS,
MSG_CONFIG_PREVENT_SLEEP,

// Buttons
MSG_BTN_OK,
Expand Down
1 change: 1 addition & 0 deletions source/Text/IntCheckerEng.lng
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Separate hash files"
"Display"
"Directory hash files"
"Prevent sleep when calculating"

"OK"
"Cancel"
Expand Down
1 change: 1 addition & 0 deletions source/Text/IntCheckerPol.lng
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Osobne pliki kontrolne"
"Ekran"
"Fol&der plików kontrolnych"
"*Prevent sleep when calculating"

"&OK"
"&Anuluj"
Expand Down
1 change: 1 addition & 0 deletions source/Text/IntCheckerRus.lng
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Отдельные хеш файлы"
"Экран"
"Хеш файлы для каталогов"
"Предотвращать засыпание во время рассчётов"

"OK"
"Отмена"
Expand Down
1 change: 1 addition & 0 deletions source/Text/IntCheckerSpa.lng
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Archivos hash separados"
"Visualización"
"*Directory hash files"
"*Prevent sleep when calculating"

"Aceptar"
"Cancelar"
Expand Down
1 change: 1 addition & 0 deletions source/Text/history_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changes history:
2.8.2
- Fixed loading of hash lists in BSD format for several algorithms.
- Added ability to stop on first mismatch when checking hashes.
- Added ability to prevent computer going to sleep mode when calculating hashes.

2.8.1
- Only CRC32 and SHA1 can be used in panel comparision mode now (no need to use all algorithms).
Expand Down
1 change: 1 addition & 0 deletions source/Text/history_ru.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
2.8.2
- ���������� �������� ���-������ � ������� BSD ��� ��������� ����������.
- ��������� ����������� ��������� ��� ������ ������������ ��� �������� ������.
- ��������� ����������� ������������� ��������� ���������� �� ����� ��������� �����.

2.8.1
- ��� ������ ��������� ������� ��������� ������ CRC32 � SHA1 (��� ������ ������������ ��� ���������).
Expand Down

0 comments on commit b5457fc

Please sign in to comment.