+ fix: sync. INI-File exclusive reader / writer locking

+ enh: File-MRU handling
This commit is contained in:
Rainer Kottenhoff 2020-03-12 16:59:53 +01:00
parent e509b7748c
commit 4c2469693f
15 changed files with 551 additions and 4088 deletions

View File

@ -1 +1 @@
4
1

View File

@ -1 +1 @@
311
312

View File

@ -290,6 +290,7 @@
<ClCompile Include="src\minipath.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\Config\SimpleIni.h" />
<ClInclude Include="language\common_res.h" />
<ClInclude Include="src\Config.h" />
<ClInclude Include="src\Dialogs.h" />
@ -298,7 +299,6 @@
<ClInclude Include="src\Helpers.h" />
<ClInclude Include="src\minipath.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\SimpleIni.h" />
<ClInclude Include="src\version.h" />
</ItemGroup>
<ItemGroup>

View File

@ -66,7 +66,7 @@
<ClInclude Include="src\Config.h">
<Filter>H Source Files</Filter>
</ClInclude>
<ClInclude Include="src\SimpleIni.h">
<ClInclude Include="..\src\Config\SimpleIni.h">
<Filter>H Source Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -49,7 +49,7 @@ extern "C" int flagPosParam;
// ----------------------------------------------------------------------------
#include "SimpleIni.h"
#include "..\..\src\Config\SimpleIni.h"
#include "Config.h"
// ============================================================================
@ -68,6 +68,45 @@ constexpr bool SI_Success(const SI_Error rc) noexcept {
// ============================================================================
// ----------------------------------------------------------------------------
// No mechanism for EXCLUSIVE WRITE / SHARD READ:
// cause we need completely synchronized exclusive access for READ _and_ WRITE
// of complete file to preserve integrety of any transaction
// ----------------------------------------------------------------------------
HANDLE AcquireFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd)
{
HANDLE hFile = CreateFile(lpIniFilePath,
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
DWORD const flags = LOCKFILE_EXCLUSIVE_LOCK;
bool const bLocked = LockFileEx(hFile, flags, 0, MAXDWORD, 0, &rOvrLpd);
return (bLocked ? hFile : INVALID_HANDLE_VALUE);
}
// ----------------------------------------------------------------------------
bool ReleaseFileLock(HANDLE hFile, OVERLAPPED& rOvrLpd)
{
bool bUnLocked = true;
if (hFile != INVALID_HANDLE_VALUE) {
FlushFileBuffers(hFile);
bUnLocked = !UnlockFileEx(hFile, 0, MAXDWORD, 0, &rOvrLpd);
CloseHandle(hFile);
}
return bUnLocked;
}
// ============================================================================
// ============================================================================
static OVERLAPPED s_OvrLpd = { 0 };
static HANDLE s_INI_Hndl = INVALID_HANDLE_VALUE;
static CSimpleIni s_INI(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
@ -76,20 +115,36 @@ extern "C" BOOL LoadIniFile(LPCWSTR lpIniFilePath)
s_INI.Reset();
s_INI.SetSpaces(s_bSetSpaces);
s_INI.SetMultiLine(s_bUseMultiLine);
SI_Error const rc = s_INI.LoadFile(lpIniFilePath);
return SI_Success(rc);
s_INI_Hndl = AcquireFileLock(lpIniFilePath, s_OvrLpd);
if (s_INI_Hndl == INVALID_HANDLE_VALUE) {
return false;
}
return SI_Success(s_INI.LoadFile(s_INI_Hndl));
}
extern "C" bool IsIniFileLoaded()
{
return (s_INI_Hndl != INVALID_HANDLE_VALUE);
}
extern "C" void ReleaseIniFile()
{
s_INI.Reset();
ReleaseFileLock(s_INI_Hndl, s_OvrLpd);
s_INI_Hndl = INVALID_HANDLE_VALUE;
ZeroMemory(&s_OvrLpd, sizeof(OVERLAPPED));
}
extern "C" BOOL SaveIniFile(LPCWSTR lpIniFilePath)
extern "C" BOOL SaveIniFile()
{
s_INI.SetSpaces(s_bSetSpaces);
s_INI.SetMultiLine(s_bUseMultiLine);
SI_Error const rc = s_INI.SaveFile(lpIniFilePath, s_bWriteSIG);
SI_Error const rc = s_INI.SaveFile(s_INI_Hndl, s_bWriteSIG);
ReleaseIniFile();
return SI_Success(rc);
}
@ -97,7 +152,7 @@ extern "C" BOOL SaveIniFile(LPCWSTR lpIniFilePath)
//=============================================================================
//
// Manipulation of (cached) INI file
// Manipulation of (cached) ini file
//
//=============================================================================
@ -243,7 +298,7 @@ extern "C" BOOL IniClearAllSections(LPCWSTR lpPrefix, BOOL bRemoveEmpty)
{
if (lstrcmpi(section.pItem, lpPrefix) == 0)
{
s_INI.Delete(section.pItem, nullptr, bRemoveEmpty);
IniSectionClear(section.pItem, bRemoveEmpty);
}
}
return TRUE;
@ -259,7 +314,17 @@ extern "C" size_t IniFileGetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LP
LPWSTR lpReturnedString, size_t cchReturnedString)
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
SI_Error const rc = Ini.LoadFile(lpFilePath);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
StringCchCopyW(lpReturnedString, cchReturnedString, lpDefault);
return (size_t)lstrlen(lpReturnedString);
}
SI_Error const rc = Ini.LoadFile(hFile);
ReleaseFileLock(hFile, ovrLpd);
if (SI_Success(rc)) {
bool bHasMultiple = false;
StringCchCopyW(lpReturnedString, cchReturnedString, Ini.GetValue(lpSectionName, lpKeyName, lpDefault, &bHasMultiple));
@ -277,16 +342,24 @@ extern "C" BOOL IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCW
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
Ini.SetSpaces(s_bSetSpaces);
Ini.SetMultiLine(s_bUseMultiLine);
SI_Error rc = Ini.LoadFile(lpFilePath);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return false;
}
SI_Error rc = Ini.LoadFile(hFile);
if (SI_Success(rc))
{
SI_Error const res = Ini.SetValue(lpSectionName, lpKeyName, lpString, nullptr, !s_bUseMultiKey);
rc = SI_Success(res) ? SI_Error::SI_OK : SI_Error::SI_FAIL;
if (SI_Success(rc)) {
rc = Ini.SaveFile(lpFilePath, s_bWriteSIG);
rc = Ini.SaveFile(hFile, s_bWriteSIG);
}
}
ReleaseFileLock(hFile, ovrLpd);
return SI_Success(rc);
}
// ============================================================================
@ -295,8 +368,18 @@ extern "C" BOOL IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCW
extern "C" int IniFileGetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, int iDefault)
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
SI_Error const rc = Ini.LoadFile(lpFilePath);
if (SI_Success(rc)) {
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return iDefault;
}
SI_Error rc = Ini.LoadFile(hFile);
ReleaseFileLock(hFile, ovrLpd);
if (SI_Success(rc))
{
bool bHasMultiple = false;
int const iValue = Ini.GetLongValue(lpSectionName, lpKeyName, (long)iDefault, &bHasMultiple);
//assert(!bHasMultiple);
@ -311,13 +394,21 @@ extern "C" BOOL IniFileSetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
Ini.SetSpaces(s_bSetSpaces);
Ini.SetMultiLine(s_bUseMultiLine);
SI_Error rc = Ini.LoadFile(lpFilePath);
if (SI_Success(rc)) {
Ini.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, false, !s_bUseMultiKey);
rc = Ini.SaveFile(lpFilePath, s_bWriteSIG);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return false;
}
Ini.Reset();
SI_Error rc = Ini.LoadFile(hFile);
if (SI_Success(rc))
{
Ini.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, false, !s_bUseMultiKey);
rc = Ini.SaveFile(hFile, s_bWriteSIG);
}
ReleaseFileLock(hFile, ovrLpd);
return SI_Success(rc);
}
// ============================================================================
@ -326,10 +417,20 @@ extern "C" BOOL IniFileSetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR
extern "C" BOOL IniFileGetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, BOOL bDefault)
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
SI_Error const rc = Ini.LoadFile(lpFilePath);
if (SI_Success(rc)) {
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return bDefault;
}
SI_Error rc = Ini.LoadFile(hFile);
ReleaseFileLock(hFile, ovrLpd);
if (SI_Success(rc))
{
bool bHasMultiple = false;
BOOL const bValue = Ini.GetBoolValue(lpSectionName, lpKeyName, bDefault, &bHasMultiple);
bool const bValue = Ini.GetBoolValue(lpSectionName, lpKeyName, bDefault, &bHasMultiple);
//assert(!bHasMultiple);
return bValue;
}
@ -342,13 +443,21 @@ extern "C" BOOL IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
Ini.SetSpaces(s_bSetSpaces);
Ini.SetMultiLine(s_bUseMultiLine);
SI_Error rc = Ini.LoadFile(lpFilePath);
if (SI_Success(rc)) {
Ini.SetBoolValue(lpSectionName, lpKeyName, bValue, nullptr, !s_bUseMultiKey);
rc = Ini.SaveFile(lpFilePath, s_bWriteSIG);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return false;
}
Ini.Reset();
SI_Error rc = Ini.LoadFile(hFile);
if (SI_Success(rc))
{
Ini.SetBoolValue(lpSectionName, lpKeyName, bValue, nullptr, !s_bUseMultiKey);
rc = Ini.SaveFile(hFile, s_bWriteSIG);
}
ReleaseFileLock(hFile, ovrLpd);
return SI_Success(rc);
}
// ============================================================================
@ -357,26 +466,40 @@ extern "C" BOOL IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST
extern "C" BOOL IniFileDelete(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, BOOL bRemoveEmpty)
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
Ini.SetMultiLine(s_bUseMultiLine);
Ini.SetSpaces(s_bSetSpaces);
SI_Error rc = Ini.LoadFile(lpFilePath);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return false;
}
SI_Error rc = Ini.LoadFile(hFile);
if (SI_Success(rc))
{
Ini.Delete(lpSectionName, lpKeyName, bRemoveEmpty);
Ini.SetSpaces(s_bSetSpaces);
rc = Ini.SaveFile(lpFilePath, s_bWriteSIG);
rc = Ini.SaveFile(hFile, s_bWriteSIG);
}
Ini.Reset();
ReleaseFileLock(hFile, ovrLpd);
return SI_Success(rc);
}
// ============================================================================
extern "C" BOOL IniFileIterateSection(LPCWSTR lpFilePath, LPCWSTR lpSectionName, IterSectionFunc_t callBack)
{
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
SI_Error rc = Ini.LoadFile(lpFilePath);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(lpFilePath, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return false;
}
SI_Error rc = Ini.LoadFile(hFile);
ReleaseFileLock(hFile, ovrLpd);
if (SI_Success(rc))
{
bool bHasMultiple = false;
@ -397,7 +520,6 @@ extern "C" BOOL IniFileIterateSection(LPCWSTR lpFilePath, LPCWSTR lpSectionName,
//=============================================================================
//
// InitDefaultSettings()
@ -441,39 +563,52 @@ void InitDefaultSettings()
//
int CreateIniFile()
{
return(CreateIniFileEx(g_wchIniFile));
}
int CreateIniFileEx(LPCWSTR lpszIniFile) {
if (lpszIniFile && *lpszIniFile)
int result = 0;
if (g_wchIniFile[0] != L'\0')
{
WCHAR* pwchTail = StrRChrW(lpszIniFile, nullptr, L'\\');
WCHAR* pwchTail = StrRChrW(g_wchIniFile, NULL, L'\\');
if (pwchTail) {
*pwchTail = 0;
SHCreateDirectoryEx(nullptr, lpszIniFile, nullptr);
SHCreateDirectoryEx(NULL, g_wchIniFile, NULL);
*pwchTail = L'\\';
}
HANDLE hFile = CreateFile(lpszIniFile,
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE) {
if (GetFileSize(hFile, nullptr) == 0) {
DWORD dw;
WriteFile(hFile, (LPCVOID)L"\xFEFF[minipath]\r\n", 26, &dw, nullptr);
DWORD dwFileSize = 0UL;
if (!PathFileExists(g_wchIniFile)) {
HANDLE hFile = CreateFile(g_wchIniFile,
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE) {
CloseHandle(hFile);
}
CloseHandle(hFile);
return(1);
}
else {
return(0);
OVERLAPPED ovrLpd = { 0 };
HANDLE hFile = AcquireFileLock(g_wchIniFile, ovrLpd);
if (hFile == INVALID_HANDLE_VALUE) {
return result;
}
DWORD dwFSHigh = 0UL;
dwFileSize = GetFileSize(hFile, &dwFSHigh);
ReleaseFileLock(hFile, ovrLpd);
}
if ((dwFileSize == 0) && (dwFileSize != INVALID_FILE_SIZE)) {
result = IniFileSetString(g_wchIniFile, L"minipath", NULL, NULL);
}
else {
result = true;
}
return result;
}
else {
return(0);
}
return result;
}
//=============================================================================
//=============================================================================
//
@ -682,34 +817,39 @@ int TestIniFile() {
//
void LoadFlags()
{
LoadIniFile(g_wchIniFile);
__try {
const WCHAR* const Settings_Section2 = L"Settings2";
LoadIniFile(g_wchIniFile);
const WCHAR* const Settings_Section2 = L"Settings2";
if (!IniSectionGetString(Settings_Section2, L"PreferredLanguageLocaleName", L"",
g_tchPrefLngLocName, COUNTOF(g_tchPrefLngLocName)))
{
// try to fetch Locale Name from Notepad3.ini
IniFileGetString(g_wchNP3IniFile, L"Settings2", L"PreferredLanguageLocaleName", L"",
g_tchPrefLngLocName, COUNTOF(g_tchPrefLngLocName));
}
if (!flagNoReuseWindow) {
if (!IniSectionGetInt(Settings_Section2, L"ReuseWindow", 1))
flagNoReuseWindow = 1;
}
if (IniSectionGetInt(Settings_Section2, L"PortableMyDocs", 1))
flagPortableMyDocs = 1;
if (IniSectionGetInt(Settings_Section2, L"NoFadeHidden", 0))
flagNoFadeHidden = 1;
flagToolbarLook = IniSectionGetInt(Settings_Section2, L"ToolbarLook", 0);
flagToolbarLook = max(min(flagToolbarLook, 2), 0);
if (!IniSectionGetString(Settings_Section2, L"PreferredLanguageLocaleName", L"",
g_tchPrefLngLocName, COUNTOF(g_tchPrefLngLocName)))
{
// try to fetch Locale Name from Notepad3.ini
IniFileGetString(g_wchNP3IniFile, L"Settings2", L"PreferredLanguageLocaleName", L"",
g_tchPrefLngLocName, COUNTOF(g_tchPrefLngLocName));
}
if (!flagNoReuseWindow) {
if (!IniSectionGetInt(Settings_Section2, L"ReuseWindow", 1))
flagNoReuseWindow = 1;
__finally {
ReleaseIniFile();
}
if (IniSectionGetInt(Settings_Section2, L"PortableMyDocs", 1))
flagPortableMyDocs = 1;
if (IniSectionGetInt(Settings_Section2, L"NoFadeHidden", 0))
flagNoFadeHidden = 1;
flagToolbarLook = IniSectionGetInt(Settings_Section2, L"ToolbarLook", 0);
flagToolbarLook = max(min(flagToolbarLook, 2), 0);
ReleaseIniFile();
}
@ -733,6 +873,8 @@ extern "C" LPWSTR lpFilterArg;
void LoadSettings()
{
__try {
LoadIniFile(g_wchIniFile);
const WCHAR* const Settings_Section = L"Settings";
@ -865,7 +1007,10 @@ void LoadSettings()
Settings.crCustom[i] = Defaults.crCustom[i];
}
ReleaseIniFile();
}
__finally {
ReleaseIniFile();
}
}
@ -909,99 +1054,104 @@ void SaveSettings(BOOL bSaveSettingsNow)
return;
}
LoadIniFile(g_wchIniFile);
__try {
const WCHAR* const Settings_Section = L"Settings";
LoadIniFile(g_wchIniFile);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SaveSettings", bSaveSettings);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SingleClick", bSingleClick);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"TrackSelect", bTrackSelect);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"FullRowSelect", bFullRowSelect);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"UseRecycleBin", fUseRecycleBin);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"NoConfirmDelete", fNoConfirmDelete);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ClearReadOnly", bClearReadOnly);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"RenameOnCollision", bRenameOnCollision);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"FocusEdit", bFocusEdit);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"AlwaysOnTop", bAlwaysOnTop);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"MinimizeToTray", bMinimizeToTray);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"TransparentMode", g_bTransparentMode);
const WCHAR* const Settings_Section = L"Settings";
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SaveSettings", bSaveSettings);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SingleClick", bSingleClick);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"TrackSelect", bTrackSelect);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"FullRowSelect", bFullRowSelect);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"UseRecycleBin", fUseRecycleBin);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"NoConfirmDelete", fNoConfirmDelete);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ClearReadOnly", bClearReadOnly);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"RenameOnCollision", bRenameOnCollision);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"FocusEdit", bFocusEdit);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"AlwaysOnTop", bAlwaysOnTop);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"MinimizeToTray", bMinimizeToTray);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"TransparentMode", g_bTransparentMode);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"EscFunction", iEscFunction);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"StartupDirectory", iStartupDir);
if (Settings.iStartupDir == 1) {
IniSectionSetString(Settings_Section, L"MRUDirectory", Settings.szCurDir);
}
if (!Settings.bNP3sFavoritesSettings) {
PathRelativeToApp(Settings.g_tchFavoritesDir, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
IniSectionSetString(Settings_Section, L"Favorites", wchTmp);
}
PathRelativeToApp(Settings.szQuickview, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
IniSectionSetString(Settings_Section, L"Quikview.exe", wchTmp);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"Quikview.exe", szQuickviewParams);
PathRelativeToApp(Settings.tchOpenWithDir, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
if (lstrcmp(wchTmp, Defaults.tchOpenWithDir) != 0) {
IniSectionSetString(Settings_Section, L"OpenWithDir", wchTmp);
}
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"FillMask", dwFillMask);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"SortOptions", nSortFlags);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SortReverse", fSortRev);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"FileFilter", tchFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"NegativeFilter", bNegFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"DefColorNoFilter", bDefCrNoFilt);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"DefColorFilter", bDefCrFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"ColorNoFilter", crNoFilt);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"ColorFilter", crFilter);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"ToolbarButtons", tchToolbarButtons);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowToolbar", bShowToolbar);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowStatusbar", bShowStatusbar);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowDriveBox", bShowDriveBox);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"GotoDlgSizeX", cxGotoDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"OpenWithDlgSizeX", cxOpenWithDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"OpenWithDlgSizeY", cyOpenWithDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"CopyMoveDlgSizeX", cxCopyMoveDlg);
// cleanup
IniSectionDelete(Settings_Section, L"WriteTest", FALSE);
/*
SaveSettingsNow(): query Window Dimensions
*/
if (bSaveSettingsNow)
{
WINDOWPLACEMENT wndpl;
ZeroMemory(&wndpl, sizeof(WINDOWPLACEMENT));
// GetWindowPlacement
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwndMain, &wndpl);
Settings.wi.x = wndpl.rcNormalPosition.left;
Settings.wi.y = wndpl.rcNormalPosition.top;
Settings.wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
Settings.wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
}
WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32];
int ResX = GetSystemMetrics(SM_CXSCREEN);
int ResY = GetSystemMetrics(SM_CYSCREEN);
wsprintf(tchPosX, L"%ix%i PosX", ResX, ResY);
wsprintf(tchPosY, L"%ix%i PosY", ResX, ResY);
wsprintf(tchSizeX, L"%ix%i SizeX", ResX, ResY);
wsprintf(tchSizeY, L"%ix%i SizeY", ResX, ResY);
wsprintf(tchMaximized, L"%ix%i Maximized", ResX, ResY);
const WCHAR* const Windows_Section = L"Window";
IniSectionSetInt(Windows_Section, tchPosX, Settings.wi.x);
IniSectionSetInt(Windows_Section, tchPosY, Settings.wi.y);
IniSectionSetInt(Windows_Section, tchSizeX, Settings.wi.cx);
IniSectionSetInt(Windows_Section, tchSizeY, Settings.wi.cy);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"EscFunction", iEscFunction);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"StartupDirectory", iStartupDir);
if (Settings.iStartupDir == 1) {
IniSectionSetString(Settings_Section, L"MRUDirectory", Settings.szCurDir);
}
if (!Settings.bNP3sFavoritesSettings) {
PathRelativeToApp(Settings.g_tchFavoritesDir, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
IniSectionSetString(Settings_Section, L"Favorites", wchTmp);
__finally {
SaveIniFile();
}
PathRelativeToApp(Settings.szQuickview, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
IniSectionSetString(Settings_Section, L"Quikview.exe", wchTmp);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"Quikview.exe", szQuickviewParams);
PathRelativeToApp(Settings.tchOpenWithDir, wchTmp, COUNTOF(wchTmp), FALSE, TRUE, flagPortableMyDocs);
if (lstrcmp(wchTmp, Defaults.tchOpenWithDir) != 0) {
IniSectionSetString(Settings_Section, L"OpenWithDir", wchTmp);
}
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"FillMask", dwFillMask);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"SortOptions", nSortFlags);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"SortReverse", fSortRev);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"FileFilter", tchFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"NegativeFilter", bNegFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"DefColorNoFilter", bDefCrNoFilt);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"DefColorFilter", bDefCrFilter);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"ColorNoFilter", crNoFilt);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"ColorFilter", crFilter);
SAVE_STRING_IF_NOT_EQ_DEFAULT(L"ToolbarButtons", tchToolbarButtons);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowToolbar", bShowToolbar);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowStatusbar", bShowStatusbar);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, L"ShowDriveBox", bShowDriveBox);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"GotoDlgSizeX", cxGotoDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"OpenWithDlgSizeX", cxOpenWithDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"OpenWithDlgSizeY", cyOpenWithDlg);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, L"CopyMoveDlgSizeX", cxCopyMoveDlg);
// cleanup
IniSectionDelete(Settings_Section, L"WriteTest", FALSE);
/*
SaveSettingsNow(): query Window Dimensions
*/
if (bSaveSettingsNow)
{
WINDOWPLACEMENT wndpl;
ZeroMemory(&wndpl, sizeof(WINDOWPLACEMENT));
// GetWindowPlacement
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwndMain, &wndpl);
Settings.wi.x = wndpl.rcNormalPosition.left;
Settings.wi.y = wndpl.rcNormalPosition.top;
Settings.wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
Settings.wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
}
WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32];
int ResX = GetSystemMetrics(SM_CXSCREEN);
int ResY = GetSystemMetrics(SM_CYSCREEN);
wsprintf(tchPosX, L"%ix%i PosX", ResX, ResY);
wsprintf(tchPosY, L"%ix%i PosY", ResX, ResY);
wsprintf(tchSizeX, L"%ix%i SizeX", ResX, ResY);
wsprintf(tchSizeY, L"%ix%i SizeY", ResX, ResY);
wsprintf(tchMaximized, L"%ix%i Maximized", ResX, ResY);
const WCHAR* const Windows_Section = L"Window";
IniSectionSetInt(Windows_Section, tchPosX, Settings.wi.x);
IniSectionSetInt(Windows_Section, tchPosY, Settings.wi.y);
IniSectionSetInt(Windows_Section, tchSizeX, Settings.wi.cx);
IniSectionSetInt(Windows_Section, tchSizeY, Settings.wi.cy);
SaveIniFile(g_wchIniFile);
}
//=============================================================================

