ReactOS 0.4.17-dev-966-gf06eace
geninst.cpp File Reference
#include "defines.h"
#include <shlobj.h>
#include <shlwapi.h>
#include <setupapi.h>
#include <commctrl.h>
#include "resource.h"
#include "appdb.h"
#include "appinfo.h"
#include "misc.h"
#include "configparser.h"
#include "unattended.h"
#include "minizip/ioapi.h"
#include "minizip/iowin32.h"
#include "minizip/unzip.h"
Include dependency graph for geninst.cpp:

Go to the source code of this file.

Classes

struct  CommonInfo
 
struct  InstallInfo
 
struct  UninstallInfo
 

Macros

#define REGPATH_UNINSTALL   L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
 
#define DB_NONE   L"!"
 
#define DB_GENINST_FILES   L"Files"
 
#define DB_GENINST_DIR   L"Dir"
 
#define DB_GENINST_ICON   L"Icon"
 
#define DB_GENINST_LNK   L"Lnk"
 
#define DB_GENINST_LNKARGS   L"LnkParameters"
 
#define DB_GENINST_DELFILE   L"DelFile"
 
#define DB_GENINST_DELDIR   L"DelDir"
 
#define DB_GENINST_DELDIREMPTY   L"DelDirEmpty"
 
#define DB_GENINST_DELREG   L"DelReg"
 
#define DB_GENINST_DELREGEMPTY   L"DelRegEmpty"
 

Enumerations

enum  {
  UNOP_FILE = 'F' , UNOP_DIR = 'D' , UNOP_EMPTYDIR = 'd' , UNOP_REGKEY = 'K' ,
  UNOP_EMPTYREGKEY = 'k'
}
 
enum  { IM_STARTPROGRESS = WM_APP , IM_PROGRESS , IM_END }
 
enum  UninstallStage { US_ITEMS , US_CONTAINERS , UINSTALLSTAGECOUNT }
 

Functions

BOOL IsZipFile (PCWSTR Path)
 
