ReactOS 0.4.16-dev-87-g3dfbe52
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 666 of file geninst.cpp.

667{
668 US_ITEMS,
671};
@ UINSTALLSTAGECOUNT
Definition: geninst.cpp:670
@ US_CONTAINERS
Definition: geninst.cpp:669
@ US_ITEMS
Definition: geninst.cpp:668

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 407 of file geninst.cpp.

408{
409 CStringW item, tmp;
410 if (*GetGenerateString(Name, tmp))
411 {
412 for (int pos = 1; pos > 0;)
413 {
414 pos = tmp.Find(L'|');
415 item = pos <= 0 ? tmp : tmp.Left(pos);
416 tmp = tmp.Mid(pos + 1);
417 AddEntry(UnOp, PathPrefix + item);
418 }
419 }
420}
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:478
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:93
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:20
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:466
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:2235
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2195
#define SHPPFW_IGNOREFILENAME
Definition: shlobj.h:341
#define SHPPFW_DIRCREATE
Definition: shlobj.h:338
#define CSIDL_PROGRAMS
Definition: shlobj.h:2175
#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 618 of file geninst.cpp.

619{
620 enum { DLGW = 150, DLGH = 20, PAD = 4, PADx2 = PAD * 2, CHILDCOUNT = 1 };
622 static const WORD DlgTmpl[] =
623 {
624 LOWORD(DlgStyle), HIWORD(DlgStyle), 0, 0, CHILDCOUNT, 0, 0, DLGW, DLGH, 0, 0, 0,
625 PBS_MARQUEE, HIWORD(WS_CHILD | WS_VISIBLE), 0, 0, PAD, PAD, DLGW - PADx2, DLGH - PADx2, 1,
626 'm', 's', 'c', 't', 'l', 's', '_', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', '3', '2', 0, 0,
627 };
630 if (!hWnd)
631 {
632 ErrorBox();
633 return FALSE;
634 }
635 else if (!Silent)
636 {
638 }
639 MSG Msg;
640 while (GetMessageW(&Msg, NULL, 0, 0))
641 {
644 }
645 return TRUE;
646}
DWORD WINAPI ThreadProc(LPVOID lpParam)
Definition: ServiceMain.c:30
HWND hWnd
Definition: settings.c:17
struct @1636 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:577
#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
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:778
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:793
#define MB_ICONSTOP
Definition: winuser.h:806
__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 431 of file geninst.cpp.

