ReactOS 0.4.15-dev-8219-ge8b88cf
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 "minizip/ioapi.c"
#include "minizip/iowin32.c"
#include "minizip/unzip.c"
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_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_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

static int ExtractFilesFromZip (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
 
static UINT ExtractZip (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
 
static UINT ExtractCab (LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
 
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 BOOL CreateShortcut (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 *Cookie)
 
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)
 
static DWORD CALLBACK UninstallThread (LPVOID Parameter)
 
BOOL UninstallGenerated (CInstalledApplicationInfo &AppInfo, UninstallCommandFlags Flags)
 

Variables

static struct CommonInfog_pInfo
 

Macro Definition Documentation

◆ DB_GENINST_DELDIR

#define DB_GENINST_DELDIR   L"DelDir"

Definition at line 36 of file geninst.cpp.

◆ DB_GENINST_DELDIREMPTY

#define DB_GENINST_DELDIREMPTY   L"DelDirEmpty"

Definition at line 37 of file geninst.cpp.

◆ DB_GENINST_DELFILE

#define DB_GENINST_DELFILE   L"DelFile"

Definition at line 35 of file geninst.cpp.

◆ DB_GENINST_DELREG

#define DB_GENINST_DELREG   L"DelReg"

Definition at line 38 of file geninst.cpp.

◆ DB_GENINST_DELREGEMPTY

#define DB_GENINST_DELREGEMPTY   L"DelRegEmpty"

Definition at line 39 of file geninst.cpp.

◆ DB_GENINST_DIR

#define DB_GENINST_DIR   L"Dir"

Definition at line 32 of file geninst.cpp.

◆ DB_GENINST_FILES

#define DB_GENINST_FILES   L"Files"

Definition at line 31 of file geninst.cpp.

◆ DB_GENINST_ICON

#define DB_GENINST_ICON   L"Icon"

Definition at line 33 of file geninst.cpp.

◆ DB_GENINST_LNK

#define DB_GENINST_LNK   L"Lnk"

Definition at line 34 of file geninst.cpp.

◆ REGPATH_UNINSTALL

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

Definition at line 29 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 41 of file geninst.cpp.

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

◆ anonymous enum

anonymous enum
Enumerator
IM_STARTPROGRESS 
IM_PROGRESS 
IM_END 

Definition at line 143 of file geninst.cpp.

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

◆ UninstallStage

Enumerator
US_ITEMS 
US_CONTAINERS 
UINSTALLSTAGECOUNT 

Definition at line 669 of file geninst.cpp.

670{
671 US_ITEMS,
674};
@ UINSTALLSTAGECOUNT
Definition: geninst.cpp:673
@ US_CONTAINERS
Definition: geninst.cpp:672
@ US_ITEMS
Definition: geninst.cpp:671

Function Documentation

◆ AddEntry()

static BOOL AddEntry ( WCHAR  Type,
LPCWSTR  Value 
)
static

Definition at line 217 of file geninst.cpp.

218{
219 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
221 name.Format(L"%c%u", Type, ++Info.EntryCount);
222 UINT err = Info.Entries.SetStringValue(name, Value);
223 if (err)
224 ErrorBox(err);
225 return !err;
226}
Type
Definition: Type.h:7
static UINT ErrorBox(UINT Error=GetLastError())
Definition: geninst.cpp:176
static struct CommonInfo * g_pInfo
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#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(), CreateShortcut(), DECLARE_INTERFACE_(), ExtractAndInstallThread(), and InstallFiles().

◆ AddUninstallOperationsFromDB()

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

Definition at line 410 of file geninst.cpp.

411{
412 CStringW item, tmp;
413 if (*GetGenerateString(Name, tmp))
414 {
415 for (int pos = 1; pos > 0;)
416 {
417 pos = tmp.Find(L'|');
418 item = pos <= 0 ? tmp : tmp.Left(pos);
419 tmp = tmp.Mid(pos + 1);
420 AddEntry(UnOp, PathPrefix + item);
421 }
422 }
423}
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
static BOOL AddEntry(WCHAR Type, LPCWSTR Value)
Definition: geninst.cpp:217
static LPCWSTR GetGenerateString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:197
static ATOM item
Definition: dde.c:856

Referenced by ExtractAndInstallThread().

◆ CreateShortcut()

static BOOL CreateShortcut ( const CStringW Target)
static

Definition at line 272 of file geninst.cpp.

273{
274 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
276 CStringW rel = Info.ShortcutFile, path, dir, tmp;
277
278 if (FAILED(GetSpecialPath(csidl, path, Info.GetGuiOwner())))
279 return TRUE; // Pretend everything is OK
280
281 int cat;
282 if (Info.Parser.GetInt(DB_CATEGORY, cat) && cat == ENUM_CAT_GAMES)
283 {
284 // Try to find the name of the Games folder in the Start Menu
285 if (GetLocalizedSMFolderName(L"SM_GamesName", L"shortcuts.inf", L"Games", tmp))
286 {
287 path = BuildPath(path, tmp);
288 }
289 }
290
291 // SHPathPrepareForWrite will prepare the necessary directories.
292 // Windows and ReactOS SHPathPrepareForWrite do not support '/'.
293 rel.Replace('/', '\\');
294 path = BuildPath(path, rel.GetString());
296 HRESULT hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, path, SHPPFW);
297 if ((Info.Error = ErrorFromHResult(hr)) != 0)
298 {
299 ErrorBox(Info.Error);
300 return FALSE;
301 }
302
304 hr = link.CoCreateInstance(CLSID_ShellLink, IID_IShellLinkW);
305 if (SUCCEEDED(hr))
306 {
307 if (SUCCEEDED(hr = link->SetPath(Target)))
308 {
310 {
311 LPWSTR p = tmp.GetBuffer();
313 link->SetIconLocation(p, idx);
314 }
315 CComPtr<IPersistFile> persist;
316 if (SUCCEEDED(hr = link->QueryInterface(IID_IPersistFile, (void**)&persist)))
317 {
318 hr = persist->Save(path, FALSE);
319 }
320 }
321 }
322 if (SUCCEEDED(hr))
323 {
324 if (AddEntry(UNOP_FILE, path))
325 {
328 }
329 }
330 else
331 {
333 }
334 return !Info.Error;
335}
#define DB_CATEGORY
Definition: appinfo.h:80
@ ENUM_CAT_GAMES
Definition: appinfo.h:30
unsigned int dir
Definition: maze.c:112
HRESULT GetSpecialPath(UINT csidl, CStringW &Path, HWND hwnd=NULL)
Definition: misc.cpp:450
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:91
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:20
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:438
PXSTR GetString() noexcept
Definition: atlsimpstr.h:367
int Replace(PCXSTR pszOld, PCXSTR pszNew)
Definition: cstringt.h:886
const WCHAR * link
Definition: db.cpp:997
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
static HRESULT GetCustomIconPath(InstallInfo &Info, CStringW &Path)
Definition: geninst.cpp:229
static BOOL GetLocalizedSMFolderName(LPCWSTR WinVal, LPCWSTR RosInf, LPCWSTR RosVal, CStringW &Output)
Definition: geninst.cpp:247
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
EXTERN_C HRESULT WINAPI SHPathPrepareForWriteW(HWND hwnd, IUnknown *modless, LPCWSTR path, DWORD flags)
Definition: shlfileop.cpp:2234
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2188
#define SHPPFW_IGNOREFILENAME
Definition: shlobj.h:341
#define SHPPFW_DIRCREATE
Definition: shlobj.h:338
#define CSIDL_PROGRAMS
Definition: shlobj.h:2168
#define PathParseIconLocation
Definition: shlwapi.h:991
BOOL PerUser
Definition: geninst.cpp:166
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by ExtractAndInstallThread().

◆ CreateUI()

static BOOL CreateUI ( BOOL  Silent,
LPTHREAD_START_ROUTINE  ThreadProc 
)
static

Definition at line 621 of file geninst.cpp.

622{
623 enum { DLGW = 150, DLGH = 20, PAD = 4, PADx2 = PAD * 2, CHILDCOUNT = 1 };
625 static const WORD DlgTmpl[] =
626 {
627 LOWORD(DlgStyle), HIWORD(DlgStyle), 0, 0, CHILDCOUNT, 0, 0, DLGW, DLGH, 0, 0, 0,
628 PBS_MARQUEE, HIWORD(WS_CHILD | WS_VISIBLE), 0, 0, PAD, PAD, DLGW - PADx2, DLGH - PADx2, 1,
629 'm', 's', 'c', 't', 'l', 's', '_', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', '3', '2', 0, 0,
630 };
633 if (!hWnd)
634 {
635 ErrorBox();
636 return FALSE;
637 }
638 else if (!Silent)
639 {
641 }
642 MSG Msg;
643 while (GetMessageW(&Msg, NULL, 0, 0))
644 {
647 }
648 return TRUE;
649}
DWORD WINAPI ThreadProc(LPVOID lpParam)
Definition: ServiceMain.c:30
HWND hWnd
Definition: settings.c:17
struct @1643 Msg[]
unsigned short WORD
Definition: ntddk_ex.h:93
static INT_PTR CALLBACK UIDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: geninst.cpp:580
#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:2198
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define HIWORD(l)
Definition: typedefs.h:247
LONG_PTR LPARAM
Definition: windef.h:208
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:775
HWND WINAPI CreateDialogIndirectParamW(_In_opt_ HINSTANCE, _In_ LPCDLGTEMPLATE, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)

Referenced by ExtractAndRunGeneratedInstaller(), and UninstallGenerated().

◆ ErrorBox()

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

Definition at line 176 of file geninst.cpp.

177{
178 if (!Error)
180 WCHAR buf[400];
183 MessageBoxW(g_pInfo->GetGuiOwner(), buf, 0, MB_OK | MB_ICONSTOP);
184 g_pInfo->Error = Error;
185 return Error;
186}
BOOL Error
Definition: chkdsk.c:66
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _countof(array)
Definition: sndvol32.h:70
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_OK
Definition: winuser.h:790
#define MB_ICONSTOP
Definition: winuser.h:803
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AddEntry(), CreateShortcut(), CreateUI(), ExtractAndInstallThread(), InstallFiles(), UIDlgProc(), UninstallThread(), and WriteArpEntry().

◆ ExtractAndInstallThread()

static DWORD CALLBACK ExtractAndInstallThread ( LPVOID  Parameter)
static

Definition at line 434 of file geninst.cpp.

435{
436 const BOOL PerUserModeDefault = TRUE;
437 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
438 LPCWSTR AppName = Info.AppName, Archive = Info.ArchivePath, None = L"!";
439 CStringW installdir, tempdir, files, shortcut, tmp;
440 HRESULT hr;
441 CRegKey arpkey;
442 Info.ArpKey = &arpkey;
443
444 if (!*GetGenerateString(DB_GENINST_FILES, files, L"*.exe|*.*"))
446
448 if (tmp.CompareNoCase(L"User") == 0)
449 Info.PerUser = TRUE;
450 else if (tmp.CompareNoCase(L"Machine") == 0)
451 Info.PerUser = FALSE;
452 else
453 Info.PerUser = PerUserModeDefault;
454
455 hr = GetProgramFilesPath(installdir, Info.PerUser, Info.GetGuiOwner());
456 if ((Info.Error = ErrorFromHResult(hr)) != 0)
457 return ErrorBox(Info.Error);
458
460 if (tmp.Find('%') == 0 && ExpandEnvStrings(tmp))
461 installdir = tmp;
462 else if (tmp.Compare(None))
463 installdir = BuildPath(installdir, tmp.IsEmpty() ? AppName : tmp.GetString());
464 Info.InstallDir = installdir.GetString();
465 Info.InstallDirLen = installdir.GetLength() + 1;
466 hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, installdir, SHPPFW_DIRCREATE);
467 if ((Info.Error = ErrorFromHResult(hr)) != 0)
468 return ErrorBox(Info.Error);
469
470 // Create the destination directory, and inside it, a temporary directory
471 // where we will extract the archive to before moving the files to their
472 // final location (adding uninstall entries as we go)
473 tempdir.Format(L"%s\\~RAM%u.tmp", installdir.GetString(), GetCurrentProcessId());
474 Info.Error = CreateDirectoryTree(tempdir.GetString());
475 if (Info.Error)
476 return ErrorBox(Info.Error);
477
478 if (!*GetGenerateString(DB_GENINST_LNK, shortcut))
479 shortcut.Format(L"%s.lnk", AppName);
480 Info.ShortcutFile = shortcut.Compare(None) ? shortcut.GetString() : NULL;
481
482 // Create the uninstall registration key
483 LPCWSTR arpkeyname = AppName;
484 tmp = BuildPath(REGPATH_UNINSTALL, arpkeyname);
487 Info.Error = arpkey.Create(hRoot, tmp, NULL, REG_OPTION_NON_VOLATILE, regsam);
488 if (!Info.Error)
489 {
491 Info.Error = Info.Entries.Create(arpkey, GENERATE_ARPSUBKEY);
492 }
493 if (Info.Error)
494 ErrorBox(Info.Error);
495
496 if (!Info.Error)
497 {
498 BOOL isCab = SplitFileAndDirectory(Archive).Right(4).CompareNoCase(L".cab") == 0;
499 Info.Error = isCab ? ExtractCab(Archive, tempdir, ExtractCallback, &Info)
500 : ExtractZip(Archive, tempdir, ExtractCallback, &Info);
501 }
502
503 if (!Info.Error)
504 {
505 // We now know how many files we extracted, change from marquee to normal progress bar.
506 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
507
508 for (int pos = 1; pos > 0 && !Info.Error;)
509 {
510 pos = files.Find(L'|');
511 CStringW item = pos <= 0 ? files : files.Left(pos);
512 files = files.Mid(pos + 1);
513 InstallFiles(tempdir, item, installdir);
514 }
515
516 if (!Info.MainApp.IsEmpty())
517 {
524
525 WriteArpEntry(L"DisplayName", AppName);
526 WriteArpEntry(L"InstallLocation", Info.InstallDir); // Note: This value is used by the uninstaller!
527
528 LPWSTR p = tmp.GetBuffer(1 + MAX_PATH);
529 p[0] = L'\"';
531 tmp.ReleaseBuffer();
532 UINT cch = tmp.GetLength(), bitness = IsSystem64Bit() ? 64 : 32;
533 WCHAR modechar = Info.PerUser ? 'U' : 'M';
534 LPCWSTR unparamsfmt = L"\" /" CMD_KEY_UNINSTALL L" /K%s \"%c%d\\%s\"";
535 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L"", modechar, bitness, arpkeyname);
536 WriteArpEntry(L"UninstallString", tmp);
537 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L" /S", modechar, bitness, arpkeyname);
538 WriteArpEntry(L"QuietUninstallString", tmp);
539
540 if (GetCustomIconPath(Info, tmp) != S_OK)
541 tmp = Info.MainApp;
542 WriteArpEntry(L"DisplayIcon", tmp);
543
544 if (*GetCommonString(DB_VERSION, tmp))
545 WriteArpEntry(L"DisplayVersion", tmp);
546
547 SYSTEMTIME st;
548 GetSystemTime(&st);
549 tmp.Format(L"%.4u%.2u%.2u", st.wYear, st.wMonth, st.wDay);
550 WriteArpEntry(L"InstallDate", tmp);
551
552 if (*GetCommonString(DB_PUBLISHER, tmp))
553 WriteArpEntry(L"Publisher", tmp);
554
555#if DBG
556 tmp.Format(L"sys64=%d rapps%d", IsSystem64Bit(), sizeof(void*) * 8);
557 WriteArpEntry(L"_DEBUG", tmp);
558#endif
559 }
560
561 if (!Info.Error && Info.ShortcutFile)
562 {
563 CreateShortcut(Info.MainApp);
564 }
565 }
566
568 RemoveDirectory(installdir.GetString()); // This is harmless even if we installed something
569 return 0;
570}
#define DB_PUBLISHER
Definition: appinfo.h:81
#define GENERATE_ARPSUBKEY
Definition: appinfo.h:87
#define DB_VERSION
Definition: appinfo.h:79
#define DB_SCOPE
Definition: appinfo.h:84
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:392
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:418
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:431
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:474
BOOL IsSystem64Bit()
Definition: misc.cpp:287
@ 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
CStringT Right(int nCount) const
Definition: cstringt.h:788
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:327
unsigned int BOOL
Definition: ntddk_ex.h:94
#define DB_GENINST_DIR
Definition: geninst.cpp:32
#define DB_GENINST_FILES
Definition: geninst.cpp:31
static BOOL CreateShortcut(const CStringW &Target)
Definition: geninst.cpp:272
#define DB_GENINST_DELREG
Definition: geninst.cpp:38
static UINT ExtractCab(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: geninst.cpp:134
#define DB_GENINST_DELDIR
Definition: geninst.cpp:36
static void AddUninstallOperationsFromDB(LPCWSTR Name, WCHAR UnOp, CStringW PathPrefix=CStringW(L""))
Definition: geninst.cpp:410
#define DB_GENINST_DELDIREMPTY
Definition: geninst.cpp:37
#define DB_GENINST_LNK
Definition: geninst.cpp:34
#define REGPATH_UNINSTALL
Definition: geninst.cpp:29
static BOOL CALLBACK ExtractCallback(const EXTRACTCALLBACKINFO &, void *Cookie)
Definition: geninst.cpp:426
#define DB_GENINST_DELFILE
Definition: geninst.cpp:35
static BOOL InstallFiles(const CStringW &SourceDirBase, const CStringW &Spec, const CStringW &DestinationDir)
Definition: geninst.cpp:338
#define DB_GENINST_DELREGEMPTY
Definition: geninst.cpp:39
static void WriteArpEntry(LPCWSTR Name, LPCWSTR Value, UINT Type=REG_SZ)
Definition: geninst.cpp:205
static LPCWSTR GetCommonString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:189
static UINT ExtractZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: geninst.cpp:126
#define S_OK
Definition: intsafe.h:52
static HTREEITEM hRoot
Definition: treeview.c:381
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
@ Archive
Definition: scrrun.idl:75
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
WORD wYear
Definition: winbase.h:905
WORD wMonth
Definition: winbase.h:906
WORD wDay
Definition: winbase.h:908
#define CMD_KEY_UNINSTALL
Definition: unattended.h:5
#define RemoveDirectory
Definition: winbase.h:3895
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define GetModuleFileName
Definition: winbase.h:3831
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
ACCESS_MASK REGSAM
Definition: winreg.h:69
#define SendMessage
Definition: winuser.h:5852
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ExtractAndRunGeneratedInstaller().

◆ ExtractAndRunGeneratedInstaller()

BOOL ExtractAndRunGeneratedInstaller ( const CAvailableApplicationInfo AppInfo,
LPCWSTR  Archive 
)

Definition at line 652 of file geninst.cpp.

653{
654 InstallInfo Info(AppInfo.szDisplayName, *AppInfo.GetConfigParser(), Archive);
655 g_pInfo = &Info;
656 return CreateUI(Info.Silent, ExtractAndInstallThread) ? !Info.Error : FALSE;
657}
CStringW szDisplayName
Definition: appinfo.h:102
CConfigParser * GetConfigParser() const
Definition: appinfo.h:155
static DWORD CALLBACK ExtractAndInstallThread(LPVOID Parameter)
Definition: geninst.cpp:434
static BOOL CreateUI(BOOL Silent, LPTHREAD_START_ROUTINE ThreadProc)
Definition: geninst.cpp:621

Referenced by HandleGenerateInstallerCommand().

◆ ExtractCab()

static UINT ExtractCab ( LPCWSTR  Archive,
const CStringW OutputDir,
EXTRACTCALLBACK  Callback,
void Cookie 
)
static

Definition at line 134 of file geninst.cpp.

136{
137 if (ExtractFilesFromCab(Archive, OutputDir, Callback, Cookie))
138 return ERROR_SUCCESS;
140 return err ? err : ERROR_INTERNAL_ERROR;
141}
BOOL ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: cabinet.cpp:249
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14

Referenced by ExtractAndInstallThread().

◆ ExtractCallback()

static BOOL CALLBACK ExtractCallback ( const EXTRACTCALLBACKINFO ,
void Cookie 
)
static

Definition at line 426 of file geninst.cpp.

427{
429 Info.Count += 1;
430 return TRUE;
431}

Referenced by ExtractAndInstallThread().

◆ ExtractFilesFromZip()

static int ExtractFilesFromZip ( LPCWSTR  Archive,
const CStringW OutputDir,
EXTRACTCALLBACK  Callback,
void Cookie 
)
static

Definition at line 50 of file geninst.cpp.

52{
53 const UINT pkzefsutf8 = 1 << 11; // APPNOTE; APPENDIX D
56 unzFile hzf = unzOpen2_64(Archive, &zff);
57 if (!hzf)
58 return UNZ_BADZIPFILE;
59 CStringA narrow;
61 int zerr = unzGoToFirstFile(hzf);
62 for (; zerr == UNZ_OK; zerr = unzGoToNextFile(hzf))
63 {
65 zerr = unzGetCurrentFileInfo64(hzf, &fi, NULL, 0, NULL, 0, NULL, 0);
66 if (zerr != UNZ_OK)
67 break;
68 LPSTR file = narrow.GetBuffer(fi.size_filename);
69 zerr = unzGetCurrentFileInfo64(hzf, &fi, file, narrow.GetAllocLength(), NULL, 0, NULL, 0);
70 if (zerr != UNZ_OK)
71 break;
73 narrow.Replace('/', '\\');
74 while (narrow[0] == '\\')
75 narrow = narrow.Mid(1);
76 UINT codepage = (fi.flag & pkzefsutf8) ? CP_UTF8 : 1252;
77 UINT cch = MultiByteToWideChar(codepage, 0, narrow, -1, NULL, 0);
78 cch = MultiByteToWideChar(codepage, 0, narrow, -1, path.GetBuffer(cch - 1), cch);
79 if (!cch)
80 break;
81 path.ReleaseBuffer(cch - 1);
83 BYTE attsys = HIBYTE(fi.version), dos = 0, ntfs = 10, vfat = 14;
84 if ((attsys == dos || attsys == ntfs || attsys == vfat) && LOBYTE(fi.external_fa))
85 fileatt = LOBYTE(fi.external_fa);
86
89 continue; // Skip file
90
91 path = BuildPath(OutputDir, path);
93 if (!dir.IsEmpty() && (err = CreateDirectoryTree(dir)))
94 {
95 zerr = UNZ_ERRNO;
97 break;
98 }
99
100 if ((zerr = unzOpenCurrentFile(hzf)) != UNZ_OK)
101 break;
102 zerr = UNZ_ERRNO;
105 NULL, CREATE_ALWAYS, fileatt, NULL);
107 {
108 DWORD len = 1024 * 4, cb;
109 LPSTR buf = narrow.GetBuffer(len);
110 for (zerr = UNZ_OK; zerr == UNZ_OK;)
111 {
112 len = zerr = unzReadCurrentFile(hzf, buf, len);
113 if (zerr <= 0)
114 break;
115 zerr = WriteFile(hFile, buf, len, &cb, NULL) && cb == len ? UNZ_OK : UNZ_ERRNO;
116 }
118 }
120 }
121 unzClose(hzf);
122 return zerr == UNZ_END_OF_LIST_OF_FILE ? UNZ_OK : zerr;
123}
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:56
int GetAllocLength() const noexcept
Definition: atlsimpstr.h:357
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#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 LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: iowin32.c:457
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define CREATE_ALWAYS
Definition: disk.h:72
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
IMAGE_DOS_HEADER dos
Definition: module.c:49
_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:127
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
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
char * LPSTR
Definition: xmlstorage.h:182
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ExtractZip().

