From 58aa145cc53bbe0fe080225cf46c19ae9ca179f5 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 16 Apr 2019 17:21:30 -0500 Subject: [PATCH] Cleanup ms office (#964) --- DiabloUI/diabloui_gcc.def | 3 ++ Source/init.cpp | 99 +++++++++++++++++++-------------------- Source/init.h | 2 +- 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/DiabloUI/diabloui_gcc.def b/DiabloUI/diabloui_gcc.def index 513b55800..6bd8befd1 100644 --- a/DiabloUI/diabloui_gcc.def +++ b/DiabloUI/diabloui_gcc.def @@ -22,12 +22,14 @@ EXPORTS UiCreditsDialog @11 UiCreditsDialog@4 @11 NONAME UiDestroy @12 + UiDestroy@0 @12 NONAME UiDrawDescCallback @13 UiDrawDescCallback@32 @13 NONAME UiGetDataCallback @14 UiGetDataCallback@20 @14 NONAME UiGetDefaultStats @15 UiInitialize @16 + UiInitialize@0 @16 NONAME UiMainMenuDialog @17 UiMainMenuDialog@16 @17 NONAME UiMessageBoxCallback @18 @@ -36,6 +38,7 @@ EXPORTS UiProfileCallback @20 UiProfileDraw @21 UiProfileGetString @22 + UiProfileGetString@0 @22 NONAME UiProgressDialog @23 UiProgressDialog@20 @23 NONAME UiSelHeroMultDialog @24 diff --git a/Source/init.cpp b/Source/init.cpp index b14d013c9..0ab42f056 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -11,7 +11,7 @@ WNDPROC CurrentProc; HANDLE diabdat_mpq; char diabdat_mpq_path[MAX_PATH]; HANDLE patch_rt_mpq; -int killed_mom_parent; // weak +BOOL killed_mom_parent; // weak BOOLEAN screensaver_enabled_prev; /* data */ @@ -52,65 +52,60 @@ void init_cleanup(BOOL show_cursor) void init_run_office_from_start_menu() { - HWND v0; // eax - char pszPath[256]; // [esp+0h] [ebp-104h] - LPITEMIDLIST ppidl; // [esp+100h] [ebp-4h] - - if (killed_mom_parent) { - //*pszPath = empty_string; - killed_mom_parent = 0; - memset(pszPath, 0, sizeof(pszPath)); - // *(_WORD *)&pszPath[253] = 0; - //pszPath[255] = 0; - ppidl = 0; - v0 = GetDesktopWindow(); - if (!SHGetSpecialFolderLocation(v0, CSIDL_STARTMENU, &ppidl)) { - SHGetPathFromIDList(ppidl, pszPath); - init_run_office(pszPath); - } + LPITEMIDLIST idl; + + if(!killed_mom_parent) { + return; + } + + killed_mom_parent = FALSE; + char szPath[256] = ""; /// BUGFIX: size should be at least 'MAX_PATH' + idl = NULL; + + if(SHGetSpecialFolderLocation(GetDesktopWindow(), CSIDL_STARTMENU, &idl) == NOERROR) { + SHGetPathFromIDList(idl, szPath); + init_run_office(szPath); } } // 634CA0: using guessed type int killed_mom_parent; void init_run_office(char *dir) { - char *v1; // esi - HANDLE v2; // ebx - BOOLEAN v3; // zf - HWND v4; // eax - char Directory[MAX_PATH]; // [esp+8h] [ebp-348h] - char FileName[MAX_PATH]; // [esp+10Ch] [ebp-244h] - struct _WIN32_FIND_DATAA FindFileData; // [esp+210h] [ebp-140h] - - v1 = dir; - strcpy(FileName, dir); - if (FileName[0] && Directory[strlen(FileName) + 259] == '\\') - strcat(FileName, "*"); - else - strcat(FileName, "\\*"); - v2 = FindFirstFile(FileName, &FindFileData); - if (v2 != (HANDLE)-1) { - do { - if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (strcmp(FindFileData.cFileName, ".") && strcmp(FindFileData.cFileName, "..")) { - //*Directory = empty_string; - memset(Directory, 0, sizeof(Directory)); - v3 = *v1 == 0; - // *(_WORD *)&Directory[257] = 0; - //Directory[259] = 0; - if (v3 || v1[strlen(v1) - 1] != '\\') - sprintf(Directory, "%s\\%s\\", v1, FindFileData.cFileName); - else - sprintf(Directory, "%s%s\\", v1, FindFileData.cFileName); - init_run_office(Directory); + HANDLE hSearch; + WIN32_FIND_DATA find; + char szFirst[MAX_PATH]; + + strcpy(szFirst, dir); + if(szFirst[0] != '\0' && szFirst[strlen(szFirst) - 1] == '\\') { + strcat(szFirst, "*"); + } else { + strcat(szFirst, "\\*"); + } + hSearch = FindFirstFile(szFirst, &find); + if(hSearch == INVALID_HANDLE_VALUE) { + return; + } + + while(1) { + if(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + if(strcmp(find.cFileName, ".") != 0 && strcmp(find.cFileName, "..") != 0) { + char szNext[MAX_PATH] = ""; + if(dir[0] != '\0' && dir[strlen(dir) - 1] == '\\') { + sprintf(szNext, "%s%s\\", dir, find.cFileName); + } else { + sprintf(szNext, "%s\\%s\\", dir, find.cFileName); } - } else if (!_strcmpi(FindFileData.cFileName, "Microsoft Office Shortcut Bar.lnk")) { - v4 = GetDesktopWindow(); - ShellExecute(v4, "open", FindFileData.cFileName, "", v1, SW_SHOWNORMAL); + init_run_office(szNext); } - } while (FindNextFile(v2, &FindFileData)); - FindClose(v2); + } else if(_strcmpi(find.cFileName, "Microsoft Office Shortcut Bar.lnk") == 0) { + ShellExecute(GetDesktopWindow(), "open", find.cFileName, "", dir, SW_SHOWNORMAL); + } + if(!FindNextFile(hSearch, &find)) { + break; + } } + + FindClose(hSearch); } void init_disable_screensaver(BOOLEAN disable) @@ -191,7 +186,7 @@ void init_kill_mom_parent() v0 = init_find_mom_parent(); if (v0) { PostMessage(v0, WM_CLOSE, 0, 0); - killed_mom_parent = 1; + killed_mom_parent = TRUE; } } // 634CA0: using guessed type int killed_mom_parent; diff --git a/Source/init.h b/Source/init.h index 7529d2940..cca31acf8 100644 --- a/Source/init.h +++ b/Source/init.h @@ -11,7 +11,7 @@ extern WNDPROC CurrentProc; extern HANDLE diabdat_mpq; extern char diabdat_mpq_path[MAX_PATH]; extern HANDLE patch_rt_mpq; -extern int killed_mom_parent; // weak +extern BOOL killed_mom_parent; // weak extern BOOLEAN screensaver_enabled_prev; void init_cleanup(BOOL show_cursor);