432{
433 const BOOL PerUserModeDefault = TRUE;
434 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
435 LPCWSTR AppName = Info.AppName, Archive = Info.ArchivePath, None = L"!";
436 CStringW installdir, tempdir, files, shortcut, tmp;
437 HRESULT hr;
438 CRegKey arpkey;
439 Info.ArpKey = &arpkey;
440
441 if (!*GetGenerateString(DB_GENINST_FILES, files, L"*.exe|*.*"))
443
445 if (tmp.CompareNoCase(L"User") == 0)
446 Info.PerUser = TRUE;
447 else if (tmp.CompareNoCase(L"Machine") == 0)
448 Info.PerUser = FALSE;
449 else
450 Info.PerUser = PerUserModeDefault;
451
452 hr = GetProgramFilesPath(installdir, Info.PerUser, Info.GetGuiOwner());
453 if ((Info.Error = ErrorFromHResult(hr)) != 0)
454 return ErrorBox(Info.Error);
455
457 if (tmp.Find('%') == 0 && ExpandEnvStrings(tmp))
458 installdir = tmp;
459 else if (tmp.Compare(None))
460 installdir = BuildPath(installdir, tmp.IsEmpty() ? AppName : tmp.GetString());
461 Info.InstallDir = installdir.GetString();
462 Info.InstallDirLen = installdir.GetLength() + 1;
463 hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, installdir, SHPPFW_DIRCREATE);
464 if ((Info.Error = ErrorFromHResult(hr)) != 0)
465 return ErrorBox(Info.Error);
466
467 // Create the destination directory, and inside it, a temporary directory
468 // where we will extract the archive to before moving the files to their
469 // final location (adding uninstall entries as we go)
470 tempdir.Format(L"%s\\~RAM%u.tmp", installdir.GetString(), GetCurrentProcessId());
471 Info.Error = CreateDirectoryTree(tempdir.GetString());
472 if (Info.Error)
473 return ErrorBox(Info.Error);
474
475 if (!*GetGenerateString(DB_GENINST_LNK, shortcut))
476 shortcut.Format(L"%s.lnk", AppName);
477 Info.ShortcutFile = shortcut.Compare(None) ? shortcut.GetString() : NULL;
478
479 // Create the uninstall registration key
480 LPCWSTR arpkeyname = AppName;
481 tmp = BuildPath(REGPATH_UNINSTALL, arpkeyname);
484 Info.Error = arpkey.Create(hRoot, tmp, NULL, REG_OPTION_NON_VOLATILE, regsam);
485 if (!Info.Error)
486 {
488 Info.Error = Info.Entries.Create(arpkey, GENERATE_ARPSUBKEY);
489 }
490 if (Info.Error)
491 ErrorBox(Info.Error);
492
493 if (!Info.Error)
494 {
495 BOOL isCab = SplitFileAndDirectory(Archive).Right(4).CompareNoCase(L".cab") == 0;
496 Info.Error = isCab ? ExtractCab(Archive, tempdir, ExtractCallback, &Info)
497 : ExtractZip(Archive, tempdir, ExtractCallback, &Info);
498 }
499
500 if (!Info.Error)
501 {
502 // We now know how many files we extracted, change from marquee to normal progress bar.
503 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
504
505 for (int pos = 1; pos > 0 && !Info.Error;)
506 {
507 pos = files.Find(L'|');
508 CStringW item = pos <= 0 ? files : files.Left(pos);
509 files = files.Mid(pos + 1);
510 InstallFiles(tempdir, item, installdir);
511 }
512
513 if (!Info.MainApp.IsEmpty())
514 {
521
522 WriteArpEntry(L"DisplayName", AppName);
523 WriteArpEntry(L"InstallLocation", Info.InstallDir); // Note: This value is used by the uninstaller!
524
525 LPWSTR p = tmp.GetBuffer(1 + MAX_PATH);
526 p[0] = L'\"';
528 tmp.ReleaseBuffer();
529 UINT cch = tmp.GetLength(), bitness = IsSystem64Bit() ? 64 : 32;
530 WCHAR modechar = Info.PerUser ? 'U' : 'M';
531 LPCWSTR unparamsfmt = L"\" /" CMD_KEY_UNINSTALL L" /K%s \"%c%d\\%s\"";
532 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L"", modechar, bitness, arpkeyname);
533 WriteArpEntry(L"UninstallString", tmp);
534 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L" /S", modechar, bitness, arpkeyname);
535 WriteArpEntry(L"QuietUninstallString", tmp);
536
537 if (GetCustomIconPath(Info, tmp) != S_OK)
538 tmp = Info.MainApp;
539 WriteArpEntry(L"DisplayIcon", tmp);
540
541 if (*GetCommonString(DB_VERSION, tmp))
542 WriteArpEntry(L"DisplayVersion", tmp);
543
544 SYSTEMTIME st;
545 GetSystemTime(&st);
546 tmp.Format(L"%.4u%.2u%.2u", st.wYear, st.wMonth, st.wDay);
547 WriteArpEntry(L"InstallDate", tmp);
548
549 if (*GetCommonString(DB_PUBLISHER, tmp))
550 WriteArpEntry(L"Publisher", tmp);
551
552#if DBG
553 tmp.Format(L"sys64=%d rapps%d", IsSystem64Bit(), sizeof(void*) * 8);
554 WriteArpEntry(L"_DEBUG", tmp);
555#endif
556 }
557
558 if (!Info.Error && Info.ShortcutFile)
559 {
560 CreateShortcut(Info.MainApp);
561 }
562 }
563
565 RemoveDirectory(installdir.GetString()); // This is harmless even if we installed something
566 return 0;
567}
#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:420
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:446
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:459
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:502
BOOL IsSystem64Bit()
Definition: misc.cpp:315
@ 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:407
#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:423
#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:383
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:5855
#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 649 of file geninst.cpp.

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

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:250
#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 423 of file geninst.cpp.

