mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ chg: "commit" on fflush() for _wfopen_s() in SimpleIni settings file writer
+ fix: some issues on tmpfile handling
This commit is contained in:
parent
d7a74e017a
commit
d3ea1a7281
@ -1 +1 @@
|
||||
2627
|
||||
2629
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<assemblyIdentity
|
||||
name="Notepad3"
|
||||
processorArchitecture="*"
|
||||
version="5.19.912.2627"
|
||||
version="5.19.912.2629"
|
||||
type="win32"
|
||||
/>
|
||||
<description>Notepad3 BETA</description>
|
||||
|
||||
@ -54,7 +54,7 @@ extern "C" int s_flagSingleFileInstance;
|
||||
extern "C" int s_flagMultiFileArg;
|
||||
extern "C" int s_flagShellUseSystemMRU;
|
||||
extern "C" int s_flagPrintFileAndLeave;
|
||||
extern "C" int s_flagDoRelaunchElevated;
|
||||
extern "C" bool s_flagDoRelaunchElevated;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -250,6 +250,8 @@ extern "C" size_t IniFileGetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LP
|
||||
|
||||
extern "C" bool IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR lpString)
|
||||
{
|
||||
if (s_flagDoRelaunchElevated) { return false; }
|
||||
|
||||
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
|
||||
SI_Error rc = Ini.LoadFile(lpFilePath);
|
||||
if (SI_SUCCESS(rc))
|
||||
@ -261,6 +263,7 @@ extern "C" bool IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCW
|
||||
Ini.SetSpaces(s_bSetSpaces);
|
||||
rc = Ini.SaveFile(lpFilePath, true);
|
||||
}
|
||||
Ini.Reset();
|
||||
}
|
||||
return SI_SUCCESS(rc);
|
||||
}
|
||||
@ -284,6 +287,8 @@ extern "C" int IniFileGetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR
|
||||
|
||||
extern "C" bool IniFileSetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, int iValue)
|
||||
{
|
||||
if (s_flagDoRelaunchElevated) { return false; }
|
||||
|
||||
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
|
||||
SI_Error rc = Ini.LoadFile(lpFilePath);
|
||||
if (SI_SUCCESS(rc)) {
|
||||
@ -291,6 +296,7 @@ extern "C" bool IniFileSetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR
|
||||
Ini.SetSpaces(s_bSetSpaces);
|
||||
rc = Ini.SaveFile(lpFilePath, true);
|
||||
}
|
||||
Ini.Reset();
|
||||
return SI_SUCCESS(rc);
|
||||
}
|
||||
// ============================================================================
|
||||
@ -313,6 +319,8 @@ extern "C" bool IniFileGetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST
|
||||
|
||||
extern "C" bool IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool bValue)
|
||||
{
|
||||
if (s_flagDoRelaunchElevated) { return false; }
|
||||
|
||||
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
|
||||
SI_Error rc = Ini.LoadFile(lpFilePath);
|
||||
if (SI_SUCCESS(rc)) {
|
||||
@ -320,6 +328,7 @@ extern "C" bool IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST
|
||||
Ini.SetSpaces(s_bSetSpaces);
|
||||
rc = Ini.SaveFile(lpFilePath, true);
|
||||
}
|
||||
Ini.Reset();
|
||||
return SI_SUCCESS(rc);
|
||||
}
|
||||
// ============================================================================
|
||||
@ -327,6 +336,8 @@ extern "C" bool IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST
|
||||
|
||||
extern "C" bool IniFileDelete(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool bRemoveEmpty)
|
||||
{
|
||||
if (s_flagDoRelaunchElevated) { return false; }
|
||||
|
||||
CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine);
|
||||
SI_Error rc = Ini.LoadFile(lpFilePath);
|
||||
if (SI_SUCCESS(rc))
|
||||
@ -335,6 +346,7 @@ extern "C" bool IniFileDelete(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR
|
||||
Ini.SetSpaces(s_bSetSpaces);
|
||||
rc = Ini.SaveFile(lpFilePath, true);
|
||||
}
|
||||
Ini.Reset();
|
||||
return SI_SUCCESS(rc);
|
||||
}
|
||||
// ============================================================================
|
||||
@ -1188,14 +1200,14 @@ void LoadFlags()
|
||||
|
||||
bool SaveSettings(bool bSaveSettingsNow)
|
||||
{
|
||||
if (StrIsEmpty(Globals.IniFile) || !s_bEnableSaveSettings || s_flagDoRelaunchElevated) { return false; }
|
||||
if (StrIsEmpty(Globals.IniFile) || s_flagDoRelaunchElevated) { return false; }
|
||||
|
||||
CreateIniFile();
|
||||
LoadIniFile(Globals.IniFile);
|
||||
|
||||
const WCHAR* const Settings_Section = L"Settings";
|
||||
|
||||
if (!(Settings.SaveSettings || bSaveSettingsNow))
|
||||
if (!Settings.SaveSettings && !bSaveSettingsNow)
|
||||
{
|
||||
if (Settings.SaveSettings != Defaults.SaveSettings) {
|
||||
IniSectionSetBool(Settings_Section, L"SaveSettings", Settings.SaveSettings);
|
||||
@ -1450,12 +1462,17 @@ bool SaveSettings(bool bSaveSettingsNow)
|
||||
IniSectionDelete(Window_Section, tchZoom, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool const ok = SaveIniFile(Globals.IniFile);
|
||||
|
||||
if (ok) {
|
||||
Style_Save(); // Scintilla Styles
|
||||
Globals.bIniFileFromScratch = false;
|
||||
}
|
||||
|
||||
ReleaseIniFile();
|
||||
|
||||
return ok;
|
||||
}
|
||||
//=============================================================================
|
||||
|
||||
@ -405,6 +405,7 @@ public:
|
||||
FILE * m_file;
|
||||
public:
|
||||
explicit FileWriter(FILE * a_file) : m_file(a_file) { }
|
||||
~FileWriter() { fflush(m_file); }
|
||||
void Write(const char * a_pBuf) override {
|
||||
fputs(a_pBuf, m_file);
|
||||
}
|
||||
@ -2440,9 +2441,9 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SaveFile(
|
||||
#ifdef _WIN32
|
||||
FILE * fp = nullptr;
|
||||
#if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
|
||||
_wfopen_s(&fp, a_pwszFile, L"wb");
|
||||
_wfopen_s(&fp, a_pwszFile, L"wbc");
|
||||
#else // !__STDC_WANT_SECURE_LIB__
|
||||
fp = _wfopen(a_pwszFile, L"wb");
|
||||
fp = _wfopen(a_pwszFile, L"wbc");
|
||||
#endif // __STDC_WANT_SECURE_LIB__
|
||||
if (!fp) return SI_FILE;
|
||||
SI_Error rc = SaveFile(fp, a_bAddSignature);
|
||||
|
||||
@ -827,7 +827,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
|
||||
StringCchCat(s_wchWndClass, COUNTOF(s_wchWndClass), L"B");
|
||||
}
|
||||
// Try to Relaunch with elevated privileges
|
||||
if (RelaunchElevated(NULL)) {
|
||||
s_flagDoRelaunchElevated = RelaunchElevated(NULL);
|
||||
if (s_flagDoRelaunchElevated) {
|
||||
return 0;
|
||||
}
|
||||
// Try to run multiple instances
|
||||
@ -1232,8 +1233,18 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow)
|
||||
Style_SetLexerFromFile(Globals.hwndEdit, Globals.CurrentFile);
|
||||
}
|
||||
// check for temp file and delete
|
||||
if (s_bIsElevated && PathFileExists(s_wchTmpFilePath)) {
|
||||
if (s_IsThisAnElevatedRelaunch && PathFileExists(s_wchTmpFilePath))
|
||||
{
|
||||
DeleteFile(s_wchTmpFilePath);
|
||||
// delete possible .tmp guard
|
||||
size_t const len = StringCchLen(s_wchTmpFilePath, MAX_PATH);
|
||||
LPWSTR p = PathFindExtension(s_wchTmpFilePath);
|
||||
if (p && *p) {
|
||||
StringCchCopy(p, (MAX_PATH - len), L".tmp");
|
||||
}
|
||||
if (PathFileExists(s_wchTmpFilePath)) {
|
||||
DeleteFile(s_wchTmpFilePath);
|
||||
}
|
||||
}
|
||||
SciCall_SetSavePoint();
|
||||
_SetSaveNeededFlag(true);
|
||||
@ -7575,7 +7586,7 @@ void ParseCommandLine()
|
||||
lp1 + CSTRLEN(L"tmpfbuf="), len - CSTRLEN(L"tmpfbuf="));
|
||||
TrimSpcW(s_wchTmpFilePath);
|
||||
NormalizePathEx(s_wchTmpFilePath, COUNTOF(s_wchTmpFilePath), true, s_flagSearchPathIfRelative);
|
||||
s_IsThisAnElevatedRelaunch = true;
|
||||
s_bIsElevated = s_IsThisAnElevatedRelaunch = true;
|
||||
}
|
||||
|
||||
else switch (*CharUpper(lp1)) {
|
||||
@ -9646,11 +9657,13 @@ bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus)
|
||||
s_flagDoRelaunchElevated = true;
|
||||
|
||||
LPWSTR lpCmdLine = GetCommandLine();
|
||||
size_t const wlen = StringCchLenW(lpCmdLine, 0) + 2;
|
||||
size_t const wlen = StringCchLen(lpCmdLine, 0) + 2;
|
||||
LPWSTR lpExe = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
|
||||
LPWSTR lpArgs = AllocMem(sizeof(WCHAR) * wlen, HEAP_ZERO_MEMORY);
|
||||
ExtractFirstArgument(lpCmdLine, lpExe, lpArgs, (int)wlen);
|
||||
|
||||
// remove relaunch elevated, we are doing this here already
|
||||
lpArgs[StringCchLen(lpArgs, 0)] = L' '; // add a space
|
||||
lpArgs = StrCutI(lpArgs, L"/u ");
|
||||
lpArgs = StrCutI(lpArgs, L"-u ");
|
||||
WCHAR wchFlags[32] = { L'\0' };
|
||||
@ -10285,7 +10298,13 @@ bool RelaunchMultiInst() {
|
||||
//
|
||||
bool RelaunchElevated(LPWSTR lpNewCmdLnArgs)
|
||||
{
|
||||
if (!IsVista() || s_bIsElevated || !s_flagDoRelaunchElevated || s_flagDisplayHelp) { return false; }
|
||||
if (!IsVista() ||
|
||||
!s_flagDoRelaunchElevated ||
|
||||
s_bIsElevated || s_IsThisAnElevatedRelaunch ||
|
||||
s_flagDisplayHelp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
STARTUPINFO si;
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
@ -10302,9 +10321,14 @@ bool RelaunchElevated(LPWSTR lpNewCmdLnArgs)
|
||||
if (lpNewCmdLnArgs) {
|
||||
StringCchCopy(szOrigArgs, COUNTOF(szOrigArgs), lpNewCmdLnArgs);
|
||||
}
|
||||
size_t const len = StringCchLen(szOrigArgs, 0);
|
||||
szOrigArgs[len] = L' '; // add a space
|
||||
szOrigArgs[len+1] = L'\0'; // ensure termination
|
||||
// remove relaunch elevated, we are doing this here already
|
||||
StrCutI(szOrigArgs, L"/u ");
|
||||
StrCutI(szOrigArgs, L"-u ");
|
||||
|
||||
WCHAR szArguments[2032] = { L'\0' };
|
||||
|
||||
if (StrStrI(szOrigArgs, L"/f ") || StrStrI(szOrigArgs, L"-f ") || StrIsEmpty(Globals.IniFile))
|
||||
{
|
||||
StringCchCopy(szArguments, COUNTOF(szArguments), szOrigArgs);
|
||||
@ -10317,7 +10341,7 @@ bool RelaunchElevated(LPWSTR lpNewCmdLnArgs)
|
||||
SHELLEXECUTEINFO sei;
|
||||
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
|
||||
sei.cbSize = sizeof(SHELLEXECUTEINFO);
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_UNICODE | SEE_MASK_HMONITOR | SEE_MASK_NOZONECHECKS;
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_UNICODE | SEE_MASK_HMONITOR | SEE_MASK_NOZONECHECKS | SEE_MASK_WAITFORINPUTIDLE;
|
||||
sei.hwnd = GetForegroundWindow();
|
||||
sei.hMonitor = MonitorFromWindow(sei.hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
sei.lpVerb = L"runas";
|
||||
|
||||
36
src/Styles.c
36
src/Styles.c
@ -704,7 +704,7 @@ bool Style_Export(HWND hwnd)
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_ExportToFile()
|
||||
// Style_Export()
|
||||
//
|
||||
|
||||
#define SAVE_STYLE_IF_NOT_EQ_DEFAULT(TYPE, VARNAME, VALUE, DEFAULT) \
|
||||
@ -716,18 +716,9 @@ bool Style_Export(HWND hwnd)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
|
||||
void Style_ToIniSection(bool bForceAll)
|
||||
{
|
||||
if (StrIsEmpty(szFile)) {
|
||||
if (s_idxSelectedTheme != 0) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SETTINGSNOTSAVED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
LoadIniFile(szFile); // reset
|
||||
|
||||
// Custom colors
|
||||
// Custom colors
|
||||
const WCHAR* const CustomColors_Section = L"Custom Colors";
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
@ -815,6 +806,27 @@ bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
|
||||
IniSectionDelete(L"Default Text", NULL, true);
|
||||
IniSectionDelete(L"2nd Default Text", NULL, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_ExportToFile()
|
||||
//
|
||||
|
||||
bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll)
|
||||
{
|
||||
if (StrIsEmpty(szFile)) {
|
||||
if (s_idxSelectedTheme != 0) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SETTINGSNOTSAVED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
LoadIniFile(szFile); // reset
|
||||
|
||||
Style_ToIniSection(bForceAll);
|
||||
|
||||
return SaveIniFile(szFile);
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ bool Style_Import(HWND hwnd);
|
||||
bool Style_ImportFromFile(const WCHAR* szFile);
|
||||
void Style_Save();
|
||||
bool Style_Export(HWND hwnd);
|
||||
void Style_ToIniSection(bool bForceAll);
|
||||
bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll);
|
||||
|
||||
unsigned ThemeItems_CountOf();
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#define VERSION_MAJOR 5
|
||||
#define VERSION_MINOR 19
|
||||
#define VERSION_REV 912
|
||||
#define VERSION_BUILD 2627
|
||||
#define VERSION_BUILD 2629
|
||||
#define SCINTILLA_VER 420
|
||||
#define ONIGURUMA_REGEX_VER 6.9.3
|
||||
#define UCHARDET_VER 2018.09.27
|
||||
|
||||
Loading…
Reference in New Issue
Block a user