◆ ExtractZip()

static UINT ExtractZip ( LPCWSTR  Archive,
const CStringW OutputDir,
EXTRACTCALLBACK  Callback,
void Cookie 
)
static

Definition at line 126 of file geninst.cpp.

128{
129 int zerr = ExtractFilesFromZip(Archive, OutputDir, Callback, Cookie);
130 return zerr == UNZ_ERRNO ? GetLastError() : zerr ? ERROR_INTERNAL_ERROR : 0;
131}
static int ExtractFilesFromZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: geninst.cpp:50

Referenced by ExtractAndInstallThread().

◆ GetCommonString()

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

Definition at line 189 of file geninst.cpp.

190{
191 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
193 return (found && !Output.IsEmpty() ? Output : Output = Default).GetString();
194}
BOOL GetString(const CStringW &KeyName, CStringW &ResultString)
@ Default
Definition: stdole2.idl:392
@ Output
Definition: arc.h:85
CConfigParser & Parser
Definition: geninst.cpp:162

Referenced by ExtractAndInstallThread().

◆ GetCustomIconPath()

static HRESULT GetCustomIconPath ( InstallInfo Info,
CStringW Path 
)
static

Definition at line 229 of file geninst.cpp.

230{
232 {
233 Path = BuildPath(Info.InstallDir, Path);
234 int idx = PathParseIconLocation(Path.GetBuffer());
235 Path.ReleaseBuffer();
236 HICON hIco = NULL;
237 if (ExtractIconExW(Path, idx, &hIco, NULL, 1))
238 DestroyIcon(hIco);
239 if (idx)
240 Path.AppendFormat(L",%d", idx);
241 return hIco ? S_OK : S_FALSE;
242 }
244}
PRTL_UNICODE_STRING_BUFFER Path
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define DB_GENINST_ICON
Definition: geninst.cpp:33
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
static HICON
Definition: imagelist.c:84
#define S_FALSE
Definition: winerror.h:2357
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2084