424{
426 Info.Count += 1;
427 return TRUE;
428}

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:58
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:80
#define S_FALSE
Definition: winerror.h:2357
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2097

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:397
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
374 if (success)
375 {
376 success = InstallFiles(from, filespec, to);
377 }
378 AddEntry(UNOP_EMPTYDIR, uninstpath);
379 }
380 }
381 else
382 {
384 if (success)
385 {
386 if (Info.MainApp.IsEmpty())
387 {
388 Info.MainApp = to;
389 }
390 success = AddEntry(UNOP_FILE, uninstpath);
391 }
392 else
393 {
394 ErrorBox();
395 }
396 SendMessage(g_pInfo->hDlg, IM_PROGRESS, 0, 0);
397 }
398
399 if (!success || !FindNextFileW(hFind, &wfd))
400 break;
401 }
402 FindClose(hFind);
403 return success;
404}
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 577 of file geninst.cpp.

578{
579 HWND hPB = GetDlgItem(hDlg, 1);
580 switch(uMsg)
581 {
582 case IM_STARTPROGRESS:
585 SendMessageW(hPB, PBM_SETRANGE32, 0, g_pInfo->Count);
586 SendMessageW(hPB, PBM_SETPOS, 0, 0);
587 break;
588 case IM_PROGRESS:
589 SendMessageW(hPB, PBM_DELTAPOS, 1, 0);
590 break;
591 case IM_END:
592 DestroyWindow(hDlg);
593 break;
594 case WM_INITDIALOG:
595 {
597 g_pInfo->hDlg = hDlg;
599 SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIco);
600 SendMessageW(hDlg, WM_SETTEXT, 0, (LPARAM)g_pInfo->AppName);
602 {
603 ErrorBox();
604 SendMessageW(hDlg, IM_END, 0, 0);
605 }
606 break;
607 }
608 case WM_CLOSE:
609 return TRUE;
610 case WM_DESTROY:
611 PostMessage(NULL, WM_QUIT, 0, 0);
612 break;
613 }
614 return FALSE;
615}
#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:570
#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
#define CTF_COINIT
Definition: shlwapi.h:1938
#define ICON_BIG
Definition: tnclass.cpp:51
#define SetWindowLongPtr
Definition: treelist.c:70
#define WM_CLOSE
Definition: winuser.h:1624
#define WM_QUIT
Definition: winuser.h:1626
#define WM_INITDIALOG
Definition: winuser.h:1742
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SETTEXT
Definition: winuser.h:1620
#define PostMessage
Definition: winuser.h:5844
#define WM_DESTROY
Definition: winuser.h:1612
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GWL_STYLE
Definition: winuser.h:855
BOOL WINAPI DestroyWindow(_In_ HWND)
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2119
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by CreateUI().

◆ UninstallGenerated()

BOOL UninstallGenerated ( CInstalledApplicationInfo AppInfo,
UninstallCommandFlags  Flags 
)

Definition at line 809 of file geninst.cpp.

810{
812 g_pInfo = &Info;
813 return CreateUI(Info.Silent, UninstallThread) ? !Info.Error : FALSE;
814}
@ UCF_SILENT
Definition: appinfo.h:70
static DWORD CALLBACK UninstallThread(LPVOID Parameter)
Definition: geninst.cpp:674
_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 674 of file geninst.cpp.

