-
Notifications
You must be signed in to change notification settings - Fork 3
/
Sazabi.h
1056 lines (965 loc) · 26.3 KB
/
Sazabi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "StdAfx.h"
#include "resource.h" // メイン シンボル
//////////////////////////////////////////////
#include "Psapi.h"
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "Version.lib")
#pragma comment(lib, "Dwmapi.lib")
//////////////////////////////////////////////
#include "fav.h"
#include "sbcommon.h"
#include "DlgSetting.h"
#include "DlgDebugWnd.h"
#include "include\cef_parser.h"
#include "MessageLoopWorker.h"
/////////////////////////////////////////////////////////////////////////////
// CSazabi:
//
//////////////////////////////////////////////////////////
#define CEF_PROC_BROWSER 0
#define CEF_PROC_RENDERER 1
#define CEF_PROC_GPU 2
#define CEF_PROC_OTHER 3
#if CHROME_VERSION_MAJOR < 119 || (CHROME_VERSION_MAJOR == 119 && CHROME_VERSION_PATCH < 124)
// Since CEF 119.4.2, cef_window_open_disposition_t was changed to
// add CEF_ prefix. (chromium-119.0.6045.124)
#define CEF_WOD_CURRENT_TAB WOD_CURRENT_TAB
#define CEF_WOD_SINGLETON_TAB WOD_SINGLETON_TAB
#define CEF_WOD_NEW_FOREGROUND_TAB WOD_NEW_FOREGROUND_TAB
#define CEF_WOD_NEW_BACKGROUND_TAB WOD_NEW_BACKGROUND_TAB
#define CEF_WOD_NEW_POPUP WOD_NEW_POPUP
#define CEF_WOD_NEW_WINDOW WOD_NEW_WINDOW
#define CEF_WOD_SAVE_TO_DISK WOD_SAVE_TO_DISK
#define CEF_WOD_OFF_THE_RECORD WOD_OFF_THE_RECORD
#define CEF_WOD_IGNORE_ACTION WOD_IGNORE_ACTION
#endif
enum class CHFILER_INIT_MODE
{
OPEN,
TRANSFER,
EXIT_CHECK
};
class CChildView;
class CScriptHost;
class CBrowserFrame;
class CCloseNilButton;
class CNewTabButton;
class CActiveTabLine;
class APIHookC;
class CLogDispatcher;
#include "client_app.h"
class CSazabi : public CWinApp
{
public:
//func
CSazabi();
virtual ~CSazabi();
CStringW m_strAppIDw;
//SZB
BOOL m_bCEFInitialized;
BOOL m_bToBeShutdown;
BOOL m_bMultiThreadedMessageLoop;
MessageLoopWorker* m_pMessageLoopWorker;
CefRefPtr<ClientApp> m_cefApp;
CImageList m_imgMenuIcons;
CImageList m_imgFavIcons;
void SetFavicon(CImage* img, CBrowserFrame* pwndFrame);
void SetDefaultFavicon(CBrowserFrame* pwndFrame);
void SetWarmFavicon(HWND hwndF);
CFavoriteItemManager m_FavMng;
APIHookC* m_pAPIHook;
HWND m_hwndTaskDlg;
CChildView* GetActiveViewPtr();
CBrowserFrame* GetActiveBFramePtr();
HWND GetActiveBFramePtrHWND();
BOOL m_bTabEnable_Init;
BOOL m_bShutdownFlg;
//setting//////////////////////////
AppSettings m_AppSettings;
CScriptSrcMgr m_cScriptSrc;
//Path///////////////////////////////
CString m_strExeFullPath;
CString m_strExeFileName;
CString m_strExeFolderPath;
CString m_strLogFileFullPath;
CString m_strRecoveryFileFullPath;
CString m_strRecoveryFileName;
CString m_strLogoFileFullPath;
CString m_strRestoreFileFullPath;
BOOL m_bAbortFlg;
CString m_strDBL_EXE_Default_FullPath;
CString m_strDBL_EXE_FullPath;
CString m_strDBL_EXE_FolderPath;
CString m_strSettingFileFullPath;
CString m_strCEFCachePathBase;
CString m_strCEFCachePath;
CString m_strFaviconCachePath;
//StringInfo/////////////////////////////////////
CString m_strThisAppName;
CString m_strThisAppVersionString;
CString m_strAtomParam;
CString m_strCommandParam;
CString m_strOptionParam;
BOOL m_bNewInstanceParam;
BOOL m_bTabWndChanging;
//ConstString
CString m_strZoneMessageDBL;
CString m_strZoneMessageNG;
CString m_strZoneMessageIE;
CString m_strZoneMessageFF;
CString m_strZoneMessageCHR;
CString m_strZoneMessageEDG;
CString m_strZoneMessageCustom;
CString m_strLastSelectFolderPath;
CString m_strLastSelectUploadFolderPath;
//funcutil
TCHAR m_FrmWndClassName[512];
/* CBrowserFrame::OnCloseDelay */
HANDLE m_hEventLog;
CString m_strEventLogName;
/* CSazabi::IsCacheRedirectFilterNone */
HANDLE m_hEventLogScript;
CString m_strEventLogScriptName;
/* CMainFrame::SaveWindowList */
HANDLE m_hEventRecovery;
CString m_strEventRecoveryName;
CStringList m_listCloseWindowURL;
CStringList m_listCloseWindowTitle;
CMapStringToPtr m_CacheRedirectFilter_None;
BOOL IsCacheRedirectFilterNone(LPCTSTR pURL);
void AddCacheRedirectFilterNone(LPCTSTR pURL);
/* CSazabi::IsCacheRedirectFilterAllow */
HANDLE m_hEventURLFilterAllow;
CString m_strEventURLFilterAllow;
CMapStringToPtr m_CacheURLFilter_Allow;
BOOL IsCacheURLFilterAllow(LPCTSTR pURL);
void AddCacheURLFilterAllow(LPCTSTR pURL);
/* CSazabi::IsCacheRedirectFilterDeny */
HANDLE m_hEventURLFilterDeny;
CString m_strEventURLFilterDeny;
CFilterURLList m_cDomainFilterList;
CString m_strDomainFilterFileFullPath;
CCustomScriptList m_cCustomScriptList;
CString m_strCustomScriptConfFullPath;
CMapStringToPtr m_CacheURLFilter_Deny;
BOOL IsCacheURLFilterDeny(LPCTSTR pURL);
void AddCacheURLFilterDeny(LPCTSTR pURL);
BOOL IsURLFilterAllow(LPCTSTR sURL,
LPCTSTR sSchme,
LPCTSTR sHost,
LPCTSTR sPath);
BOOL bCreateFavDone;
BOOL m_IsSGMode;
BOOL IsSGMode()
{
return m_IsSGMode;
}
///////////////////////////////////////
BOOL m_bFirstInstance;
BOOL IsFirstInstance()
{
return m_bFirstInstance;
}
BOOL IsExistsAnotherInstance()
{
BOOL bRet = FALSE;
//既に起動しているか?
HWND hWndCap = FindWindow(m_FrmWndClassName, NULL); //APのハンドル取得
//起動している。
if (hWndCap != NULL)
{
TCHAR szTitleMultipleInstance[260] = {0};
::GetWindowText(hWndCap, szTitleMultipleInstance, 259);
CString strTitleMultiple;
strTitleMultiple = szTitleMultipleInstance;
if (strTitleMultiple != m_FrmWndClassName)
{
bRet = FALSE;
}
else
bRet = TRUE;
}
else
{
bRet = FALSE;
}
return bRet;
}
//ChildViewのポインタをリストから返す。
CChildView* GetChildViewPtr(HWND hWnd);
DWORD m_dwProcessId;
CHandle m_hProcess;
int m_iWinOSVersion;
int m_iWinOSBuildVersion;
double m_ScaleDPI;
////////////////////////////////////////////////
virtual BOOL InitInstance();
BOOL InitFunc_Base();
BOOL InitFunc_Events();
BOOL InitFunc_Paths();
BOOL InitFunc_ExecOnVOS();
BOOL InitFunc_Settings();
BOOL InitFunc_SGMode();
void InitProcessSetting();
void InitLogWrite();
void InitParseCommandLine();
BOOL InitMultipleInstance();
void InitReadConfSetting();
void InitializeCef();
////////////////////////////////////////////////
virtual int ExitInstance();
void UnInitializeObjects();
void UnInitializeCef();
////////////////////////////////////////////////
void SetThisAppVersionString();
CString GetUserAgent();
CString GetOSInfo();
CString GetOSKernelVersion();
CString GetVOSInfo();
CString GetVOSVersionFromNT0_DLLStr();
CString GetVOSProcessString(BOOL bCurrent = TRUE, DWORD* pdwCnt = NULL, BOOL bNeedCmdLine = TRUE);
CString GetTurboVMInfo();
BOOL CloseVOSProc();
void CloseVOSProcessReadReg(BOOL bForce);
void CloseVOSProcessOther();
HWND GetTopWindowHandle(const DWORD TargetID);
BOOL IsProcessExists(DWORD dPID);
CString IsProcessExistsName(DWORD dPID);
CString GetCefVersionStr();
CString GetChromiumVersionStr();
//Setting Dlg///////////////////////////////////
void ShowSettingDlg(CWnd* pParentWnd);
CString m_strCurrentURL4DlgSetting;
CSettingsDialog* m_pSettingDlg;
AppSettings m_AppSettingsDlgCurrent;
////////////////////////////////////////////////
//DebugTrace Dlg///////////////////////////////
CDlgDebugWnd* m_pDebugDlg;
void ShowDebugTraceDlg();
void ShowDevTools();
BOOL IsShowDevTools();
void CreateNewWindow(LPCTSTR lpURL, BOOL bActive);
////////////////////////////////////////////////
BOOL m_bUseApp;
////////////////////////////////////////////////
////////////////////////////////////////////////
DWORD GetKeyCombi();
BOOL bValidKeyCombi();
////////////////////////////////////////////////
CString GetAllModules();
///////////////////////////////////////////////////////////
int GetGDIObjectCnt()
{
return ::GetGuiResources(m_hProcess, GR_GDIOBJECTS);
;
}
int GetUserObjectCnt()
{
return ::GetGuiResources(m_hProcess, GR_USEROBJECTS);
}
unsigned long long GetMemoryUsageSize();
unsigned long long GetMemoryUsageSizeFromPID(DWORD dwPID);
void EmptyWorkingSetAll();
void EmptyWorkingSetSingle(DWORD dwProcessId);
BOOL IsProcOwner(DWORD dwPID);
int GetProcessRunningTime();
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
CString GetThinAppEntryPointPath();
CString GetThinAppEntryPointFolderPath();
UINT GetWindowCount();
int GetOSVersion();
void HideRebar(CWnd* pFrame);
///////////////////////////////////////////////////////////
void CopyDBLEXEToTempInit();
void SetRecoveryFilePath();
void CopyDBLEXEToTempEx();
void OpenDefaultBrowser(const CString& strURL, DWORD iType, const CString strPath);
void OpenFileExplorer(const CString& strURL);
void ExecNewInstance(const CString strURL);
void TraceLogBackup();
void WriteDebugTraceDateTime(LPCTSTR msg, int iLogType);
void AppendDebugViewLog(const DebugWndLogData& Data);
BOOL SafeTerminateProcess(HANDLE hProcess, INT_PTR uExitCode);
CString GetActivePageURL();
BOOL DeleteDirectory(LPCTSTR lpPathName, LPCTSTR lpPat);
BOOL DeleteDirectoryTempFolder(LPCTSTR lpPathName);
void ExitKillZombieProcess();
void OpenChFiler(CHFILER_INIT_MODE initMode, LPCTSTR lpOpenPath = NULL);
void OpenChTaskMgr();
//{{AFX_VIRTUAL(CSazabi)
public:
//}}AFX_VIRTUAL
virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);
BOOL IsLimitChkEx();
///////////////////////////////////////////////////////////
inline HWND SafeWnd(HWND wnd)
{
HWND hRetNULL = {0};
if (wnd == NULL)
return hRetNULL;
TCHAR szLog[128] = {0};
__try
{
if (IsWindow(wnd))
return wnd;
else
{
return hRetNULL;
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return hRetNULL;
}
return hRetNULL;
}
inline HWND SafeWnd(CWnd* wnd)
{
HWND hRetNULL = {0};
if (wnd == NULL)
return hRetNULL;
return SafeWnd(wnd->m_hWnd);
}
inline static BOOL IsWnd(CWnd* wnd)
{
if (wnd == NULL)
return FALSE;
__try
{
if (!IsWindow(wnd->m_hWnd))
return FALSE;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
}
return TRUE;
}
inline static BOOL Safe_WM_GETTEXT(HWND hWnd, int iBuffLen, LPCTSTR ptrS)
{
BOOL bRet = TRUE;
if (ptrS == NULL) return bRet;
if (hWnd == NULL) return bRet;
__try
{
if (!IsWindow(hWnd))
return bRet;
::SendMessage(hWnd, WM_GETTEXT, iBuffLen, (LPARAM)ptrS);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
}
return bRet;
}
inline BOOL IsWndVisible(HWND hWnd)
{
BOOL bRet = FALSE;
__try
{
if (!IsWindow(hWnd))
return bRet;
bRet = ::IsWindowVisible(hWnd);
if (bRet)
{
LONG dwExStyle = 0;
dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
if ((dwExStyle & WS_EX_LAYERED) == WS_EX_LAYERED)
{
BYTE alpha = 0;
GetLayeredWindowAttributes(hWnd, NULL, &alpha, NULL);
if (alpha == 0)
bRet = FALSE;
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
}
return bRet;
}
inline void HideWnd(HWND hWnd)
{
__try
{
if (!IsWindow(hWnd))
return;
::ShowWindow(hWnd, SW_HIDE);
return;
LONG dwExStyle = 0;
dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
if ((dwExStyle & WS_EX_LAYERED) != WS_EX_LAYERED)
{
dwExStyle = dwExStyle | WS_EX_LAYERED;
SetWindowLong(hWnd, GWL_EXSTYLE, dwExStyle);
::SetLayeredWindowAttributes(hWnd, 0, 0, LWA_ALPHA);
}
else
{
BYTE alpha = 0;
GetLayeredWindowAttributes(hWnd, NULL, &alpha, NULL);
if (alpha != 0)
{
::SetLayeredWindowAttributes(hWnd, 0, 0, LWA_ALPHA);
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return;
}
return;
}
inline void ShowWnd(HWND hWnd)
{
__try
{
if (!IsWindow(hWnd))
return;
return;
LONG dwExStyle = 0;
dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
if ((dwExStyle & WS_EX_LAYERED) == WS_EX_LAYERED)
{
BYTE alpha = 0;
GetLayeredWindowAttributes(hWnd, NULL, &alpha, NULL);
if (alpha < 255)
{
::SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA);
}
return;
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return;
}
return;
}
CString ConvertStr2UTF8UrlEncode(LPCTSTR str)
{
CefString strIn(str);
CefString strOut;
strOut = CefURIEncode(strIn, false);
CString strRet = (LPCWSTR)strOut.c_str();
return strRet;
}
UINT m_VEcache;
UINT InVirtualEnvironment()
{
if (m_VEcache == 9999)
{
m_VEcache = VE_NA;
HMODULE hMods = NULL;
#ifndef _WIN64
hMods = ::GetModuleHandle(_T("NT0_DLL.DLL"));
#else //WIN64
hMods = ::GetModuleHandle(_T("NT0_DLL64.DLL"));
#endif //WIN64
if (hMods)
m_VEcache = VE_THINAPP;
else
{
hMods = ::GetModuleHandle(_T("vmx.dll"));
if (hMods)
m_VEcache = VE_TURBO;
}
}
return m_VEcache;
}
UINT m_tRDS;
UINT InRDSEnvironment()
{
if (m_tRDS == 9999)
{
m_tRDS = RDS_NA;
if (SBUtil::IsWindowsServerRDS())
{
m_tRDS = RDS_RDP;
HMODULE hMods = NULL;
#ifndef _WIN64
hMods = ::GetModuleHandle(_T("VMToolsHook.DLL"));
#else //WIN64
hMods = ::GetModuleHandle(_T("VMToolsHook64.DLL"));
#endif //WIN64
if (hMods)
m_tRDS = RDS_VMWARE;
}
}
return m_tRDS;
}
int SB_MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, BOOL bBlackOut = FALSE, int iTimeOut = -1);
CScriptHost* m_pScHost;
CDLManager m_DlMgr;
WINDOWPLACEMENT m_NormalWindow_FramePlacementCache;
protected:
WINDOWPLACEMENT m_ActiveFramePlacement;
public:
WINDOWPLACEMENT GetActiveFrameWindowPlacement();
CBrowserFrame* GetNextGenerationActiveWindow(CBrowserFrame* pTarget);
CCloseNilButton* m_wndpClose;
CNewTabButton* m_wndpNewTab;
CActiveTabLine* m_wndpActiveTabLine;
CLogDispatcher* m_pLogDisp;
void SendLoggingMsg(int LOG_TYPE, LPCTSTR lpFileName, HWND hWnd);
public:
BOOL IsFolderExists(LPCTSTR ptrPath)
{
if (!ptrPath) return FALSE;
BOOL bFolderExists = FALSE;
//フォルダーの存在チェック
if (::PathFileExists(ptrPath) && !::PathIsDirectory(ptrPath))
{
// 指定されたパスにファイルが存在、かつディレクトリでない
bFolderExists = FALSE;
}
else if (::PathFileExists(ptrPath))
{
bFolderExists = TRUE;
}
return bFolderExists;
}
BOOL MakeDirectoryPath(LPCTSTR lpPathName)
{
int nStart = 0;
BOOL res = FALSE;
CString strMakePath;
CString strPathName = lpPathName;
strPathName.TrimRight('\\');
strPathName += _T("\\");
// ディレクトリを1つずつ繰り返し作成
while (strMakePath + _T("\\") != strPathName)
{
// 作成するディレクトリ名を設定
nStart = strPathName.Find(_T("\\"), nStart + 1);
strMakePath = strPathName.Left(nStart);
// ディレクトリが存在するかチェックし無ければ作成
if (strMakePath.GetLength() > 2)
{
if (!IsFolderExists(strMakePath))
res = ::CreateDirectory(strMakePath, NULL);
}
}
return res;
}
BOOL SetPriority(DWORD PID, DWORD uiPR_Class)
{
BOOL bRet = FALSE;
if (PID == 0) return TRUE;
HANDLE hProcess = {0};
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, PID);
if (!hProcess)
return FALSE;
if (::SetPriorityClass(hProcess, uiPR_Class))
bRet = TRUE;
//::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL);
CloseHandle(hProcess);
return bRet;
}
/////////////////////////////////////////////////////////////////////////////////////
CString GetDriveName(LPCTSTR lpPath)
{
CString strRet;
if (!lpPath) return strRet;
CString strParam(lpPath);
TCHAR szPath[MAX_PATH] = {0};
StringCchCopy(szPath, MAX_PATH, strParam);
if (PathStripToRoot(szPath))
strRet = szPath;
return strRet;
}
CString GetSandboxFilePath(LPCTSTR lpFile)
{
CString strRet;
if (InVirtualEnvironment() != VE_THINAPP)
return strRet;
CString SBPath;
HKEY hKey = {0};
LONG lResult = 0L;
DWORD dwType = 0;
lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\ChronosSystemGuard"),
0, KEY_ALL_ACCESS, &hKey);
if (lResult == ERROR_SUCCESS)
{
DWORD iSize = 0;
TCHAR* pVal = NULL;
RegQueryValueEx(hKey, _T("SBPath"), NULL, &dwType, NULL, &iSize);
if (iSize > 0)
{
iSize += 1; //+1=null
pVal = new TCHAR[iSize];
memset(pVal, 0x00, sizeof(TCHAR) * iSize);
RegQueryValueEx(hKey, _T("SBPath"), NULL, &dwType, (LPBYTE)pVal, &iSize);
SBPath = pVal;
delete[] pVal;
}
RegCloseKey(hKey);
}
if (!SBPath.IsEmpty())
{
SBPath.TrimRight('\\');
SBPath += _T("\\");
CString strTemp;
strTemp = vFS_ReverseExpandPath(lpFile);
if (!strTemp.IsEmpty())
{
SBPath += strTemp;
strRet = SBPath;
}
}
return strRet;
}
CString vFS_ReverseExpandPath(LPCTSTR lpFile)
{
CString strFile(lpFile);
CString strRet;
if (InVirtualEnvironment() != VE_THINAPP)
return strRet;
//現実的にファイルを保存する先のみに絞る。
CString strDesktopPath;
CString strPersonalPath;
CString strProfilePath;
CString strDrive;
TCHAR szFolder[1024] = {0};
//Desktop
memset(szFolder, 0x00, sizeof(szFolder));
if (::SHGetSpecialFolderPath(NULL, szFolder, CSIDL_DESKTOP, FALSE))
{
strDesktopPath = szFolder;
if (!strDesktopPath.IsEmpty())
{
strDesktopPath.TrimRight('\\');
strDesktopPath += _T("\\");
}
}
//Personal
memset(szFolder, 0x00, sizeof(szFolder));
if (::SHGetSpecialFolderPath(NULL, szFolder, CSIDL_PERSONAL, FALSE))
{
strPersonalPath = szFolder;
if (!strPersonalPath.IsEmpty())
{
strPersonalPath.TrimRight('\\');
strPersonalPath += _T("\\");
}
}
//Profile
memset(szFolder, 0x00, sizeof(szFolder));
if (::SHGetSpecialFolderPath(NULL, szFolder, CSIDL_PROFILE, FALSE))
{
strProfilePath = szFolder;
if (!strProfilePath.IsEmpty())
{
strProfilePath.TrimRight('\\');
strProfilePath += _T("\\");
}
}
//Drive
strDrive = GetDriveName(strFile);
strDrive.MakeLower();
//Pathがどの項目に該当するかチェック
TCHAR szBuffer[MAX_PATH] = {0};
CString strBuffer;
CString strTemp;
BOOL bFindSB = FALSE;
for (;;)
{
//Desktop
if (PathCommonPrefix(strDesktopPath, strFile, szBuffer))
{
strBuffer = szBuffer;
strBuffer.MakeLower();
strTemp = strFile;
strTemp.MakeLower();
strTemp.Replace(strBuffer, _T("%Desktop%"));
if (FindSBFile(strTemp))
{
bFindSB = TRUE;
break;
}
}
//Personal
if (PathCommonPrefix(strPersonalPath, strFile, szBuffer))
{
strBuffer = szBuffer;
strBuffer.MakeLower();
strTemp = strFile;
strTemp.MakeLower();
strTemp.Replace(strBuffer, _T("%Personal%"));
if (FindSBFile(strTemp))
{
bFindSB = TRUE;
break;
}
}
//Profile
if (PathCommonPrefix(strProfilePath, strFile, szBuffer))
{
strBuffer = szBuffer;
strBuffer.MakeLower();
strTemp = strFile;
strTemp.MakeLower();
strTemp.Replace(strBuffer, _T("%Profile%"));
if (FindSBFile(strTemp))
{
bFindSB = TRUE;
break;
}
}
//Drive
strTemp = strFile;
strTemp.MakeLower();
CString strDriveMac;
strDriveMac = _T("%drive_");
strDriveMac += strDrive[0];
strDriveMac += _T("%\\");
strTemp.Replace(strDrive, strDriveMac);
if (FindSBFile(strTemp))
{
bFindSB = TRUE;
break;
}
else
{
//DosDeviceChk
CString strDiskPath;
CString strDosDrive;
strDosDrive = strDrive[0];
strDosDrive += _T(":");
TCHAR szTargetPath[4096] = {0};
if (0 != QueryDosDevice(strDosDrive, szTargetPath, 4096))
{
strDiskPath = szTargetPath;
if (strDiskPath.Find(_T("\\??\\")) == 0)
{
strDiskPath.Replace(_T("\\??\\"), _T(""));
strDiskPath.TrimRight('\\');
strDiskPath += _T("\\");
strDiskPath.MakeLower();
strTemp = strFile;
strTemp.MakeLower();
strTemp.Replace(strDrive, strDiskPath);
strDrive = GetDriveName(strTemp);
strDrive.MakeLower();
strDriveMac = _T("%drive_");
strDriveMac += strDrive[0];
strDriveMac += _T("%\\");
strTemp.Replace(strDrive, strDriveMac);
if (FindSBFile(strTemp))
{
bFindSB = TRUE;
break;
}
}
}
}
break;
}
if (bFindSB)
strRet = strTemp;
return strRet;
}
BOOL FindSBFile(LPCTSTR lpMacroRoot)
{
CString strSubKey;
strSubKey = _T("FS\\");
strSubKey += lpMacroRoot;
HKEY hKey = {0};
LONG lResult = 0L;
DWORD dwType = 0;
DWORD dwCount = 0;
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strSubKey,
0, KEY_READ, &hKey);
if (lResult == ERROR_SUCCESS)
{
RegCloseKey(hKey);
return TRUE;
}
return FALSE;
}
void Exec_SB2PYS_COPY(LPCTSTR lpSBFilePath, LPCTSTR lpPYSFilePath)
{
try
{
if (InVirtualEnvironment() != VE_THINAPP)
return;
CString strSBFilePath(lpSBFilePath);
CString strPYSFilePath(lpPYSFilePath);
if (!strSBFilePath.IsEmpty() && !strPYSFilePath.IsEmpty())
{
if (PathIsRelative(strPYSFilePath))
return;
if (PathIsFileSpec(strPYSFilePath))
return;
TCHAR szTemp[MAX_PATH + 1] = {0};
::GetTempPath(MAX_PATH, szTemp);
CString strTempPath;
CString strTempPathDir;
strTempPath = szTemp;
CString strTempUpper;
strTempUpper = strTempPath;
strTempUpper.MakeUpper();
if (strTempUpper.Find(_T("\\CHRONOSSG\\")) >= 0)
{
strTempPath.TrimRight('\\');
}
else
strTempPath += _T("ChronosSG");
strTempPath += _T("\\DBLC.exe");
if (::PathFileExists(strTempPath))
{
CString strCommand;
CString strParam;
strCommand.Format(_T("\"%s\" -SB2PYS \"%s|@@|%s\""), (LPCTSTR)strTempPath, (LPCTSTR)strSBFilePath, (LPCTSTR)strPYSFilePath);
strParam.Format(_T("-SB2PYS \"%s|@@|%s\""), (LPCTSTR)strSBFilePath, (LPCTSTR)strPYSFilePath);
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
unsigned long ecode = 0;
if (!CreateProcess(NULL, (LPTSTR)(LPCTSTR)strCommand, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
SetLastError(NO_ERROR);
//Retry
if (!CreateProcess(strTempPath, (LPTSTR)(LPCTSTR)strParam, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
SetLastError(NO_ERROR);
if (::ShellExecute(NULL, _T("open"), strTempPath, strParam, NULL, SW_SHOW) <= HINSTANCE(32))
{
::ShellExecute(NULL, NULL, strCommand, NULL, NULL, SW_SHOW);
}
}
}
if (pi.hThread)
{
CloseHandle(pi.hThread);
pi.hThread = 0;
}
if (pi.hProcess)
{
CloseHandle(pi.hProcess);
pi.hProcess = 0;
}
}
}
}
catch (...)
{
ATLASSERT(0);
}
return;
}
BOOL m_bEnforceDeleteCache;
void DeleteCEFCache()
{
//CEFCacheを削除する。
if (!m_strCEFCachePath.IsEmpty())
{
DeleteDirectory(m_strCEFCachePath, _T("*.*"));
::RemoveDirectory(m_strCEFCachePath);
}
}
void DeleteCEFCacheAll()
{
// CEFCacheを削除する。
if (!m_strCEFCachePathBase.IsEmpty())
{
DeleteDirectory(m_strCEFCachePathBase, _T("*.*"));
}
}
//Windows10 1903環境で問題発生。対策コード2019-10-15
BOOL DeleteFileFix(LPCTSTR ptrPath)
{
if (!ptrPath)
return FALSE;
//ファイルが存在しない。
if (!::PathFileExists(ptrPath))
return FALSE;
//Win32APIのDeleteFileをCall
//Windows 10 1903 VOSでは、削除されない場合がある。2019-10-18
::DeleteFile(ptrPath);
//ファイルが存在しない=削除された。
if (!::PathFileExists(ptrPath))
return TRUE;
CString strLog;
strLog.Format(_T("##ChWin32API_DeleteFile FailBack: %s\n"), ptrPath);
::OutputDebugString(strLog);
//Windows 10 1903 VOSでは、削除されない場合がある。2019-10-18
//IFileOperationで消す。
BOOL bRet = FALSE;
CStringW strDeleteFilePath(ptrPath);
HRESULT hr = {0};
CComPtr<IFileOperation> pfo;
hr = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL, IID_PPV_ARGS(&pfo));
if (SUCCEEDED(hr))
{
hr = pfo->SetOperationFlags(FOF_FILESONLY | FOF_NO_CONNECTED_ELEMENTS | FOF_NORECURSEREPARSE | FOF_NOCONFIRMMKDIR | FOF_NO_UI);
if (SUCCEEDED(hr))
{
CComPtr<IShellItem> psiDelete;
hr = SHCreateItemFromParsingName(strDeleteFilePath, NULL, IID_PPV_ARGS(&psiDelete));
if (SUCCEEDED(hr))
{
hr = pfo->DeleteItems(psiDelete);
}
if (SUCCEEDED(hr))
{