View File

@ -34,12 +34,11 @@ extern "C" {
int FindIniFile();
int TestIniFile();
int CreateIniFile();
int CreateIniFileEx(LPCWSTR);
// ----------------------------------------------------------------------------
BOOL LoadIniFile(LPCWSTR lpIniFilePath);
BOOL SaveIniFile(LPCWSTR lpIniFilePath);
BOOL SaveIniFile();
void ReleaseIniFile();
size_t IniSectionGetString(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR lpDefault,

View File

@ -2687,87 +2687,92 @@ INT_PTR CALLBACK FindTargetDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lPar
int i;
// input validation
if ((IsDlgButtonChecked(hwnd,IDC_TARGET) && GetDlgItemText(hwnd,IDC_TARGETPATH,tch,COUNTOF(tch)) == 0) ||
(IsDlgButtonChecked(hwnd,IDC_SENDDROPMSG) && StrIsEmpty(szTargetWndClass)) ||
(IsDlgButtonChecked(hwnd,IDC_USEDDE) &&
(GetDlgItemText(hwnd,IDC_DDEMSG,tch,COUNTOF(tch)) == 0 ||
GetDlgItemText(hwnd,IDC_DDEAPP,tch,COUNTOF(tch)) == 0 ||
GetDlgItemText(hwnd,IDC_DDETOPIC,tch,COUNTOF(tch)) == 0)))
if ((IsDlgButtonChecked(hwnd, IDC_TARGET) && GetDlgItemText(hwnd, IDC_TARGETPATH, tch, COUNTOF(tch)) == 0) ||
(IsDlgButtonChecked(hwnd, IDC_SENDDROPMSG) && StrIsEmpty(szTargetWndClass)) ||
(IsDlgButtonChecked(hwnd, IDC_USEDDE) &&
(GetDlgItemText(hwnd, IDC_DDEMSG, tch, COUNTOF(tch)) == 0 ||
GetDlgItemText(hwnd, IDC_DDEAPP, tch, COUNTOF(tch)) == 0 ||
GetDlgItemText(hwnd, IDC_DDETOPIC, tch, COUNTOF(tch)) == 0)))
ErrorMessage(1,IDS_ERR_INVALIDTARGET);
ErrorMessage(1, IDS_ERR_INVALIDTARGET);
else {
else {
__try {
LoadIniFile(g_wchIniFile);
const WCHAR* const TargetApp_Section = L"Target Application";
i = (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_LAUNCH));
eUseTargetApplication = ((i) ? UTA_UNDEFINED : UTA_LAUNCH_TARGET);
IniSectionSetInt(TargetApp_Section,L"UseTargetApplication",eUseTargetApplication);
IniSectionSetInt(TargetApp_Section, L"UseTargetApplication", eUseTargetApplication);
if (eUseTargetApplication != UTA_UNDEFINED) {
GetDlgItemText(hwnd,IDC_TARGETPATH,tch,COUNTOF(tch));
ExtractFirstArgument(tch,szTargetApplication,szTargetApplicationParams);
GetDlgItemText(hwnd, IDC_TARGETPATH, tch, COUNTOF(tch));
ExtractFirstArgument(tch, szTargetApplication, szTargetApplicationParams);
}
else {
lstrcpy(szTargetApplication,L"");
lstrcpy(szTargetApplicationParams,L"");
lstrcpy(szTargetApplication, L"");
lstrcpy(szTargetApplicationParams, L"");
}
IniSectionSetString(TargetApp_Section,L"TargetApplicationPath",szTargetApplication);
IniSectionSetString(TargetApp_Section,L"TargetApplicationParams",szTargetApplicationParams);
IniSectionSetString(TargetApp_Section, L"TargetApplicationPath", szTargetApplication);
IniSectionSetString(TargetApp_Section, L"TargetApplicationParams", szTargetApplicationParams);
if (eUseTargetApplication == UTA_UNDEFINED) {
eTargetApplicationMode = TAM_ALWAYS_RUN;
IniSectionSetInt(TargetApp_Section,L"TargetApplicationMode",eTargetApplicationMode);
IniSectionSetInt(TargetApp_Section, L"TargetApplicationMode", eTargetApplicationMode);
}
else {
if (BST_CHECKED == IsDlgButtonChecked(hwnd,IDC_ALWAYSRUN)) {
if (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_ALWAYSRUN)) {
eTargetApplicationMode = TAM_ALWAYS_RUN;
IniSectionSetInt(TargetApp_Section,L"TargetApplicationMode",eTargetApplicationMode);
IniSectionSetInt(TargetApp_Section, L"TargetApplicationMode", eTargetApplicationMode);
}
else if (BST_CHECKED == IsDlgButtonChecked(hwnd,IDC_SENDDROPMSG)) {
else if (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_SENDDROPMSG)) {
eTargetApplicationMode = TAM_SEND_DROP_MSG;
IniSectionSetInt(TargetApp_Section,L"TargetApplicationMode",eTargetApplicationMode);
IniSectionSetInt(TargetApp_Section, L"TargetApplicationMode", eTargetApplicationMode);
}
else {
eTargetApplicationMode = TAM_SEND_DDE_MSG;
IniSectionSetInt(TargetApp_Section,L"TargetApplicationMode",eTargetApplicationMode);
IniSectionSetInt(TargetApp_Section, L"TargetApplicationMode", eTargetApplicationMode);
}
}
if (BST_CHECKED == IsDlgButtonChecked(hwnd,IDC_SENDDROPMSG) && !i) {
lstrcpy(szTargetApplicationWndClass,szTargetWndClass);
IniSectionSetString(TargetApp_Section,L"TargetApplicationWndClass",szTargetApplicationWndClass);
if (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_SENDDROPMSG) && !i) {
lstrcpy(szTargetApplicationWndClass, szTargetWndClass);
IniSectionSetString(TargetApp_Section, L"TargetApplicationWndClass", szTargetApplicationWndClass);
}
else {
lstrcpy(szTargetApplicationWndClass,L"");
IniSectionSetString(TargetApp_Section,L"TargetApplicationWndClass",szTargetApplicationWndClass);
lstrcpy(szTargetApplicationWndClass, L"");
IniSectionSetString(TargetApp_Section, L"TargetApplicationWndClass", szTargetApplicationWndClass);
}
i = (BST_CHECKED == IsDlgButtonChecked(hwnd,IDC_USEDDE));
i = (BST_CHECKED == IsDlgButtonChecked(hwnd, IDC_USEDDE));
if (i)
GetDlgItemText(hwnd,IDC_DDEMSG,szDDEMsg,COUNTOF(szDDEMsg));
GetDlgItemText(hwnd, IDC_DDEMSG, szDDEMsg, COUNTOF(szDDEMsg));
else
lstrcpy(szDDEMsg,L"");
IniSectionSetString(TargetApp_Section,L"DDEMessage",szDDEMsg);
lstrcpy(szDDEMsg, L"");
IniSectionSetString(TargetApp_Section, L"DDEMessage", szDDEMsg);
if (i)
GetDlgItemText(hwnd,IDC_DDEAPP,szDDEApp,COUNTOF(szDDEApp));
GetDlgItemText(hwnd, IDC_DDEAPP, szDDEApp, COUNTOF(szDDEApp));
else
lstrcpy(szDDEApp,L"");
IniSectionSetString(TargetApp_Section,L"DDEApplication",szDDEApp);
lstrcpy(szDDEApp, L"");
IniSectionSetString(TargetApp_Section, L"DDEApplication", szDDEApp);
if (i)
GetDlgItemText(hwnd,IDC_DDETOPIC,szDDETopic,COUNTOF(szDDETopic));
GetDlgItemText(hwnd, IDC_DDETOPIC, szDDETopic, COUNTOF(szDDETopic));
else
lstrcpy(szDDETopic,L"");
IniSectionSetString(TargetApp_Section,L"DDETopic",szDDETopic);
lstrcpy(szDDETopic, L"");
IniSectionSetString(TargetApp_Section, L"DDETopic", szDDETopic);
SaveIniFile(g_wchIniFile);
EndDialog(hwnd,IDOK);
}
__finally {
SaveIniFile();
}
EndDialog(hwnd, IDOK);
}
}
break;

View File

@ -1529,28 +1529,33 @@ BOOL MRU_Load(LPMRULIST pmru) {
WCHAR tchItem[1024];
MRU_Empty(pmru);
LoadIniFile(g_wchIniFile);
__try {
LoadIniFile(g_wchIniFile);
const WCHAR* const RegKey_Section = pmru->szRegKey;
const WCHAR* const RegKey_Section = pmru->szRegKey;
for (i = 0; i < pmru->iSize; i++) {
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
if (IniSectionGetString(RegKey_Section, tchName, L"", tchItem, COUNTOF(tchItem))) {
size_t const len = (size_t)lstrlen(tchItem);
if ((len > 0) && (tchItem[0] == L'"') && (tchItem[len - 1] == L'"')) {
MoveMemory(tchItem, (tchItem + 1), len * sizeof(WCHAR));
tchItem[len - 2] = L'\0'; // clear dangling '"'
for (i = 0; i < pmru->iSize; i++) {
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
if (IniSectionGetString(RegKey_Section, tchName, L"", tchItem, COUNTOF(tchItem))) {
size_t const len = (size_t)lstrlen(tchItem);
if ((len > 0) && (tchItem[0] == L'"') && (tchItem[len - 1] == L'"')) {
MoveMemory(tchItem, (tchItem + 1), len * sizeof(WCHAR));
tchItem[len - 2] = L'\0'; // clear dangling '"'
}
pmru->pszItems[n++] = StrDup(tchItem);
}
pmru->pszItems[n++] = StrDup(tchItem);
}
}
ReleaseIniFile();
__finally {
ReleaseIniFile();
}
return(1);
}
BOOL MRU_Save(LPMRULIST pmru) {
if (LoadIniFile(g_wchIniFile)) {
__try {
LoadIniFile(g_wchIniFile);
WCHAR tchName[32];
WCHAR tchItem[1024] = { L'\0' };
@ -1565,10 +1570,11 @@ BOOL MRU_Save(LPMRULIST pmru) {
IniSectionSetString(RegKey_Section, tchName, tchItem);
}
}
SaveIniFile(g_wchIniFile);
return TRUE;
}
return FALSE;
__finally {
SaveIniFile(g_wchIniFile);
}
return TRUE;
}
void MRU_LoadToCombobox(HWND hwnd,LPCWSTR pszKey)

File diff suppressed because it is too large Load Diff

View File

@ -1162,37 +1162,41 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance)
DeleteObject(hbmpCopy);
// Load toolbar labels
LoadIniFile(g_wchIniFile);
const WCHAR* const ToolbarLabels_Section = L"Toolbar Labels";
__try {
LoadIniFile(g_wchIniFile);
const WCHAR* const ToolbarLabels_Section = L"Toolbar Labels";
n = 0;
for (i = 0; i < COUNTOF(tbbMainWnd); i++) {
n = 0;
for (i = 0; i < COUNTOF(tbbMainWnd); i++) {
if (tbbMainWnd[i].fsStyle == TBSTYLE_SEP)
continue;
else
n++;
if (tbbMainWnd[i].fsStyle == TBSTYLE_SEP)
continue;
else
n++;
wsprintf(tchIndex,L"%02i",n);
wsprintf(tchIndex, L"%02i", n);
if (IniSectionGetString(ToolbarLabels_Section,tchIndex,L"",tchDesc,COUNTOF(tchDesc)) &&
lstrcmpi(tchDesc,L"(none)") != 0) {
if (IniSectionGetString(ToolbarLabels_Section, tchIndex, L"", tchDesc, COUNTOF(tchDesc)) &&
lstrcmpi(tchDesc, L"(none)") != 0) {
tbbMainWnd[i].iString = SendMessage(hwndToolbar,TB_ADDSTRING,0,(LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
tbbMainWnd[i].iString = SendMessage(hwndToolbar, TB_ADDSTRING, 0, (LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
}
else if ((n == 5 || n == 8) && lstrcmpi(tchDesc, L"(none)") != 0) {
GetLngString(42000 + n, tchDesc, COUNTOF(tchDesc));
tbbMainWnd[i].iString = SendMessage(hwndToolbar, TB_ADDSTRING, 0, (LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
}
else
tbbMainWnd[i].fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT);
}
else if ((n == 5 || n == 8) && lstrcmpi(tchDesc,L"(none)") != 0) {
GetLngString(42000+n,tchDesc,COUNTOF(tchDesc));
tbbMainWnd[i].iString = SendMessage(hwndToolbar,TB_ADDSTRING,0,(LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
}
else
tbbMainWnd[i].fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT);
}
ReleaseIniFile();
__finally {
ReleaseIniFile();
}
SendMessage(hwndToolbar,TB_SETEXTENDEDSTYLE,0,
SendMessage(hwndToolbar,TB_GETEXTENDEDSTYLE,0,0) | TBSTYLE_EX_MIXEDBUTTONS);
@ -2112,12 +2116,14 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
if (StrIsEmpty(g_wchIniFile)) {
if (StrIsNotEmpty(g_wchIniFile2)) {
if (CreateIniFileEx(g_wchIniFile2)) {
lstrcpy(g_wchIniFile,g_wchIniFile2);
lstrcpy(g_wchIniFile, g_wchIniFile2);
if (CreateIniFile()) {
lstrcpy(g_wchIniFile2,L"");
}
else
else {
lstrcpy(g_wchIniFile, L""); // reset
bCreateFailure = TRUE;
}
}
else
break;
@ -3323,31 +3329,34 @@ void LoadTargetParamsOnce(void)
if (fLoaded)
return;
LoadIniFile(g_wchIniFile);
const WCHAR* const TargetApp_Section = L"Target Application";
__try {
LoadIniFile(g_wchIniFile);
const WCHAR* const TargetApp_Section = L"Target Application";
if (IniSectionGetInt(TargetApp_Section,L"UseTargetApplication",0xFB) != 0xFB) {
eUseTargetApplication = IniSectionGetInt(TargetApp_Section,L"UseTargetApplication",eUseTargetApplication);
eTargetApplicationMode = IniSectionGetInt(TargetApp_Section,L"TargetApplicationMode",eTargetApplicationMode);
IniSectionGetString(TargetApp_Section,L"TargetApplicationPath",szTargetApplication,szTargetApplication,COUNTOF(szTargetApplication));
IniSectionGetString(TargetApp_Section,L"TargetApplicationParams",szTargetApplicationParams,szTargetApplicationParams,COUNTOF(szTargetApplicationParams));
IniSectionGetString(TargetApp_Section,L"TargetApplicationWndClass",szTargetApplicationWndClass,szTargetApplicationWndClass,COUNTOF(szTargetApplicationWndClass));
IniSectionGetString(TargetApp_Section,L"DDEMessage",szDDEMsg,szDDEMsg,COUNTOF(szDDEMsg));
IniSectionGetString(TargetApp_Section,L"DDEApplication",szDDEApp,szDDEApp,COUNTOF(szDDEApp));
IniSectionGetString(TargetApp_Section,L"DDETopic",szDDETopic,szDDETopic,COUNTOF(szDDETopic));
if (IniSectionGetInt(TargetApp_Section, L"UseTargetApplication", 0xFB) != 0xFB) {
eUseTargetApplication = IniSectionGetInt(TargetApp_Section, L"UseTargetApplication", eUseTargetApplication);
eTargetApplicationMode = IniSectionGetInt(TargetApp_Section, L"TargetApplicationMode", eTargetApplicationMode);
IniSectionGetString(TargetApp_Section, L"TargetApplicationPath", szTargetApplication, szTargetApplication, COUNTOF(szTargetApplication));
IniSectionGetString(TargetApp_Section, L"TargetApplicationParams", szTargetApplicationParams, szTargetApplicationParams, COUNTOF(szTargetApplicationParams));
IniSectionGetString(TargetApp_Section, L"TargetApplicationWndClass", szTargetApplicationWndClass, szTargetApplicationWndClass, COUNTOF(szTargetApplicationWndClass));
IniSectionGetString(TargetApp_Section, L"DDEMessage", szDDEMsg, szDDEMsg, COUNTOF(szDDEMsg));
IniSectionGetString(TargetApp_Section, L"DDEApplication", szDDEApp, szDDEApp, COUNTOF(szDDEApp));
IniSectionGetString(TargetApp_Section, L"DDETopic", szDDETopic, szDDETopic, COUNTOF(szDDETopic));
}
else if ((eUseTargetApplication != UTA_UNDEFINED) && StrIsEmpty(szTargetApplication)) {
eUseTargetApplication = UTA_LAUNCH_TARGET;
eTargetApplicationMode = TAM_SEND_DROP_MSG;
lstrcpy(szTargetApplication, L"Notepad3.exe");
lstrcpy(szTargetApplicationParams, L"");
lstrcpy(szTargetApplicationWndClass, L"Notepad3");
lstrcpy(szDDEMsg, L"");
lstrcpy(szDDEApp, L"");
lstrcpy(szDDETopic, L"");
}
}
else if ((eUseTargetApplication != UTA_UNDEFINED) && StrIsEmpty(szTargetApplication)) {
eUseTargetApplication = UTA_LAUNCH_TARGET;
eTargetApplicationMode = TAM_SEND_DROP_MSG;
lstrcpy(szTargetApplication,L"Notepad3.exe");
lstrcpy(szTargetApplicationParams,L"");
lstrcpy(szTargetApplicationWndClass,L"Notepad3");
lstrcpy(szDDEMsg,L"");
lstrcpy(szDDEApp,L"");
lstrcpy(szDDETopic,L"");
__finally {
ReleaseIniFile();
}
ReleaseIniFile();
fLoaded = TRUE;
}

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.20.311.4"
version="5.20.312.1"
type="win32"
/>
<description>Notepad3 RC3</description>

View File

@ -83,6 +83,12 @@ constexpr bool SI_Success(const SI_Error rc) noexcept {
// ============================================================================
// ----------------------------------------------------------------------------
// No mechanism for EXCLUSIVE WRITE / SHARD READ:
// cause we need completely synchronized exclusive access for READ _and_ WRITE
// of complete file to preserve integrety of any transaction
// ----------------------------------------------------------------------------
HANDLE AcquireFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd)
{
HANDLE hFile = CreateFile(lpIniFilePath,
@ -97,7 +103,6 @@ HANDLE AcquireFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd)
// ----------------------------------------------------------------------------
bool ReleaseFileLock(HANDLE hFile, OVERLAPPED& rOvrLpd)
{
bool bUnLocked = true;
@ -112,7 +117,6 @@ bool ReleaseFileLock(HANDLE hFile, OVERLAPPED& rOvrLpd)
// ============================================================================
// ============================================================================
static OVERLAPPED s_OvrLpd = { 0 };
@ -308,7 +312,7 @@ extern "C" bool IniClearAllSections(LPCWSTR lpPrefix, bool bRemoveEmpty)
{
if (StringCchCompareNI(section.pItem, len, lpPrefix, len) == 0)
{
s_INI.Delete(section.pItem, nullptr, bRemoveEmpty);
IniSectionClear(section.pItem, bRemoveEmpty);
}
}
return true;
@ -1831,14 +1835,8 @@ bool SaveAllSettings(bool bForceSaveSettings)
MRU_Save(Globals.pFileMRU);
}
else {
int const cnt = MRU_Count(Globals.pFileMRU);
if (cnt == 0) {
MRU_Empty(Globals.pFileMRU);
MRU_Save(Globals.pFileMRU); // intension is to destroy the multi-instance saved list
}
else {
MRU_MergeSave(Globals.pFileMRU, true, Flags.RelativeFileMRU, Flags.PortableMyDocs);
}
//int const cnt = MRU_Count(Globals.pFileMRU);
MRU_MergeSave(Globals.pFileMRU, true, Flags.RelativeFileMRU, Flags.PortableMyDocs);
}
if (!Settings.SaveFindReplace) {
@ -2040,34 +2038,33 @@ bool MRU_AddFile(LPMRULIST pmru, LPCWSTR pszFile, bool bRelativePath, bool bUnex
bool MRU_Delete(LPMRULIST pmru, int iIndex)
{
if (pmru) {
int i;
if (iIndex < 0 || iIndex > pmru->iSize - 1) {
return false;
}
if (pmru->pszItems[iIndex]) {
LocalFree(pmru->pszItems[iIndex]); // StrDup()
}
if (pmru->pszBookMarks[iIndex]) {
LocalFree(pmru->pszBookMarks[iIndex]); // StrDup()
}
bool bZeroMoved = false;
for (i = iIndex; (i < pmru->iSize - 1) && !bZeroMoved; ++i)
if (iIndex >= 0 || iIndex < pmru->iSize)
{
pmru->pszItems[i] = pmru->pszItems[i + 1];
pmru->iEncoding[i] = pmru->iEncoding[i + 1];
pmru->iCaretPos[i] = pmru->iCaretPos[i + 1];
pmru->iSelAnchPos[i] = pmru->iSelAnchPos[i + 1];
pmru->pszBookMarks[i] = pmru->pszBookMarks[i + 1];
if (pmru->pszItems[iIndex]) {
LocalFree(pmru->pszItems[iIndex]); // StrDup()
}
if (pmru->pszBookMarks[iIndex]) {
LocalFree(pmru->pszBookMarks[iIndex]); // StrDup()
}
bool bZeroMoved = false;
for (int i = iIndex; (i < pmru->iSize - 1) && !bZeroMoved; ++i)
{
pmru->pszItems[i] = pmru->pszItems[i + 1];
pmru->iEncoding[i] = pmru->iEncoding[i + 1];
pmru->iCaretPos[i] = pmru->iCaretPos[i + 1];
pmru->iSelAnchPos[i] = pmru->iSelAnchPos[i + 1];
pmru->pszBookMarks[i] = pmru->pszBookMarks[i + 1];
bZeroMoved = (NULL == pmru->pszItems[i + 1]);
bZeroMoved = (NULL == pmru->pszItems[i + 1]);
pmru->pszItems[i + 1] = NULL;
pmru->iEncoding[i + 1] = 0;
pmru->iCaretPos[i + 1] = -1;
pmru->iSelAnchPos[i + 1] = -1;
pmru->pszBookMarks[i + 1] = NULL;
pmru->pszItems[i + 1] = NULL;
pmru->iEncoding[i + 1] = 0;
pmru->iCaretPos[i + 1] = -1;
pmru->iSelAnchPos[i + 1] = -1;
pmru->pszBookMarks[i + 1] = NULL;
}
return true;
}
return true;
}
return false;
}
@ -2117,45 +2114,54 @@ bool MRU_Load(LPMRULIST pmru, bool bFileProps)
{
if (pmru)
{
MRU_Empty(pmru);
//if (bFileProps) { ClearDestinationsOnRecentDocs(); }
const WCHAR* const RegKey_Section = pmru->szRegKey;
bool const bOpendByMe = !IsIniFileLoaded() ? OpenSettingsFile() : false;
int n = 0;
for (int i = 0; i < pmru->iSize; ++i)
{
WCHAR tchName[32] = { L'\0' };
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
WCHAR tchItem[2048] = { L'\0' };
if (IniSectionGetString(RegKey_Section, tchName, L"", tchItem, COUNTOF(tchItem)))
if (IsIniFileLoaded()) {
MRU_Empty(pmru);
//if (bFileProps) { ClearDestinationsOnRecentDocs(); }
const WCHAR* const RegKey_Section = pmru->szRegKey;
for (int i = 0; i < pmru->iSize; ++i)
{
size_t const len = StringCchLen(tchItem, 0);
if ((len > 0) && (tchItem[0] == L'"') && (tchItem[len - 1] == L'"')) {
MoveMemory(tchItem, (tchItem + 1), len * sizeof(WCHAR));
tchItem[len - 2] = L'\0'; // clear dangling '"'
WCHAR tchName[32] = { L'\0' };
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
WCHAR tchItem[2048] = { L'\0' };
if (IniSectionGetString(RegKey_Section, tchName, L"", tchItem, COUNTOF(tchItem)))
{
size_t const len = StringCchLen(tchItem, 0);
if ((len > 0) && (tchItem[0] == L'"') && (tchItem[len - 1] == L'"')) {
MoveMemory(tchItem, (tchItem + 1), len * sizeof(WCHAR));
tchItem[len - 2] = L'\0'; // clear dangling '"'
}
pmru->pszItems[n] = StrDup(tchItem);
StringCchPrintf(tchName, COUNTOF(tchName), L"ENC%.2i", i + 1);
int const iCP = (cpi_enc_t)IniSectionGetInt(RegKey_Section, tchName, 0);
pmru->iEncoding[n] = bFileProps ? (cpi_enc_t)Encoding_MapIniSetting(true, iCP) : 0;
StringCchPrintf(tchName, COUNTOF(tchName), L"POS%.2i", i + 1);
pmru->iCaretPos[n] = bFileProps ? ((Settings.PreserveCaretPos) ? IniSectionGetInt(RegKey_Section, tchName, 0) : -1) : -1;
StringCchPrintf(tchName, COUNTOF(tchName), L"ANC%.2i", i + 1);
pmru->iSelAnchPos[n] = bFileProps ? ((Settings.PreserveCaretPos) ? IniSectionGetInt(RegKey_Section, tchName, 0) : -1) : -1;
StringCchPrintf(tchName, COUNTOF(tchName), L"BMRK%.2i", i + 1);
WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' };
IniSectionGetString(RegKey_Section, tchName, L"", wchBookMarks, COUNTOF(wchBookMarks));
pmru->pszBookMarks[n] = bFileProps ? StrDup(wchBookMarks) : nullptr;
++n;
}
pmru->pszItems[n] = StrDup(tchItem);
StringCchPrintf(tchName, COUNTOF(tchName), L"ENC%.2i", i + 1);
int const iCP = (cpi_enc_t)IniSectionGetInt(RegKey_Section, tchName, 0);
pmru->iEncoding[n] = bFileProps ? (cpi_enc_t)Encoding_MapIniSetting(true, iCP) : 0;
StringCchPrintf(tchName, COUNTOF(tchName), L"POS%.2i", i + 1);
pmru->iCaretPos[n] = bFileProps ? ((Settings.PreserveCaretPos) ? IniSectionGetInt(RegKey_Section, tchName, 0) : -1) : -1;
StringCchPrintf(tchName, COUNTOF(tchName), L"ANC%.2i", i + 1);
pmru->iSelAnchPos[n] = bFileProps ? ((Settings.PreserveCaretPos) ? IniSectionGetInt(RegKey_Section, tchName, 0) : -1) : -1;
StringCchPrintf(tchName, COUNTOF(tchName), L"BMRK%.2i", i + 1);
WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' };
IniSectionGetString(RegKey_Section, tchName, L"", wchBookMarks, COUNTOF(wchBookMarks));
pmru->pszBookMarks[n] = bFileProps ? StrDup(wchBookMarks) : nullptr;
++n;
}
if (bOpendByMe) {
CloseSettingsFile(true);
}
}
if (bFileProps) {
WCHAR szFilePath[MAX_PATH + 1];
for (int i = n - 1; i >= 0; --i)
@ -2176,7 +2182,6 @@ bool MRU_Load(LPMRULIST pmru, bool bFileProps)
void MRU_Save(LPMRULIST pmru)
{
if (pmru) {
bool const bOpendByMe = !IsIniFileLoaded() ? OpenSettingsFile() : false;
if (IsIniFileLoaded()) {
@ -2211,9 +2216,9 @@ void MRU_Save(LPMRULIST pmru)
}
}
}
}
if (bOpendByMe) {
CloseSettingsFile(true);
if (bOpendByMe) {
CloseSettingsFile(true);
}
}
}
}

View File

@ -1652,6 +1652,13 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
if (Globals.hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hDlgIcon); }
// sync with other instances
if (Settings.SaveRecentFiles) {
if (MRU_MergeSave(Globals.pFileMRU, true, Flags.RelativeFileMRU, Flags.PortableMyDocs)) {
MRU_Load(Globals.pFileMRU, true);
}
}
SHFILEINFO shfi;
ZeroMemory(&shfi, sizeof(SHFILEINFO));
LVCOLUMN lvc = { LVCF_FMT|LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
@ -1716,6 +1723,10 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
RemoveProp(hwnd,L"it");
FreeMem(lpit);
if (Settings.SaveRecentFiles) {
MRU_Save(Globals.pFileMRU); // last instance on save wins
}
Settings.SaveRecentFiles = IsButtonChecked(hwnd, IDC_SAVEMRU);
Settings.SaveFindReplace = IsButtonChecked(hwnd, IDC_REMEMBERSEARCHPATTERN);
Settings.PreserveCaretPos = IsButtonChecked(hwnd, IDC_PRESERVECARET);
@ -1835,10 +1846,10 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
UINT const cnt = ListView_GetSelectedCount(GetDlgItem(hwnd, IDC_FILEMRU));
DialogEnableControl(hwnd, IDOK, (cnt > 0));
// can't discard current file (myself)
int iCur = 0;
if (!MRU_FindFile(Globals.pFileMRU, Globals.CurrentFile, &iCur)) { iCur = -1; }
int cur = 0;
if (!MRU_FindFile(Globals.pFileMRU, Globals.CurrentFile, &cur)) { cur = -1; }
int const item = ListView_GetNextItem(GetDlgItem(hwnd, IDC_FILEMRU), -1, LVNI_ALL | LVNI_SELECTED);
DialogEnableControl(hwnd, IDC_REMOVE, (cnt > 0) && (iCur != item));
DialogEnableControl(hwnd, IDC_REMOVE, (cnt > 0) && (cur != item));
}
break;
}
@ -1898,9 +1909,14 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
UINT cnt = ListView_GetItemCount(GetDlgItem(hwnd, IDC_FILEMRU));
if (cnt > 0) {
UINT idx = ListView_GetTopIndex(GetDlgItem(hwnd, IDC_FILEMRU));
ListView_SetItemState(GetDlgItem(hwnd, IDC_FILEMRU), idx, LVIS_FOCUSED, LVIS_FOCUSED);
ListView_SetColumnWidth(GetDlgItem(hwnd, IDC_FILEMRU), idx, LVSCW_AUTOSIZE_USEHEADER);
ListView_SetItemState(GetDlgItem(hwnd, IDC_FILEMRU), idx, LVIS_SELECTED, LVIS_SELECTED);
ListView_SetItemState(GetDlgItem(hwnd, IDC_FILEMRU), ((cnt > 1) ? idx + 1 : idx), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
//int cur = 0;
//if (!MRU_FindFile(Globals.pFileMRU, Globals.CurrentFile, &cur)) { cur = -1; }
//int const item = ListView_GetNextItem(GetDlgItem(hwnd, IDC_FILEMRU), -1, LVNI_ALL | LVNI_SELECTED);
//if ((cur == item) && (cnt > 1)) {
// ListView_SetItemState(GetDlgItem(hwnd, IDC_FILEMRU), idx + 1, LVIS_SELECTED, LVIS_SELECTED);
//}
}
lpit->hThread = CreateThread(NULL,0,FileMRUIconThread,(LPVOID)lpit,0,&dwtid);
@ -1921,8 +1937,8 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
case IDC_REMOVE:
{
WCHAR tchFileName[MAX_PATH] = { L'\0' };
//int iItem;
//if ((iItem = SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_GETCURSEL,0,0)) != LB_ERR)
UINT cnt = ListView_GetSelectedCount(GetDlgItem(hwnd, IDC_FILEMRU));

View File

@ -649,7 +649,6 @@ typedef struct _themeFiles
//=============================================================================
// --------- common defines --------
#define NOTEPAD3_MODULE_DIR_ENV_VAR L"NOTEPAD3MODULEDIR"

View File

@ -8,12 +8,12 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 20
#define VERSION_REV 311
#define VERSION_BUILD 4
#define VERSION_REV 312
#define VERSION_BUILD 1
#define SCINTILLA_VER 432
#define ONIGURUMA_REGEX_VER 6.9.4
#define UCHARDET_VER 2018.09.27
#define TINYEXPR_VER 2018.05.11
#define UTHASH_VER 2.1.0
#define VERSION_PATCH RC3
#define VERSION_COMMIT_ID dkt1-amr
#define VERSION_COMMIT_ID nebukadn