675{
676 UninstallInfo &Info = *static_cast<UninstallInfo *>(g_pInfo);
677
678 CStringW tmp, path, installdir;
680 tmp.Format(path.GetString(), Info.AppName);
681 if (!Info.Silent &&
682 MessageBox(Info.GetGuiOwner(), tmp, Info.AppName, MB_YESNO | MB_ICONQUESTION) != IDYES)
683 {
684 Info.Error = ERROR_CANCELLED;
685 SendMessage(Info.hDlg, IM_END, 0, 0);
686 return 0;
687 }
688
689 Info.Error = Info.Entries.Open(*Info.ArpKey, GENERATE_ARPSUBKEY, KEY_READ);
690 if (Info.Error)
691 return ErrorBox(Info.Error);
692
693 RegQueryInfoKey(Info.Entries, NULL, NULL, NULL, NULL, NULL, NULL, &Info.Count, NULL, NULL, NULL, NULL);
694 Info.Count *= UINSTALLSTAGECOUNT;
695 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
696
697 if (!GetRegString(*Info.ArpKey, L"InstallLocation", installdir) || installdir.IsEmpty())
699
700 for (UINT stage = 0; stage < UINSTALLSTAGECOUNT; ++stage)
701 {
702 for (UINT vi = 0;; ++vi)
703 {
705 DWORD valsize = _countof(value), size = sizeof(data) - sizeof(WCHAR), rt;
707 UINT err = RegEnumValue(Info.Entries, vi, value, &valsize, NULL, &rt, (BYTE*)data, &size);
708 if (err)
709 {
711 {
712 return ErrorBox(err);
713 }
714 break;
715 }
716
717 LPCWSTR str = data;
718 WORD op = value[0];
719 switch(*data ? MAKEWORD(stage, op) : 0)
720 {
723 {
724 REGSAM wowsam = 0;
725 HKEY hKey = NULL;
726 path.Format(L"%.4s", data);
727 if (path.CompareNoCase(L"HKCR") == 0)
729 else if (path.CompareNoCase(L"HKCU") == 0)
731 else if (path.CompareNoCase(L"HKLM") == 0)
733
734 if (data[4] == '6' && data[5] == '4')
735 wowsam = KEY_WOW64_64KEY;
736 else if (data[4] == '3' && data[5] == '2')
737 wowsam = KEY_WOW64_32KEY;
738
739 str = &data[wowsam ? 6 : 4];
740 if (!hKey || *str != L'\\')
741 break;
742 tmp = SplitFileAndDirectory(++str, &path);
743 if (!tmp.IsEmpty() && !path.IsEmpty())
744 {
745 CRegKey key;
746 err = key.Open(hKey, path, DELETE | wowsam);
747 if (err == ERROR_SUCCESS)
748 {
749 if (op == UNOP_REGKEY)
750 err = key.RecurseDeleteKey(tmp);
751 else if (RegKeyHasValues(hKey, str, wowsam) == S_FALSE)
752 key.DeleteSubKey(tmp); // DelRegEmpty ignores errors
753 }
754 switch(err)
755 {
756 case ERROR_SUCCESS:
759 break;
760 default:
761 return ErrorBox(err);
762 }
763 }
764 break;
765 }
766
768 {
769 if (*data == L'\\')
770 str = (path = BuildPath(installdir, data));
771
772 if (!DeleteFile(str))
773 {
774 err = GetLastError();
776 {
777 return ErrorBox(err);
778 }
779 }
780 break;
781 }
782
785 {
786 if (*data == L'\\')
787 str = (path = BuildPath(installdir, data));
788
789 if (op == UNOP_DIR)
790 DeleteDirectoryTree(str, Info.GetGuiOwner());
791 else
793 break;
794 }
795 }
796 SendMessage(Info.hDlg, IM_PROGRESS, 0, 0);
797 }
798 }
799 if (!Info.Error)
800 {
802 if (Info.Error)
803 return ErrorBox(Info.Error);
804 }
805 return 0;
806}
HRESULT RegKeyHasValues(HKEY hKey, LPCWSTR Path, REGSAM wowsam=0)
Definition: misc.cpp:379
#define IDS_INSTGEN_CONFIRMUNINST
Definition: resource.h:237
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:820
#define MB_ICONQUESTION
Definition: winuser.h:792
#define MessageBox
Definition: winuser.h:5834
#define IDYES
Definition: winuser.h:838

Referenced by UninstallGenerated().

◆ WorkerThread()

static DWORD CALLBACK WorkerThread ( LPVOID  Parameter)
static

Definition at line 570 of file geninst.cpp.

571{
573 return SendMessage(g_pInfo->hDlg, IM_END, 0, 0);
574}
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