Referenced by CreateShortcut(), and ExtractAndInstallThread().

◆ GetGenerateString()

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

Definition at line 197 of file geninst.cpp.

198{
199 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
201 return (r ? Output : Output = Default).GetString();
202}
#define DB_GENINSTSECTION
Definition: appinfo.h:86
UINT GetSectionString(LPCWSTR Section, LPCWSTR Name, CStringW &Result)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

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

◆ GetLocalizedSMFolderName()

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

Definition at line 247 of file geninst.cpp.

248{
249 CRegKey key;
250 if (key.Open(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", KEY_READ) == ERROR_SUCCESS &&
251 GetRegString(key, WinVal, Output) && !Output.IsEmpty())
252 {
253 return TRUE;
254 }
255 WCHAR windir[MAX_PATH];
256 GetWindowsDirectoryW(windir, _countof(windir));
257 CStringW path = BuildPath(BuildPath(windir, L"inf"), RosInf), section;
258 DWORD lang = 0, lctype = LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER;
259 if (GetLocaleInfoW(GetUserDefaultLCID(), lctype, (LPWSTR) &lang, sizeof(lang) / sizeof(WCHAR)))
260 {
261 section.Format(L"Strings.%.4x", lang);
262 if (ReadIniValue(path, section, RosVal, Output) > 0)
263 return TRUE;
264 section.Format(L"Strings.%.2x", PRIMARYLANGID(lang));
265 if (ReadIniValue(path, section, RosVal, Output) > 0)
266 return TRUE;
267 }
268 return ReadIniValue(path, L"Strings", RosVal, Output) > 0;
269}
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:369
HRESULT ReadIniValue(LPCWSTR File, LPCWSTR Section, LPCWSTR Name, CStringW &Output)
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
LCID WINAPI GetUserDefaultLCID(void)
Definition: locale.c:1210
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1665
#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:25

Referenced by CreateShortcut().

◆ InstallFiles()

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

Definition at line 338 of file geninst.cpp.

340{
341 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
342 CStringW sourcedir, filespec;
343 filespec = SplitFileAndDirectory(Spec, &sourcedir); // Split "[OptionalDir\]*.ext"
344 sourcedir = BuildPath(SourceDirBase, sourcedir);
345 BOOL success = TRUE;
347 HANDLE hFind = FindFirstFileW(BuildPath(sourcedir, filespec), &wfd);
348 if (hFind == INVALID_HANDLE_VALUE)
349 {
352 return TRUE;
353 else
354 return !ErrorBox(error);
355 }
356
357 for (;;)
358 {
359 CStringW from = BuildPath(sourcedir, wfd.cFileName);
360 CStringW to = BuildPath(DestinationDir, wfd.cFileName);
361 CStringW uninstpath = to.Mid(Info.InstallDirLen - 1);
362 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
363 {
364 LPWSTR p = wfd.cFileName;
365 BOOL dots = p[0] == '.' && (!p[1] || (p[1] == '.' && !p[2]));
366 if (!dots)
367 {
368 Info.Error = CreateDirectoryTree(to);
369 if (Info.Error)
370 {
371 success = !ErrorBox(Info.Error);
372 }
373 else
374 {
375 success = AddEntry(UNOP_EMPTYDIR, uninstpath);
376 }
377
378 if (success)
379 {
380 success = InstallFiles(from, filespec, to);
381 }
382 }
383 }
384 else
385 {
387 if (success)
388 {
389 if (Info.MainApp.IsEmpty())
390 {
391 Info.MainApp = to;
392 }
393 success = AddEntry(UNOP_FILE, uninstpath);
394 }
395 else
396 {
397 ErrorBox();
398 }
399 SendMessage(g_pInfo->hDlg, IM_PROGRESS, 0, 0);
400 }
401
402 if (!success || !FindNextFileW(hFind, &wfd))
403 break;
404 }
405 FindClose(hFind);
406 return success;
407}
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
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
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
CardRegion * from
Definition: spigame.cpp:19
#define success(from, fromstr, to, tostr)
#define MoveFileEx
Definition: winbase.h:3878

Referenced by ExtractAndInstallThread(), and InstallFiles().

◆ UIDlgProc()

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

Definition at line 580 of file geninst.cpp.

581{
582 HWND hPB = GetDlgItem(hDlg, 1);
583 switch(uMsg)
584 {
585 case IM_STARTPROGRESS:
588 SendMessageW(hPB, PBM_SETRANGE32, 0, g_pInfo->Count);
589 SendMessageW(hPB, PBM_SETPOS, 0, 0);
590 break;
591 case IM_PROGRESS:
592 SendMessageW(hPB, PBM_DELTAPOS, 1, 0);
593 break;
594 case IM_END:
595 DestroyWindow(hDlg);
596 break;
597 case WM_INITDIALOG:
598 {
600 g_pInfo->hDlg = hDlg;
602 SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIco);
603 SendMessageW(hDlg, WM_SETTEXT, 0, (LPARAM)g_pInfo->AppName);
605 {
606 ErrorBox();
607 SendMessageW(hDlg, IM_END, 0, 0);
608 }
609 break;
610 }
611 case WM_CLOSE:
612 return TRUE;
613 case WM_DESTROY:
614 PostMessage(NULL, WM_QUIT, 0, 0);
615 break;
616 }
617 return FALSE;
618}
#define IDI_MAIN
Definition: resource.h:4
LPARAM lParam
Definition: combotst.c:139
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE pfnThreadProc, VOID *pData, DWORD dwFlags, LPTHREAD_START_ROUTINE pfnCallback)
Definition: thread.c:356
HINSTANCE hInst
Definition: dxdiag.c:13
static DWORD CALLBACK WorkerThread(LPVOID Parameter)
Definition: geninst.cpp:573
#define PBM_SETRANGE32
Definition: commctrl.h:2188
#define PBM_DELTAPOS
Definition: commctrl.h:2185
#define PBM_SETPOS
Definition: commctrl.h:2184
#define PBM_SETMARQUEE
Definition: commctrl.h:2199
#define CTF_COINIT
Definition: shlwapi.h:1936
#define ICON_BIG
Definition: tnclass.cpp:51
#define SetWindowLongPtr
Definition: treelist.c:70
#define WM_CLOSE
Definition: winuser.h:1621
#define WM_QUIT
Definition: winuser.h:1623
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SETTEXT
Definition: winuser.h:1617
#define PostMessage
Definition: winuser.h:5841
#define WM_DESTROY
Definition: winuser.h:1609
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GWL_STYLE
Definition: winuser.h:852
BOOL WINAPI DestroyWindow(_In_ HWND)
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2106
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by CreateUI().