static int ExtractFilesFromZip (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
 
static UINT ExtractZip (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
 
static UINT ExtractCab (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
 
static UINT ExtractArchive (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
 
static UINT ErrorBox (UINT Error=GetLastError())
 
static LPCWSTR GetCommonString (LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
 
static LPCWSTR GetGenerateString (LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
 
static void WriteArpEntry (LPCWSTR Name, LPCWSTR Value, UINT Type=REG_SZ)
 
static BOOL AddEntry (WCHAR Type, LPCWSTR Value)
 
static HRESULT GetCustomIconPath (InstallInfo &Info, CStringW &Path)
 
static BOOL GetLocalizedSMFolderName (LPCWSTR WinVal, LPCWSTR RosInf, LPCWSTR RosVal, CStringW &Output)
 
static CStringW CreateMainShortcut (const CStringW &Target)
 
static BOOL InstallFiles (const CStringW &SourceDirBase, const CStringW &Spec, const CStringW &DestinationDir)
 
static void AddUninstallOperationsFromDB (LPCWSTR Name, WCHAR UnOp, CStringW PathPrefix=CStringW(L""))
 
static BOOL CALLBACK ExtractCallback (const EXTRACTCALLBACKINFO &, void *Context)
 
static DWORD CALLBACK ExtractAndInstallThread (LPVOID Parameter)
 
static DWORD CALLBACK WorkerThread (LPVOID Parameter)
 
static INT_PTR CALLBACK UIDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static BOOL CreateUI (BOOL Silent, LPTHREAD_START_ROUTINE ThreadProc)
 
BOOL ExtractAndRunGeneratedInstaller (const CAvailableApplicationInfo &AppInfo, LPCWSTR Archive, bool Silent)
 
static DWORD CALLBACK UninstallThread (LPVOID Parameter)
 
BOOL UninstallGenerated (CInstalledApplicationInfo &AppInfo, UninstallCommandFlags Flags)
 
HRESULT ExtractArchiveForExecution (PCWSTR pszArchive, const CStringW &PackageName, CStringW &TempDir, CStringW &App)
 

Variables

static struct CommonInfo * g_pInfo
 

Macro Definition Documentation

◆ DB_GENINST_DELDIR

#define DB_GENINST_DELDIR   L"DelDir"

Definition at line 33 of file geninst.cpp.

◆ DB_GENINST_DELDIREMPTY

#define DB_GENINST_DELDIREMPTY   L"DelDirEmpty"

Definition at line 34 of file geninst.cpp.

◆ DB_GENINST_DELFILE

#define DB_GENINST_DELFILE   L"DelFile"

Definition at line 32 of file geninst.cpp.

◆ DB_GENINST_DELREG

#define DB_GENINST_DELREG   L"DelReg"

Definition at line 35 of file geninst.cpp.

◆ DB_GENINST_DELREGEMPTY

#define DB_GENINST_DELREGEMPTY   L"DelRegEmpty"

Definition at line 36 of file geninst.cpp.

◆ DB_GENINST_DIR

#define DB_GENINST_DIR   L"Dir"

Definition at line 28 of file geninst.cpp.

◆ DB_GENINST_FILES

#define DB_GENINST_FILES   L"Files"

Definition at line 27 of file geninst.cpp.

◆ DB_GENINST_ICON

#define DB_GENINST_ICON   L"Icon"

Definition at line 29 of file geninst.cpp.

◆ DB_GENINST_LNK

#define DB_GENINST_LNK   L"Lnk"

Definition at line 30 of file geninst.cpp.

◆ DB_GENINST_LNKARGS

#define DB_GENINST_LNKARGS   L"LnkParameters"

Definition at line 31 of file geninst.cpp.

◆ DB_NONE

#define DB_NONE   L"!"

Definition at line 26 of file geninst.cpp.

◆ REGPATH_UNINSTALL

#define REGPATH_UNINSTALL   L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"

Definition at line 24 of file geninst.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
UNOP_FILE 
UNOP_DIR 
UNOP_EMPTYDIR 
UNOP_REGKEY 
UNOP_EMPTYREGKEY 

Definition at line 38 of file geninst.cpp.

38 {
39 UNOP_FILE = 'F',
40 UNOP_DIR = 'D',
41 UNOP_EMPTYDIR = 'd',
42 UNOP_REGKEY = 'K',
43 UNOP_EMPTYREGKEY = 'k',
44};
@ UNOP_REGKEY
Definition: geninst.cpp:42
@ UNOP_FILE
Definition: geninst.cpp:39
@ UNOP_DIR
Definition: geninst.cpp:40
@ UNOP_EMPTYDIR
Definition: geninst.cpp:41
@ UNOP_EMPTYREGKEY
Definition: geninst.cpp:43

◆ anonymous enum

anonymous enum
Enumerator
IM_STARTPROGRESS 
IM_PROGRESS 
IM_END 

Definition at line 160 of file geninst.cpp.

#define WM_APP
Definition: eventvwr.h:73
@ IM_PROGRESS
Definition: geninst.cpp:160
@ IM_STARTPROGRESS
Definition: geninst.cpp:160
@ IM_END
Definition: geninst.cpp:160

◆ UninstallStage

Enumerator
US_ITEMS 
US_CONTAINERS 
UINSTALLSTAGECOUNT 

Definition at line 694 of file geninst.cpp.

695{
696 US_ITEMS,
699};
@ UINSTALLSTAGECOUNT
Definition: geninst.cpp:698
@ US_CONTAINERS
Definition: geninst.cpp:697
@ US_ITEMS
Definition: geninst.cpp:696

Function Documentation

◆ AddEntry()

static BOOL AddEntry ( WCHAR  Type,
LPCWSTR  Value 
)
static

Definition at line 227 of file geninst.cpp.

228{
229 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
231 name.Format(L"%c%u", Type, ++Info.EntryCount);
232 UINT err = Info.Entries.SetStringValue(name, Value);
233 if (err)
234 ErrorBox(err);
235 return !err;
236}
Type
Definition: Type.h:7
#define L(x)
Definition: resources.c:13
static UINT ErrorBox(UINT Error=GetLastError())
Definition: geninst.cpp:193
static struct CommonInfo * g_pInfo
unsigned int UINT
Definition: sysinfo.c:13
#define err(...)
Definition: name.c:39
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by AddUninstallOperationsFromDB(), CreateMainShortcut(), DECLARE_INTERFACE_(), ExtractAndInstallThread(), and InstallFiles().

◆ AddUninstallOperationsFromDB()

static void AddUninstallOperationsFromDB ( LPCWSTR  Name,
WCHAR  UnOp,
CStringW  PathPrefix = CStringW(L"") 
)
static

Definition at line 425 of file geninst.cpp.

426{
427 CStringW item, tmp;
428 if (*GetGenerateString(Name, tmp))
429 {
430 for (int pos = 1; pos > 0;)
431 {
432 pos = tmp.Find(L'|');
433 item = pos <= 0 ? tmp : tmp.Left(pos);
434 tmp = tmp.Mid(pos + 1);
435 AddEntry(UnOp, PathPrefix + item);
436 }
437 }
438}
CStringT Left(int nCount) const
Definition: cstringt.h:776
int Find(_In_ PCXSTR pszSub, _In_opt_ int iStart=0) const noexcept
Definition: cstringt.h:696
CStringT Mid(int iFirst, int nCount) const
Definition: cstringt.h:748
LPWSTR Name
Definition: desk.c:124
static BOOL AddEntry(WCHAR Type, LPCWSTR Value)
Definition: geninst.cpp:227
static LPCWSTR GetGenerateString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:207

Referenced by ExtractAndInstallThread().

◆ CreateMainShortcut()

static CStringW CreateMainShortcut ( const CStringW &  Target)
static

Definition at line 284 of file geninst.cpp.

285{
286 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
288 CStringW rel = Info.ShortcutFile, path, dir, tmp;
289
290 if (FAILED(GetSpecialPath(csidl, path, Info.GetGuiOwner())))
291 return L""; // Pretend everything is OK
292
293 int cat;
294 if (Info.Parser.GetInt(DB_CATEGORY, cat) && cat == ENUM_CAT_GAMES)
295 {
296 // Try to find the name of the Games folder in the Start Menu
297 if (GetLocalizedSMFolderName(L"SM_GamesName", L"shortcuts.inf", L"Games", tmp))
298 {
299 path = BuildPath(path, tmp);
300 }
301 }
302
303 // SHPathPrepareForWrite will prepare the necessary directories.
304 // Windows and ReactOS SHPathPrepareForWrite do not support '/'.
305 rel.Replace('/', '\\');
306 path = BuildPath(path, rel.GetString());
308 HRESULT hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, path, SHPPFW);
309 if ((Info.Error = ErrorFromHResult(hr)) != 0)
310 {
311 ErrorBox(Info.Error);
312 return L"";
313 }
314
316 hr = link.CoCreateInstance(CLSID_ShellLink, IID_IShellLinkW);
317 if (SUCCEEDED(hr))
318 {
319 if (SUCCEEDED(hr = link->SetPath(Target)))
320 {
322 link->SetWorkingDirectory(tmp);
323
325 link->SetArguments(tmp);
326
328 {
329 LPWSTR p = tmp.GetBuffer();
331 link->SetIconLocation(p, idx);
332 }
333 CComPtr<IPersistFile> persist;
334 if (SUCCEEDED(hr = link->QueryInterface(IID_IPersistFile, (void**)&persist)))
335 {
336 hr = persist->Save(path, FALSE);
337 }
338 }
339 }
340 if (SUCCEEDED(hr))
341 {
342 if (AddEntry(UNOP_FILE, path))
343 {
346 }
347 }
348 else
349 {
351 }
352 return Info.Error ? L"" : path;
353}
#define DB_CATEGORY
Definition: appinfo.h:92
@ ENUM_CAT_GAMES
Definition: appinfo.h:29
unsigned int dir
Definition: maze.c:112
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd=NULL)
Definition: misc.cpp:585
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:120
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:34
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:573
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
int Replace(PCXSTR pszOld, PCXSTR pszNew)
Definition: cstringt.h:886
const WCHAR * link
Definition: db.cpp:998
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:40
static HRESULT GetCustomIconPath(InstallInfo &Info, CStringW &Path)
Definition: geninst.cpp:239
static BOOL GetLocalizedSMFolderName(LPCWSTR WinVal, LPCWSTR RosInf, LPCWSTR RosVal, CStringW &Output)
Definition: geninst.cpp:259
#define DB_GENINST_LNKARGS
Definition: geninst.cpp:31
GLfloat GLfloat p
Definition: glext.h:8902
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
const GUID IID_IPersistFile
#define PathParseIconLocation
Definition: shlwapi.h:497
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteW(HWND hwnd, IUnknown *modless, LPCWSTR path, DWORD flags)
Definition: shlfileop.cpp:2364
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2213
#define SHPPFW_IGNOREFILENAME
Definition: shlobj.h:341
#define SHPPFW_DIRCREATE
Definition: shlobj.h:338
#define CSIDL_PROGRAMS
Definition: shlobj.h:2193
BOOL PerUser
Definition: geninst.cpp:183
uint16_t * LPWSTR
Definition: typedefs.h:56
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306

Referenced by ExtractAndInstallThread().

◆ CreateUI()

static BOOL CreateUI ( BOOL  Silent,
LPTHREAD_START_ROUTINE  ThreadProc 
)
static

Definition at line 645 of file geninst.cpp.

646{
647 enum { DLGW = 150, DLGH = 20, PAD = 4, PADx2 = PAD * 2, CHILDCOUNT = 1 };
649 static const WORD DlgTmpl[] =
650 {
651 LOWORD(DlgStyle), HIWORD(DlgStyle), 0, 0, CHILDCOUNT, 0, 0, DLGW, DLGH, 0, 0, 0,
652 PBS_MARQUEE, HIWORD(WS_CHILD | WS_VISIBLE), 0, 0, PAD, PAD, DLGW - PADx2, DLGH - PADx2, 1,
653 'm', 's', 'c', 't', 'l', 's', '_', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', '3', '2', 0, 0,
654 };
657 if (!hWnd)
658 {
659 ErrorBox();
660 return FALSE;
661 }
662 else if (!Silent)
663 {
665 }
666 MSG Msg;
667 while (GetMessageW(&Msg, NULL, 0, 0))
668 {
671 }
672 return TRUE;
673}
DWORD WINAPI ThreadProc(LPVOID lpParam)
Definition: ServiceMain.c:30
HWND hWnd
Definition: settings.c:17
struct @1887 Msg[]
#define TRUE
Definition: types.h:120
unsigned short WORD
Definition: ntddk_ex.h:93
static INT_PTR CALLBACK UIDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: geninst.cpp:604
LONG_PTR LPARAM
Definition: minwindef.h:175
#define PAD
Definition: options.h:30
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_VISIBLE
Definition: pedump.c:620
#define PBS_MARQUEE
Definition: commctrl.h:2203
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define DS_MODALFRAME
Definition: winuser.h:375
#define DS_CENTER
Definition: winuser.h:369
#define DS_NOFAILCREATE
Definition: winuser.h:376
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define SW_SHOW
Definition: winuser.h:786
HWND WINAPI CreateDialogIndirectParamW(_In_opt_ HINSTANCE, _In_ LPCDLGTEMPLATE, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by ExtractAndRunGeneratedInstaller(), and UninstallGenerated().

◆ ErrorBox()

static UINT ErrorBox ( UINT  Error = GetLastError())
inlinestatic

◆ ExtractAndInstallThread()

static DWORD CALLBACK ExtractAndInstallThread ( LPVOID  Parameter)
static

Definition at line 449 of file geninst.cpp.

450{
451 const BOOL PerUserModeDefault = TRUE;
452 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
453 LPCWSTR AppName = Info.AppName, Archive = Info.ArchivePath, None = DB_NONE;
454 CStringW installdir, tempdir, files, shortcut, tmp;
455 HRESULT hr;
456 CRegKey arpkey;
457 Info.ArpKey = &arpkey;
458
459 if (!*GetGenerateString(DB_GENINST_FILES, files, L"*.exe|*.*"))
461
463 if (tmp.CompareNoCase(L"User") == 0)
464 Info.PerUser = TRUE;
465 else if (tmp.CompareNoCase(L"Machine") == 0)
466 Info.PerUser = FALSE;
467 else
468 Info.PerUser = PerUserModeDefault;
469
470 hr = GetProgramFilesPath(installdir, Info.PerUser, Info.GetGuiOwner());
471 if ((Info.Error = ErrorFromHResult(hr)) != 0)
472 return ErrorBox(Info.Error);
473
475 if (tmp.Find('%') == 0 && ExpandEnvStrings(tmp))
476 installdir = tmp;
477 else if (tmp.Compare(None))
478 installdir = BuildPath(installdir, tmp.IsEmpty() ? AppName : tmp.GetString());
479 Info.InstallDir = installdir.GetString();
480 Info.InstallDirLen = installdir.GetLength() + 1;
481 hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, installdir, SHPPFW_DIRCREATE);
482 if ((Info.Error = ErrorFromHResult(hr)) != 0)
483 return ErrorBox(Info.Error);
484
485 // Create the destination directory, and inside it, a temporary directory
486 // where we will extract the archive to before moving the files to their
487 // final location (adding uninstall entries as we go)
488 tempdir.Format(L"%s\\~RAM%u.tmp", installdir.GetString(), GetCurrentProcessId());
489 Info.Error = CreateDirectoryTree(tempdir.GetString());
490 if (Info.Error)
491 return ErrorBox(Info.Error);
492
493 if (!*GetGenerateString(DB_GENINST_LNK, shortcut))
494 shortcut.Format(L"%s.lnk", AppName);
495 Info.ShortcutFile = shortcut.Compare(None) ? shortcut.GetString() : NULL;
496
497 // Create the uninstall registration key
498 LPCWSTR arpkeyname = AppName;
499 tmp = BuildPath(REGPATH_UNINSTALL, arpkeyname);
502 Info.Error = arpkey.Create(hRoot, tmp, NULL, REG_OPTION_NON_VOLATILE, regsam);
503 if (!Info.Error)
504 {
506 Info.Error = Info.Entries.Create(arpkey, GENERATE_ARPSUBKEY);
507 }
508 if (Info.Error)
509 ErrorBox(Info.Error);
510
511 if (!Info.Error)
512 Info.Error = ExtractArchive(Archive, tempdir, ExtractCallback, &Info);
513
514 if (!Info.Error)
515 {
516 // We now know how many files we extracted, change from marquee to normal progress bar.
517 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
518
519 for (int pos = 1; pos > 0 && !Info.Error;)
520 {
521 pos = files.Find(L'|');
522 CStringW item = pos <= 0 ? files : files.Left(pos);
523 files = files.Mid(pos + 1);
524 InstallFiles(tempdir, item, installdir);
525 }
526
527 if (!Info.MainApp.IsEmpty())
528 {
535
536 WriteArpEntry(L"DisplayName", AppName);
537 WriteArpEntry(L"InstallLocation", Info.InstallDir); // Note: This value is used by the uninstaller!
538
539 LPWSTR p = tmp.GetBuffer(1 + MAX_PATH);
540 p[0] = L'\"';
542 tmp.ReleaseBuffer();
543 UINT cch = tmp.GetLength(), bitness = IsSystem64Bit() ? 64 : 32;
544 WCHAR modechar = Info.PerUser ? 'U' : 'M';
545 LPCWSTR unparamsfmt = L"\" /" CMD_KEY_UNINSTALL L" /K%s \"%c%d\\%s\"";
546 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L"", modechar, bitness, arpkeyname);
547 WriteArpEntry(L"UninstallString", tmp);
548 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L" /S", modechar, bitness, arpkeyname);
549 WriteArpEntry(L"QuietUninstallString", tmp);
550
551 hr = GetCustomIconPath(Info, tmp);
553 WriteArpEntry(L"DisplayIcon", hr == S_OK ? tmp : Info.MainApp);
554
555 if (*GetCommonString(DB_VERSION, tmp))
556 WriteArpEntry(L"DisplayVersion", tmp);
557
558 SYSTEMTIME st;
559 GetSystemTime(&st);
560 tmp.Format(L"%.4u%.2u%.2u", st.wYear, st.wMonth, st.wDay);
561 WriteArpEntry(L"InstallDate", tmp);
562
563 if (*GetCommonString(DB_PUBLISHER, tmp))
564 WriteArpEntry(L"Publisher", tmp);
565
566#if DBG
567 tmp.Format(L"sys64=%d rapps%d", IsSystem64Bit(), sizeof(void*) * 8);
568 WriteArpEntry(L"_DEBUG", tmp);
569#endif
570 }
571
572 if (!Info.Error && Info.ShortcutFile)
573 {
574 tmp = CreateMainShortcut(Info.MainApp);
575 if (!tmp.IsEmpty() && !Info.Silent)
576 {
579 message.Format(format, const_cast<PCWSTR>(AppName));
580 if (MessageBoxW(Info.GetGuiOwner(), message, AppName, MB_YESNO | MB_ICONQUESTION) == IDYES)
581 {
582 SHELLEXECUTEINFOW sei = { sizeof(sei), SEE_MASK_NOASYNC, Info.GetGuiOwner() };
583 sei.lpFile = tmp;
584 sei.nShow = SW_SHOW;
585 ShellExecuteExW(&sei);
586 }
587 }
588 }
589 }
590
592 RemoveDirectory(installdir.GetString()); // This is harmless even if we installed something
593 return 0;
594}
#define DB_PUBLISHER
Definition: appinfo.h:93
#define GENERATE_ARPSUBKEY
Definition: appinfo.h:105
#define DB_VERSION
Definition: appinfo.h:91
#define DB_SCOPE
Definition: appinfo.h:98
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:527
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:553
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:566
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:609
BOOL IsSystem64Bit()
Definition: misc.cpp:386
#define IDS_INSTGEN_CONFIRMINSTRUNAPP
Definition: resource.h:243
@ None
Definition: install.h:14
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass=REG_NONE, DWORD dwOptions=REG_OPTION_NON_VOLATILE, REGSAM samDesired=KEY_READ|KEY_WRITE, LPSECURITY_ATTRIBUTES lpSecAttr=NULL, LPDWORD lpdwDisposition=NULL) noexcept
Definition: atlbase.h:1189
LONG RecurseDeleteKey(LPCTSTR lpszKey) noexcept
Definition: atlbase.h:1414
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
int GetLength() const noexcept
Definition: atlsimpstr.h:362
int CompareNoCase(_In_z_ PCXSTR psz) const
Definition: cstringt.h:743
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
int Compare(_In_z_ PCXSTR psz) const
Definition: cstringt.h:738
static CHAR AppName[MAX_PATH]
Definition: dem.c:252
#define MAX_PATH
Definition: compat.h:34
VOID WINAPI GetSystemTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:304
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL CALLBACK ExtractCallback(const EXTRACTCALLBACKINFO &, void *Context)
Definition: geninst.cpp:441
#define DB_GENINST_DIR
Definition: geninst.cpp:28
#define DB_GENINST_FILES
Definition: geninst.cpp:27
#define DB_GENINST_DELREG
Definition: geninst.cpp:35
#define DB_GENINST_DELDIR
Definition: geninst.cpp:33
static void AddUninstallOperationsFromDB(LPCWSTR Name, WCHAR UnOp, CStringW PathPrefix=CStringW(L""))
Definition: geninst.cpp:425
static UINT ExtractArchive(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:153
#define DB_GENINST_DELDIREMPTY
Definition: geninst.cpp:34
#define DB_NONE
Definition: geninst.cpp:26
#define DB_GENINST_LNK
Definition: geninst.cpp:30
#define REGPATH_UNINSTALL
Definition: geninst.cpp:24
#define DB_GENINST_DELFILE
Definition: geninst.cpp:32
static BOOL InstallFiles(const CStringW &SourceDirBase, const CStringW &Spec, const CStringW &DestinationDir)
Definition: geninst.cpp:356
#define DB_GENINST_DELREGEMPTY
Definition: geninst.cpp:36
static CStringW CreateMainShortcut(const CStringW &Target)
Definition: geninst.cpp:284
static void WriteArpEntry(LPCWSTR Name, LPCWSTR Value, UINT Type=REG_SZ)
Definition: geninst.cpp:215
static LPCWSTR GetCommonString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:199
#define S_OK
Definition: intsafe.h:52
static HTREEITEM hRoot
Definition: treeview.c:383
@ Archive
Definition: scrrun.idl:75
#define KEY_READ
Definition: nt_native.h:1026
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define KEY_WRITE
Definition: nt_native.h:1034
short WCHAR
Definition: pedump.c:58
#define MB_YESNO
Definition: winuser.h:828
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define SendMessage
Definition: winuser.h:6009
#define MB_ICONQUESTION
Definition: winuser.h:800
#define IDYES
Definition: winuser.h:846
_In_ UINT _In_ UINT cch
Definition: shellapi.h:432
#define SEE_MASK_NOASYNC
Definition: shellapi.h:35
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2732
Definition: tftpd.h:60
const uint16_t * PCWSTR
Definition: typedefs.h:57
const uint16_t * LPCWSTR
Definition: typedefs.h:57
#define CMD_KEY_UNINSTALL
Definition: unattended.h:5
#define RemoveDirectory
Definition: winbase.h:3618
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1205
#define GetModuleFileName
Definition: winbase.h:3554
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_CAN_NOT_COMPLETE
Definition: winerror.h:906
#define ERROR_BAD_FORMAT
Definition: winerror.h:236
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
ACCESS_MASK REGSAM
Definition: winreg.h:76
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by ExtractAndRunGeneratedInstaller().

◆ ExtractAndRunGeneratedInstaller()

BOOL ExtractAndRunGeneratedInstaller ( const CAvailableApplicationInfo &  AppInfo,
LPCWSTR  Archive,
bool  Silent 
)

Definition at line 676 of file geninst.cpp.

677{
678 InstallInfo Info(AppInfo.szDisplayName, *AppInfo.GetConfigParser(), Archive);
679 Info.Silent = Silent;
680 g_pInfo = &Info;
681 return CreateUI(Info.Silent, ExtractAndInstallThread) ? !Info.Error : FALSE;
682}
CStringW szDisplayName
Definition: appinfo.h:123
CConfigParser * GetConfigParser() const
Definition: appinfo.h:178
static DWORD CALLBACK ExtractAndInstallThread(LPVOID Parameter)
Definition: geninst.cpp:449
static BOOL CreateUI(BOOL Silent, LPTHREAD_START_ROUTINE ThreadProc)
Definition: geninst.cpp:645

Referenced by HandleGenerateInstallerCommand().

◆ ExtractArchive()

static UINT ExtractArchive ( LPCWSTR  Archive,
const CStringW &  OutputDir,
EXTRACTCALLBACK  Callback,
void *  Context 
)
static

Definition at line 153 of file geninst.cpp.

154{
155 BOOL isCab = LOBYTE(ClassifyFile(Archive)) == 'C';
156 return isCab ? ExtractCab(Archive, OutputDir, Callback, Context)
157 : ExtractZip(Archive, OutputDir, Callback, Context);
158}
UINT ClassifyFile(PCWSTR Path)
Definition: misc.cpp:127
_In_ ULONG _In_ ULONG _In_opt_ DXGKCB_MIRACAST_SEND_MESSAGE_CALLBACK Callback
Definition: dispmprt.h:620
static UINT ExtractZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:134
static UINT ExtractCab(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:142
#define LOBYTE(W)
Definition: jmemdos.c:487
_In_ PVOID Context
Definition: storport.h:2269

Referenced by ExtractAndInstallThread(), and ExtractArchiveForExecution().

◆ ExtractArchiveForExecution()

HRESULT ExtractArchiveForExecution ( PCWSTR  pszArchive,
const CStringW &  PackageName,
CStringW &  TempDir,
CStringW &  App 
)

Definition at line 845 of file geninst.cpp.

846{
847 WCHAR TempDirBuf[MAX_PATH], UniqueDir[MAX_PATH];
849 Deleter <CAvailableApplicationInfo*>del(pAppInfo);
850 if (!pAppInfo)
852 CConfigParser *pCfg = pAppInfo->GetConfigParser();
853 if (!GetTempPathW(_countof(TempDirBuf), TempDirBuf))
854 return E_FAIL;
855 wsprintfW(UniqueDir, L"~%s-%u", RAPPS_NAME, GetCurrentProcessId());
856 TempDir = BuildPath(TempDirBuf, UniqueDir);
858 if (FAILED(hr))
859 return hr;
860
861 hr = HResultFromWin32(ExtractArchive(pszArchive, TempDir, NULL, NULL));
862 if (SUCCEEDED(hr))
863 {
866 {
868 HANDLE hFind = FindFirstFileW(Exe = BuildPath(TempDir, L"*.exe"), &wfd);
869 if (hFind != INVALID_HANDLE_VALUE)
870 {
871 FindClose(hFind);
872 Exe = wfd.cFileName;
873 }
874 }
875 App = BuildPath(TempDir, Exe);
878 }
879
880 if (FAILED(hr) && !TempDir.IsEmpty())
882 return hr;
883}
#define DB_EXEINZIPSECTION
Definition: appinfo.h:107
#define DB_EXEINZIP_EXE
Definition: appinfo.h:108
#define RAPPS_NAME
Definition: defines.h:34
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
static CAvailableApplicationInfo * CreateAvailableAppInstance(const CStringW &PkgName, PCWSTR DBPath=NULL)
Definition: appdb.cpp:110
UINT GetSectionString(LPCWSTR Section, LPCWSTR Name, CStringW &Result)
#define E_FAIL
Definition: ddrawi.h:102
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:636
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2098
#define HResultFromWin32
Definition: loader.cpp:14
HWND hMainWnd
Definition: magnifier.c:32
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define _countof(array)
Definition: sndvol32.h:70
Definition: xml2sdb.h:163
_Field_z_ WCHAR cFileName[MAX_PATH]
Definition: minwinbase.h:291
#define ERROR_NOT_FOUND
Definition: winerror.h:1014

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ ExtractCab()

static UINT ExtractCab ( LPCWSTR  Archive,
const CStringW &  OutputDir,
EXTRACTCALLBACK  Callback,
void *  Context 
)
static

Definition at line 142 of file geninst.cpp.

144{
145 if (ExtractFilesFromCab(Archive, OutputDir, Callback, Context))
146 return ERROR_SUCCESS;
148 return err ? err : ERROR_INTERNAL_ERROR;
149}
BOOL ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: cabinet.cpp:250
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:1185

Referenced by ExtractArchive().

◆ ExtractCallback()

static BOOL CALLBACK ExtractCallback ( const EXTRACTCALLBACKINFO &  ,
void *  Context 
)
static

Definition at line 441 of file geninst.cpp.

442{
444 Info.Count += 1;
445 return TRUE;
446}
DWORD Count
Definition: geninst.cpp:166

Referenced by ExtractAndInstallThread().

◆ ExtractFilesFromZip()

static int ExtractFilesFromZip ( LPCWSTR  Archive,
const CStringW &  OutputDir,
EXTRACTCALLBACK  Callback,
void *  Context 
)
static

Definition at line 58 of file geninst.cpp.

60{
61 const UINT pkzefsutf8 = 1 << 11; // APPNOTE; APPENDIX D
64 unzFile hzf = unzOpen2_64(Archive, &zff);
65 if (!hzf)
66 return UNZ_BADZIPFILE;
67 CStringA narrow;
69 int zerr = unzGoToFirstFile(hzf);
70 for (; zerr == UNZ_OK; zerr = unzGoToNextFile(hzf))
71 {
73 zerr = unzGetCurrentFileInfo64(hzf, &fi, NULL, 0, NULL, 0, NULL, 0);
74 if (zerr != UNZ_OK)
75 break;
76 LPSTR file = narrow.GetBuffer(fi.size_filename);
77 zerr = unzGetCurrentFileInfo64(hzf, &fi, file, narrow.GetAllocLength(), NULL, 0, NULL, 0);
78 if (zerr != UNZ_OK)
79 break;
81 narrow.Replace('/', '\\');
82 while (narrow[0] == '\\')
83 narrow = narrow.Mid(1);
84 UINT codepage = (fi.flag & pkzefsutf8) ? CP_UTF8 : 1252;
85 UINT cch = MultiByteToWideChar(codepage, 0, narrow, -1, NULL, 0);
86 cch = MultiByteToWideChar(codepage, 0, narrow, -1, path.GetBuffer(cch - 1), cch);
87 if (!cch)
88 break;
89 path.ReleaseBuffer(cch - 1);
91 BYTE attsys = HIBYTE(fi.version), dos = 0, ntfs = 10, vfat = 14;
92 if ((attsys == dos || attsys == ntfs || attsys == vfat) && LOBYTE(fi.external_fa))
93 fileatt = LOBYTE(fi.external_fa);
94
97 continue; // Skip file
98
99 path = BuildPath(OutputDir, path);
101 if (!dir.IsEmpty() && (err = CreateDirectoryTree(dir)))
102 {
103 zerr = UNZ_ERRNO;
105 break;
106 }
107
108 if ((zerr = unzOpenCurrentFile(hzf)) != UNZ_OK)
109 break;
110 zerr = UNZ_ERRNO;
113 NULL, CREATE_ALWAYS, fileatt, NULL);
115 {
116 DWORD len = 1024 * 4, cb;
117 LPSTR buf = narrow.GetBuffer(len);
118 for (zerr = UNZ_OK; zerr == UNZ_OK;)
119 {
120 len = zerr = unzReadCurrentFile(hzf, buf, len);
121 if (zerr <= 0)
122 break;
123 zerr = WriteFile(hFile, buf, len, &cb, NULL) && cb == len ? UNZ_OK : UNZ_ERRNO;
124 }
126 }
128 }
129 unzClose(hzf);
130 return zerr == UNZ_END_OF_LIST_OF_FILE ? UNZ_OK : zerr;
131}
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:81
int GetAllocLength() const noexcept
Definition: atlsimpstr.h:357
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MultiByteToWideChar
Definition: compat.h:110
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:457
#define HIBYTE(W)
Definition: jmemdos.c:486
#define CREATE_ALWAYS
Definition: disk.h:72
IMAGE_DOS_HEADER dos
Definition: module.c:67
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define GENERIC_WRITE
Definition: nt_native.h:90
#define CP_UTF8
Definition: nls.h:20
Definition: fci.c:123
uLong version
Definition: unzip.h:113
ZPOS64_T uncompressed_size
Definition: unzip.h:120
uLong size_filename
Definition: unzip.h:121
uLong external_fa
Definition: unzip.h:127
char * LPSTR
Definition: typedefs.h:51
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: unzip.c:783
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:1129
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1183
int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition: unzip.c:1648
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Definition: unzip.c:1691
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:2014
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1204
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:813
#define UNZ_BADZIPFILE
Definition: unzip.h:79
#define UNZ_ERRNO
Definition: unzip.h:76
#define UNZ_END_OF_LIST_OF_FILE
Definition: unzip.h:75
voidp unzFile
Definition: unzip.h:70
#define UNZ_OK
Definition: unzip.h:74
int codepage
Definition: win_iconv.c:156
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ExtractZip().

◆ ExtractZip()

static UINT ExtractZip ( LPCWSTR  Archive,
const CStringW &  OutputDir,
EXTRACTCALLBACK  Callback,
void *  Context 
)
static

Definition at line 134 of file geninst.cpp.

136{
137 int zerr = ExtractFilesFromZip(Archive, OutputDir, Callback, Context);
138 return zerr == UNZ_ERRNO ? GetLastError() : zerr ? ERROR_INTERNAL_ERROR : 0;
139}
static int ExtractFilesFromZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:58

Referenced by ExtractArchive().

◆ GetCommonString()

static LPCWSTR GetCommonString ( LPCWSTR  Name,
CStringW &  Output,
LPCWSTR  Default = L"" 
)
static

Definition at line 199 of file geninst.cpp.

200{
201 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
203 return (found && !Output.IsEmpty() ? Output : Output = Default).GetString();
204}
static HRESULT GetString(ASSOCSTR Str, UINT Flags, LPCWSTR pszAssoc, LPCWSTR pszExtra, PWSTR Out, HKEY hProgId=NULL)
BOOL GetString(const CStringW &KeyName, CStringW &ResultString)
@ Default
Definition: stdole2.idl:392
@ Output
Definition: arc.h:94
CConfigParser & Parser
Definition: geninst.cpp:179

Referenced by ExtractAndInstallThread().

◆ GetCustomIconPath()

static HRESULT GetCustomIconPath ( InstallInfo &  Info,
CStringW &  Path 
)
static

Definition at line 239 of file geninst.cpp.

240{
242 {
243 if (Path.Compare(DB_NONE) == 0)
245 Path = BuildPath(Info.InstallDir, Path);
246 int idx = PathParseIconLocation(Path.GetBuffer());
247 Path.ReleaseBuffer();
248 HICON hIco = NULL;
249 if (ExtractIconExW(Path, idx, &hIco, NULL, 1))
250 DestroyIcon(hIco);
251 if (idx)
252 Path.AppendFormat(L",%d", idx);
253 return hIco ? S_OK : S_FALSE;
254 }
256}
PRTL_UNICODE_STRING_BUFFER Path
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define DB_GENINST_ICON
Definition: geninst.cpp:29
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:855
static HICON
Definition: imagelist.c:80
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2422
#define S_FALSE
Definition: winerror.h:3451

Referenced by CreateMainShortcut(), and ExtractAndInstallThread().

◆ GetGenerateString()

static LPCWSTR GetGenerateString ( LPCWSTR  Name,
CStringW &  Output,
LPCWSTR  Default = L"" 
)
static

Definition at line 207 of file geninst.cpp.

208{
209 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
211 return (r ? Output : Output = Default).GetString();
212}
#define DB_GENINSTSECTION
Definition: appinfo.h:104
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

Referenced by AddUninstallOperationsFromDB(), CreateMainShortcut(), ExtractAndInstallThread(), and GetCustomIconPath().

◆ GetLocalizedSMFolderName()

static BOOL GetLocalizedSMFolderName ( LPCWSTR  WinVal,
LPCWSTR  RosInf,
LPCWSTR  RosVal,
CStringW &  Output 
)
static

Definition at line 259 of file geninst.cpp.

260{
261 CRegKey key;
262 if (key.Open(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", KEY_READ) == ERROR_SUCCESS &&
263 GetRegString(key, WinVal, Output) && !Output.IsEmpty())
264 {
265 return TRUE;
266 }
267 WCHAR windir[MAX_PATH];
268 GetWindowsDirectoryW(windir, _countof(windir));
269 CStringW path = BuildPath(BuildPath(windir, L"inf"), RosInf), section;
270 DWORD lang = 0, lctype = LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER;
271 if (GetLocaleInfoW(GetUserDefaultLCID(), lctype, (LPWSTR) &lang, sizeof(lang) / sizeof(WCHAR)))
272 {
273 section.Format(L"Strings.%.4x", lang);
274 if (ReadIniValue(path, section, RosVal, Output) > 0)
275 return TRUE;
276 section.Format(L"Strings.%.2x", PRIMARYLANGID(lang));
277 if (ReadIniValue(path, section, RosVal, Output) > 0)
278 return TRUE;
279 }
280 return ReadIniValue(path, L"Strings", RosVal, Output) > 0;
281}
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:504
HRESULT ReadIniValue(LPCWSTR File, LPCWSTR Section, LPCWSTR Name, CStringW &Output)
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2370
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1216
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
#define PRIMARYLANGID(l)
Definition: nls.h:16
Definition: copy.c:22
Definition: parser.c:56
static const WCHAR lang[]
Definition: wbemdisp.c:287
#define LOCALE_ILANGUAGE
Definition: winnls.h:30

Referenced by CreateMainShortcut().

◆ InstallFiles()

static BOOL InstallFiles ( const CStringW &  SourceDirBase,
const CStringW &  Spec,
const CStringW &  DestinationDir 
)
static

Definition at line 356 of file geninst.cpp.

358{
359 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
360 CStringW sourcedir, filespec;
361 filespec = SplitFileAndDirectory(Spec, &sourcedir); // Split "[OptionalDir\]*.ext"
362 sourcedir = BuildPath(SourceDirBase, sourcedir);
363 BOOL success = TRUE;
365 HANDLE hFind = FindFirstFileW(BuildPath(sourcedir, filespec), &wfd);
366 if (hFind == INVALID_HANDLE_VALUE)
367 {
370 return TRUE;
371 else
372 return !ErrorBox(error);
373 }
374
375 for (;;)
376 {
377 CStringW from = BuildPath(sourcedir, wfd.cFileName);
378 CStringW to = BuildPath(DestinationDir, wfd.cFileName);
379 CStringW uninstpath = to.Mid(Info.InstallDirLen - 1);
381 {
382 LPWSTR p = wfd.cFileName;
383 BOOL dots = p[0] == '.' && (!p[1] || (p[1] == '.' && !p[2]));
384 if (!dots)
385 {
386 Info.Error = CreateDirectoryTree(to);
387 if (Info.Error)
388 {
389 success = !ErrorBox(Info.Error);
390 }
391
392 if (success)
393 {
394 success = InstallFiles(from, filespec, to);
395 }
396 AddEntry(UNOP_EMPTYDIR, uninstpath);
397 }
398 }
399 else
400 {
402 if (success)
403 {
404 if (Info.MainApp.IsEmpty())
405 {
406 Info.MainApp = to;
407 }
408 success = AddEntry(UNOP_FILE, uninstpath);
409 }
410 else
411 {
412 ErrorBox();
413 }
414 SendMessage(g_pInfo->hDlg, IM_PROGRESS, 0, 0);
415 }
416
417 if (!success || !FindNextFileW(hFind, &wfd))
418 break;
419 }
420 FindClose(hFind);
421 return success;
422}
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29
#define error(str)
Definition: mkdosfs.c:1605
CardRegion * from
Definition: spigame.cpp:19
DWORD dwFileAttributes
Definition: minwinbase.h:283
#define success(from, fromstr, to, tostr)
#define MoveFileEx
Definition: winbase.h:3601

Referenced by ExtractAndInstallThread(), and InstallFiles().

◆ IsZipFile()

BOOL IsZipFile ( PCWSTR  Path)

Definition at line 46 of file geninst.cpp.

47{
50 unzFile hzf = unzOpen2_64(Path, &zff);
51 if (!hzf)
52 return FALSE;
53 unzClose(hzf);
54 return TRUE;
55}

Referenced by ClassifyFile().

◆ UIDlgProc()

static INT_PTR CALLBACK UIDlgProc ( HWND  hDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 604 of file geninst.cpp.

605{
606 HWND hPB = GetDlgItem(hDlg, 1);
607 switch(uMsg)
608 {
609 case IM_STARTPROGRESS:
612 SendMessageW(hPB, PBM_SETRANGE32, 0, g_pInfo->Count);
613 SendMessageW(hPB, PBM_SETPOS, 0, 0);
614 break;
615 case IM_PROGRESS:
616 SendMessageW(hPB, PBM_DELTAPOS, 1, 0);
617 break;
618 case IM_END:
619 DestroyWindow(hDlg);
620 break;
621 case WM_INITDIALOG:
622 {
624 g_pInfo->hDlg = hDlg;
626 SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIco);
627 SendMessageW(hDlg, WM_SETTEXT, 0, (LPARAM)g_pInfo->AppName);
629 {
630 ErrorBox();
631 SendMessageW(hDlg, IM_END, 0, 0);
632 }
633 return TRUE;
634 }
635 case WM_CLOSE:
636 return TRUE;
637 case WM_DESTROY:
638 PostMessage(NULL, WM_QUIT, 0, 0);
639 break;
640 }
641 return FALSE;
642}
#define IDI_MAIN
Definition: resource.h:4
LPARAM lParam
Definition: combotst.c:139
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE thread_proc, void *data, DWORD flags, LPTHREAD_START_ROUTINE callback)
Definition: main.c:1628
HINSTANCE hInst
Definition: dxdiag.c:13
static DWORD CALLBACK WorkerThread(LPVOID Parameter)
Definition: geninst.cpp:597
#define PBM_SETRANGE32
Definition: commctrl.h:2193
#define PBM_DELTAPOS
Definition: commctrl.h:2190
#define PBM_SETPOS
Definition: commctrl.h:2189
#define PBM_SETMARQUEE
Definition: commctrl.h:2204
@ CTF_COINIT
Definition: shlwapi.h:75
#define WM_CLOSE
Definition: winuser.h:1649
#define WM_QUIT
Definition: winuser.h:1651
#define WM_INITDIALOG
Definition: winuser.h:1767
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SETTEXT
Definition: winuser.h:1645
#define PostMessage
Definition: winuser.h:5998
#define WM_DESTROY
Definition: winuser.h:1637
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GWL_STYLE
Definition: winuser.h:863
BOOL WINAPI DestroyWindow(_In_ HWND)
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2444
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define ICON_BIG
Definition: tnclass.cpp:51
#define SetWindowLongPtr
Definition: treelist.c:70

Referenced by CreateUI().

◆ UninstallGenerated()

BOOL UninstallGenerated ( CInstalledApplicationInfo &  AppInfo,
UninstallCommandFlags  Flags 
)

Definition at line 837 of file geninst.cpp.

838{
840 g_pInfo = &Info;
841 return CreateUI(Info.Silent, UninstallThread) ? !Info.Error : FALSE;
842}
@ UCF_SILENT
Definition: appinfo.h:75
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
static DWORD CALLBACK UninstallThread(LPVOID Parameter)
Definition: geninst.cpp:702

Referenced by CInstalledApplicationInfo::UninstallApplication().

◆ UninstallThread()

static DWORD CALLBACK UninstallThread ( LPVOID  Parameter)
static

Definition at line 702 of file geninst.cpp.

703{
704 UninstallInfo &Info = *static_cast<UninstallInfo *>(g_pInfo);
705
706 CStringW tmp, path, installdir;
708 tmp.Format(path.GetString(), Info.AppName);
709 if (!Info.Silent &&
710 MessageBox(Info.GetGuiOwner(), tmp, Info.AppName, MB_YESNO | MB_ICONQUESTION) != IDYES)
711 {
712 Info.Error = ERROR_CANCELLED;
713 SendMessage(Info.hDlg, IM_END, 0, 0);
714 return 0;
715 }
716
717 Info.Error = Info.Entries.Open(*Info.ArpKey, GENERATE_ARPSUBKEY, KEY_READ);
718 if (Info.Error)
719 return ErrorBox(Info.Error);
720
721 RegQueryInfoKey(Info.Entries, NULL, NULL, NULL, NULL, NULL, NULL, &Info.Count, NULL, NULL, NULL, NULL);
722 Info.Count *= UINSTALLSTAGECOUNT;
723 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
724
725 if (!GetRegString(*Info.ArpKey, L"InstallLocation", installdir) || installdir.IsEmpty())
727
728 for (UINT stage = 0; stage < UINSTALLSTAGECOUNT; ++stage)
729 {
730 for (UINT vi = 0;; ++vi)
731 {
733 DWORD valsize = _countof(value), size = sizeof(data) - sizeof(WCHAR), rt;
735 UINT err = RegEnumValue(Info.Entries, vi, value, &valsize, NULL, &rt, (BYTE*)data, &size);
736 if (err)
737 {
739 {
740 return ErrorBox(err);
741 }
742 break;
743 }
744
745 LPCWSTR str = data;
746 WORD op = value[0];
747 switch(*data ? MAKEWORD(stage, op) : 0)
748 {
751 {
752 REGSAM wowsam = 0;
753 HKEY hKey = NULL;
754 path.Format(L"%.4s", data);
755 if (path.CompareNoCase(L"HKCR") == 0)
757 else if (path.CompareNoCase(L"HKCU") == 0)
759 else if (path.CompareNoCase(L"HKLM") == 0)
761
762 if (data[4] == '6' && data[5] == '4')
763 wowsam = KEY_WOW64_64KEY;
764 else if (data[4] == '3' && data[5] == '2')
765 wowsam = KEY_WOW64_32KEY;
766
767 str = &data[wowsam ? 6 : 4];
768 if (!hKey || *str != L'\\')
769 break;
770 tmp = SplitFileAndDirectory(++str, &path);
771 if (!tmp.IsEmpty() && !path.IsEmpty())
772 {
773 CRegKey key;
774 err = key.Open(hKey, path, DELETE | wowsam);
775 if (err == ERROR_SUCCESS)
776 {
777 if (op == UNOP_REGKEY)
778 err = key.RecurseDeleteKey(tmp);
779 else if (RegKeyHasValues(hKey, str, wowsam) == S_FALSE)
780 key.DeleteSubKey(tmp); // DelRegEmpty ignores errors
781 }
782 switch(err)
783 {
784 case ERROR_SUCCESS:
787 break;
788 default:
789 return ErrorBox(err);
790 }
791 }
792 break;
793 }
794
796 {
797 if (*data == L'\\')
798 str = (path = BuildPath(installdir, data));
799
800 if (!DeleteFile(str))
801 {
802 err = GetLastError();
804 {
805 return ErrorBox(err);
806 }
807 }
808 break;
809 }
810
813 {
814 if (*data == L'\\')
815 str = (path = BuildPath(installdir, data));
816
817 if (op == UNOP_DIR)
818 DeleteDirectoryTree(str, Info.GetGuiOwner());
819 else
821 break;
822 }
823 }
824 SendMessage(Info.hDlg, IM_PROGRESS, 0, 0);
825 }
826 }
827 if (!Info.Error)
828 {
830 if (Info.Error)
831 return ErrorBox(Info.Error);
832 }
833 return 0;
834}
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:486
#define IDS_INSTGEN_CONFIRMUNINST
Definition: resource.h:242
static DWORD RemoveInstalledAppFromRegistry(const CAppInfo *Info)
Definition: appdb.cpp:355
UINT op
Definition: effect.c:235
#define ERROR_INVALID_NAME
Definition: compat.h:103
FxAutoRegKey hKey
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
struct msdos_volume_info vi
Definition: mkdosfs.c:440
#define DELETE
Definition: nt_native.h:57
#define UNICODE_NULL
#define MessageBox
Definition: winuser.h:5988
const WCHAR * str
#define MAKEWORD(a, b)
Definition: typedefs.h:248
Definition: pdh_main.c:64
#define DeleteFile
Definition: winbase.h:3487
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_CANCELLED
Definition: winerror.h:1055
#define RegEnumValue
Definition: winreg.h:542
#define RegQueryInfoKey
Definition: winreg.h:553
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10

Referenced by UninstallGenerated().

◆ WorkerThread()

static DWORD CALLBACK WorkerThread ( LPVOID  Parameter)
static

Definition at line 597 of file geninst.cpp.

598{
600 return SendMessage(g_pInfo->hDlg, IM_END, 0, 0);
601}
PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE
Definition: minwinbase.h:124
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by UIDlgProc().

◆ WriteArpEntry()

static void WriteArpEntry ( LPCWSTR  Name,
LPCWSTR  Value,
UINT  Type = REG_SZ 
)
static

Definition at line 215 of file geninst.cpp.

216{
217 // Write a "Add/Remove programs" value if we have a valid uninstaller key
218 if (g_pInfo->ArpKey)
219 {
220 UINT err = g_pInfo->ArpKey->SetStringValue(Name, Value, Type);
221 if (err)
222 ErrorBox(err);
223 }
224}

Referenced by ExtractAndInstallThread().

Variable Documentation

◆ g_pInfo