Skip to content

Commit 6c343d9

Browse files
committed
Replace GetVersionEx direct call
1 parent 77c8847 commit 6c343d9

7 files changed

Lines changed: 50 additions & 28 deletions

File tree

Common/Common.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<ClCompile Include="MyFunc.cpp" />
152152
<ClCompile Include="MyProp.cpp" />
153153
<ClCompile Include="MyWindow.cpp" />
154+
<ClCompile Include="OS.cpp" />
154155
<ClCompile Include="ShlItem.cpp" />
155156
<ClCompile Include="Splitter.cpp" />
156157
<ClCompile Include="stdafx.cpp">
@@ -181,6 +182,7 @@
181182
<ClInclude Include="MyFunc.h" />
182183
<ClInclude Include="MyProp.h" />
183184
<ClInclude Include="MyWindow.h" />
185+
<ClInclude Include="OS.h" />
184186
<ClInclude Include="RefDelg.h" />
185187
<ClInclude Include="ShlItem.h" />
186188
<ClInclude Include="Splitter.h" />

Common/Common.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<ClCompile Include="SyncUtil.cpp">
6464
<Filter>ソース ファイル</Filter>
6565
</ClCompile>
66+
<ClCompile Include="OS.cpp">
67+
<Filter>ソース ファイル</Filter>
68+
</ClCompile>
6669
</ItemGroup>
6770
<ItemGroup>
6871
<ClInclude Include="AppClass.h">
@@ -146,6 +149,9 @@
146149
<ClInclude Include="BitFlags.h">
147150
<Filter>ヘッダー ファイル</Filter>
148151
</ClInclude>
152+
<ClInclude Include="OS.h">
153+
<Filter>ヘッダー ファイル</Filter>
154+
</ClInclude>
149155
</ItemGroup>
150156
<ItemGroup>
151157
<None Include="ReadMe.txt" />

Common/OS.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright (C) 2026 jet (ジェット)
3+
4+
OS.cpp - implementations for OS-related functions
5+
*/
6+
7+
#include "stdafx.h"
8+
#include "OS.h"
9+
10+
static DWORD s_dwPlatformId = 0;
11+
12+
EXTERN_C bool IsUnicodeAvailableOS()
13+
{
14+
if (s_dwPlatformId == 0)
15+
{
16+
OSVERSIONINFO vi{};
17+
vi.dwOSVersionInfoSize = sizeof(vi);
18+
#pragma warning(push)
19+
#pragma warning(disable:4996 28159)
20+
if (!::GetVersionExA(&vi))
21+
#pragma warning(pop)
22+
return false;
23+
s_dwPlatformId = vi.dwPlatformId;
24+
}
25+
return (s_dwPlatformId != VER_PLATFORM_WIN32_WINDOWS);
26+
}

Common/OS.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
Copyright (C) 2026 jet (ジェット)
3+
4+
OS.h - declarations for OS-related functions
5+
*/
6+
7+
#pragma once
8+
9+
EXTERN_C bool IsUnicodeAvailableOS();

EasySFTP/EasySFTP.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "IDList.h"
1616
#include "FileStrm.h"
17+
#include "OS.h"
1718
#include "Logger.h"
1819

1920
CMainApplication theApp;
@@ -514,22 +515,10 @@ HRESULT CMainApplication::InitSystemLibraries()
514515
m_nCFShellIDList = ::RegisterClipboardFormat(CFSTR_SHELLIDLIST);
515516

516517
{
517-
OSVERSIONINFO vi;
518-
vi.dwOSVersionInfoSize = sizeof(vi);
519-
if (!::GetVersionExA(&vi))
520-
{
521-
m_bUseOFNUnicode = false;
518+
m_bUseOFNUnicode = IsUnicodeAvailableOS();
522519
#ifndef _WIN64
523-
m_bIsWin9x = true;
520+
m_bIsWin9x = !m_bUseOFNUnicode;
524521
#endif
525-
}
526-
else
527-
{
528-
m_bUseOFNUnicode = (vi.dwPlatformId == VER_PLATFORM_WIN32_NT);
529-
#ifndef _WIN64
530-
m_bIsWin9x = !m_bUseOFNUnicode;
531-
#endif
532-
}
533522
}
534523

535524
return S_OK;

EasySFTP/RegHook.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../ShellDLL/EasySFTP_h.h"
1111
#include "Array.h"
1212
#include "UString.h"
13+
#include "OS.h"
1314

1415
#ifdef _DEBUG
1516
#define new DEBUG_NEW
@@ -482,12 +483,7 @@ static bool __stdcall InitOldRegFunctions()
482483
s_pfnRegSetKeyValueW = (T_RegSetKeyValueW) ::GetProcAddress(hInstAdvapi32, "RegSetKeyValueW");
483484
#undef GetProcAddress
484485

485-
{
486-
OSVERSIONINFO osvi;
487-
osvi.dwOSVersionInfoSize = sizeof(osvi);
488-
::GetVersionEx(&osvi);
489-
s_bUnicodeSupported = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
490-
}
486+
s_bUnicodeSupported = IsUnicodeAvailableOS();
491487

492488
return true;
493489
}

ShellDLL/ShellDLL.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "CFactory.h"
1313
#include "INIFile.h"
1414
#include "MErrDlg.h"
15+
#include "OS.h"
1516

1617
CMainDLL theApp;
1718

@@ -1243,14 +1244,7 @@ bool CMainDLL::InitInstance()
12431244
::srand((unsigned int) (time(NULL) * GetTickCount()));
12441245

12451246
// Check whether we can use Unicode version of GetOpenFileName/GetSaveFileName
1246-
{
1247-
OSVERSIONINFO vi;
1248-
vi.dwOSVersionInfoSize = sizeof(vi);
1249-
if (!::GetVersionExA(&vi))
1250-
m_bUseOFNUnicode = false;
1251-
else
1252-
m_bUseOFNUnicode = (vi.dwPlatformId == VER_PLATFORM_WIN32_NT);
1253-
}
1247+
m_bUseOFNUnicode = IsUnicodeAvailableOS();
12541248

12551249
// Initializing system image lists
12561250
{

0 commit comments

Comments
 (0)