◆ UninstallGenerated()

BOOL UninstallGenerated ( CInstalledApplicationInfo AppInfo,
UninstallCommandFlags  Flags 
)

Definition at line 812 of file geninst.cpp.

813{
815 g_pInfo = &Info;
816 return CreateUI(Info.Silent, UninstallThread) ? !Info.Error : FALSE;
817}
@ UCF_SILENT
Definition: appinfo.h:70
static DWORD CALLBACK UninstallThread(LPVOID Parameter)
Definition: geninst.cpp:677
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by CInstalledApplicationInfo::UninstallApplication().

◆ UninstallThread()

static DWORD CALLBACK UninstallThread ( LPVOID  Parameter)
static

Definition at line 677 of file geninst.cpp.

678{
679 UninstallInfo &Info = *static_cast<UninstallInfo *>(g_pInfo);
680
681 CStringW tmp, path, installdir;
683 tmp.Format(path.GetString(), Info.AppName);
684 if (!Info.Silent &&
685 MessageBox(Info.GetGuiOwner(), tmp, Info.AppName, MB_YESNO | MB_ICONQUESTION) != IDYES)
686 {
687 Info.Error = ERROR_CANCELLED;
688 SendMessage(Info.hDlg, IM_END, 0, 0);
689 return 0;
690 }
691
692 Info.Error = Info.Entries.Open(*Info.ArpKey, GENERATE_ARPSUBKEY, KEY_READ);
693 if (Info.Error)
694 return ErrorBox(Info.Error);
695
696 RegQueryInfoKey(Info.Entries, NULL, NULL, NULL, NULL, NULL, NULL, &Info.Count, NULL, NULL, NULL, NULL);
697 Info.Count *= UINSTALLSTAGECOUNT;
698 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
699
700 if (!GetRegString(*Info.ArpKey, L"InstallLocation", installdir) || installdir.IsEmpty())
702
703 for (UINT stage = 0; stage < UINSTALLSTAGECOUNT; ++stage)
704 {
705 for (UINT vi = 0;; ++vi)
706 {
708 DWORD valsize = _countof(value), size = sizeof(data) - sizeof(WCHAR), rt;
710 UINT err = RegEnumValue(Info.Entries, vi, value, &valsize, NULL, &rt, (BYTE*)data, &size);
711 if (err)
712 {
714 {
715 return ErrorBox(err);
716 }
717 break;
718 }
719
720 LPCWSTR str = data;
721 WORD op = value[0];
722 switch(*data ? MAKEWORD(stage, op) : 0)
723 {
726 {
727 REGSAM wowsam = 0;
728 HKEY hKey = NULL;
729 path.Format(L"%.4s", data);
730 if (path.CompareNoCase(L"HKCR") == 0)
732 else if (path.CompareNoCase(L"HKCU") == 0)
734 else if (path.CompareNoCase(L"HKLM") == 0)
736
737 if (data[4] == '6' && data[5] == '4')
738 wowsam = KEY_WOW64_64KEY;
739 else if (data[4] == '3' && data[5] == '2')
740 wowsam = KEY_WOW64_32KEY;
741
742 str = &data[wowsam ? 6 : 4];
743 if (!hKey || *str != L'\\')
744 break;
745 tmp = SplitFileAndDirectory(++str, &path);
746 if (!tmp.IsEmpty() && !path.IsEmpty())
747 {
748 CRegKey key;
749 err = key.Open(hKey, path, DELETE | wowsam);
750 if (err == ERROR_SUCCESS)
751 {
752 if (op == UNOP_REGKEY)
753 err = key.RecurseDeleteKey(tmp);
754 else if (RegKeyHasValues(hKey, str, wowsam) == S_FALSE)
755 key.DeleteSubKey(tmp); // DelRegEmpty ignores errors
756 }
757 switch(err)
758 {
759 case ERROR_SUCCESS:
762 break;
763 default:
764 return ErrorBox(err);
765 }
766 }
767 break;
768 }
769
771 {
772 if (*data == L'\\')
773 str = (path = BuildPath(installdir, data));
774
775 if (!DeleteFile(str))
776 {
777 err = GetLastError();
779 {
780 return ErrorBox(err);
781 }
782 }
783 break;
784 }
785
788 {
789 if (*data == L'\\')
790 str = (path = BuildPath(installdir, data));
791
792 if (op == UNOP_DIR)
793 DeleteDirectoryTree(str, Info.GetGuiOwner());
794 else
796 break;
797 }
798 }
799 SendMessage(Info.hDlg, IM_PROGRESS, 0, 0);
800 }
801 }
802 if (!Info.Error)
803 {
805 if (Info.Error)
806 return ErrorBox(Info.Error);
807 }
808 return 0;
809}
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:351
#define IDS_INSTGEN_CONFIRMUNINST
Definition: resource.h:232
static DWORD RemoveInstalledAppFromRegistry(const CAppInfo *Info)
Definition: appdb.cpp:315
UINT op
Definition: effect.c:236
#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
const WCHAR * str
#define MAKEWORD(a, b)
Definition: typedefs.h:248
Definition: pdh_main.c:94
#define DeleteFile
Definition: winbase.h:3764
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_CANCELLED
Definition: winerror.h:726
#define RegEnumValue
Definition: winreg.h:511
#define RegQueryInfoKey
Definition: winreg.h:521
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define MB_YESNO
Definition: winuser.h:817
#define MB_ICONQUESTION
Definition: winuser.h:789
#define MessageBox
Definition: winuser.h:5831
#define IDYES
Definition: winuser.h:835

Referenced by UninstallGenerated().

◆ WorkerThread()

static DWORD CALLBACK WorkerThread ( LPVOID  Parameter)
static

Definition at line 573 of file geninst.cpp.

574{
576 return SendMessage(g_pInfo->hDlg, IM_END, 0, 0);
577}
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:729
_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 205 of file geninst.cpp.

206{
207 // Write a "Add/Remove programs" value if we have a valid uninstaller key
208 if (g_pInfo->ArpKey)
209 {
210 UINT err = g_pInfo->ArpKey->SetStringValue(Name, Value, Type);
211 if (err)
212 ErrorBox(err);
213 }
214}

Referenced by ExtractAndInstallThread().

Variable Documentation

◆ g_pInfo