ReactOS 0.4.16-dev-1204-gb627a42
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_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_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)
 
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 CommonInfog_pInfo
 

Macro Definition Documentation

◆ DB_GENINST_DELDIR

#define DB_GENINST_DELDIR   L"DelDir"

Definition at line 37 of file geninst.cpp.

◆ DB_GENINST_DELDIREMPTY

#define DB_GENINST_DELDIREMPTY   L"DelDirEmpty"

Definition at line 38 of file geninst.cpp.

◆ DB_GENINST_DELFILE

#define DB_GENINST_DELFILE   L"DelFile"

Definition at line 36 of file geninst.cpp.

◆ DB_GENINST_DELREG

#define DB_GENINST_DELREG   L"DelReg"

Definition at line 39 of file geninst.cpp.

◆ DB_GENINST_DELREGEMPTY

#define DB_GENINST_DELREGEMPTY   L"DelRegEmpty"

Definition at line 40 of file geninst.cpp.

◆ DB_GENINST_DIR

#define DB_GENINST_DIR   L"Dir"

Definition at line 33 of file geninst.cpp.

◆ DB_GENINST_FILES

#define DB_GENINST_FILES   L"Files"

Definition at line 32 of file geninst.cpp.

◆ DB_GENINST_ICON

#define DB_GENINST_ICON   L"Icon"

Definition at line 34 of file geninst.cpp.

◆ DB_GENINST_LNK

#define DB_GENINST_LNK   L"Lnk"

Definition at line 35 of file geninst.cpp.

◆ DB_NONE

#define DB_NONE   L"!"

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

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

◆ anonymous enum

anonymous enum
Enumerator
IM_STARTPROGRESS 
IM_PROGRESS 
IM_END 

Definition at line 164 of file geninst.cpp.

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

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

232{
233 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
235 name.Format(L"%c%u", Type, ++Info.EntryCount);
236 UINT err = Info.Entries.SetStringValue(name, Value);
237 if (err)
238 ErrorBox(err);
239 return !err;
240}
Type
Definition: Type.h:7
static UINT ErrorBox(UINT Error=GetLastError())
Definition: geninst.cpp:197
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(), CreateMainShortcut(), DECLARE_INTERFACE_(), ExtractAndInstallThread(), and InstallFiles().

◆ AddUninstallOperationsFromDB()

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

Definition at line 426 of file geninst.cpp.

427{
428 CStringW item, tmp;
429 if (*GetGenerateString(Name, tmp))
430 {
431 for (int pos = 1; pos > 0;)
432 {
433 pos = tmp.Find(L'|');
434 item = pos <= 0 ? tmp : tmp.Left(pos);
435 tmp = tmp.Mid(pos + 1);
436 AddEntry(UnOp, PathPrefix + item);
437 }
438 }
439}
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:231
static LPCWSTR GetGenerateString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:211
static ATOM item
Definition: dde.c:856

Referenced by ExtractAndInstallThread().

◆ CreateMainShortcut()

static CStringW CreateMainShortcut ( const CStringW Target)
static

Definition at line 288 of file geninst.cpp.

289{
290 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
292 CStringW rel = Info.ShortcutFile, path, dir, tmp;
293
294 if (FAILED(GetSpecialPath(csidl, path, Info.GetGuiOwner())))
295 return L""; // Pretend everything is OK
296
297 int cat;
298 if (Info.Parser.GetInt(DB_CATEGORY, cat) && cat == ENUM_CAT_GAMES)
299 {
300 // Try to find the name of the Games folder in the Start Menu
301 if (GetLocalizedSMFolderName(L"SM_GamesName", L"shortcuts.inf", L"Games", tmp))
302 {
303 path = BuildPath(path, tmp);
304 }
305 }
306
307 // SHPathPrepareForWrite will prepare the necessary directories.
308 // Windows and ReactOS SHPathPrepareForWrite do not support '/'.
309 rel.Replace('/', '\\');
310 path = BuildPath(path, rel.GetString());
312 HRESULT hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, path, SHPPFW);
313 if ((Info.Error = ErrorFromHResult(hr)) != 0)
314 {
315 ErrorBox(Info.Error);
316 return L"";
317 }
318
320 hr = link.CoCreateInstance(CLSID_ShellLink, IID_IShellLinkW);
321 if (SUCCEEDED(hr))
322 {
323 if (SUCCEEDED(hr = link->SetPath(Target)))
324 {
326 link->SetWorkingDirectory(tmp);
327
329 {
330 LPWSTR p = tmp.GetBuffer();
332 link->SetIconLocation(p, idx);
333 }
334 CComPtr<IPersistFile> persist;
335 if (SUCCEEDED(hr = link->QueryInterface(IID_IPersistFile, (void**)&persist)))
336 {
337 hr = persist->Save(path, FALSE);
338 }
339 }
340 }
341 if (SUCCEEDED(hr))
342 {
343 if (AddEntry(UNOP_FILE, path))
344 {
347 }
348 }
349 else
350 {
352 }
353 return Info.Error ? L"" : path;
354}
#define DB_CATEGORY
Definition: appinfo.h:90
@ 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:545
static CStringW BuildPath(const T &Base, LPCWSTR Append)
Definition: misc.h:106
static UINT ErrorFromHResult(HRESULT hr)
Definition: misc.h:26
CStringW SplitFileAndDirectory(LPCWSTR FullPath, CStringW *pDir=NULL)
Definition: misc.cpp:533
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 FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
static HRESULT GetCustomIconPath(InstallInfo &Info, CStringW &Path)
Definition: geninst.cpp:243
static BOOL GetLocalizedSMFolderName(LPCWSTR WinVal, LPCWSTR RosInf, LPCWSTR RosVal, CStringW &Output)
Definition: geninst.cpp:263
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:2364
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2203
#define SHPPFW_IGNOREFILENAME
Definition: shlobj.h:341
#define SHPPFW_DIRCREATE
Definition: shlobj.h:338
#define CSIDL_PROGRAMS
Definition: shlobj.h:2183
#define PathParseIconLocation
Definition: shlwapi.h:1026
BOOL PerUser
Definition: geninst.cpp:187
_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 646 of file geninst.cpp.

647{
648 enum { DLGW = 150, DLGH = 20, PAD = 4, PADx2 = PAD * 2, CHILDCOUNT = 1 };
650 static const WORD DlgTmpl[] =
651 {
652 LOWORD(DlgStyle), HIWORD(DlgStyle), 0, 0, CHILDCOUNT, 0, 0, DLGW, DLGH, 0, 0, 0,
653 PBS_MARQUEE, HIWORD(WS_CHILD | WS_VISIBLE), 0, 0, PAD, PAD, DLGW - PADx2, DLGH - PADx2, 1,
654 'm', 's', 'c', 't', 'l', 's', '_', 'p', 'r', 'o', 'g', 'r', 'e', 's', 's', '3', '2', 0, 0,
655 };
658 if (!hWnd)
659 {
660 ErrorBox();
661 return FALSE;
662 }
663 else if (!Silent)
664 {
666 }
667 MSG Msg;
668 while (GetMessageW(&Msg, NULL, 0, 0))
669 {
672 }
673 return TRUE;
674}
DWORD WINAPI ThreadProc(LPVOID lpParam)
Definition: ServiceMain.c:30
HWND hWnd
Definition: settings.c:17
struct @1681 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:605
#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:786
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())
inlinestatic

◆ ExtractAndInstallThread()

static DWORD CALLBACK ExtractAndInstallThread ( LPVOID  Parameter)
static

Definition at line 450 of file geninst.cpp.

451{
452 const BOOL PerUserModeDefault = TRUE;
453 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
454 LPCWSTR AppName = Info.AppName, Archive = Info.ArchivePath, None = DB_NONE;
455 CStringW installdir, tempdir, files, shortcut, tmp;
456 HRESULT hr;
457 CRegKey arpkey;
458 Info.ArpKey = &arpkey;
459
460 if (!*GetGenerateString(DB_GENINST_FILES, files, L"*.exe|*.*"))
462
464 if (tmp.CompareNoCase(L"User") == 0)
465 Info.PerUser = TRUE;
466 else if (tmp.CompareNoCase(L"Machine") == 0)
467 Info.PerUser = FALSE;
468 else
469 Info.PerUser = PerUserModeDefault;
470
471 hr = GetProgramFilesPath(installdir, Info.PerUser, Info.GetGuiOwner());
472 if ((Info.Error = ErrorFromHResult(hr)) != 0)
473 return ErrorBox(Info.Error);
474
476 if (tmp.Find('%') == 0 && ExpandEnvStrings(tmp))
477 installdir = tmp;
478 else if (tmp.Compare(None))
479 installdir = BuildPath(installdir, tmp.IsEmpty() ? AppName : tmp.GetString());
480 Info.InstallDir = installdir.GetString();
481 Info.InstallDirLen = installdir.GetLength() + 1;
482 hr = SHPathPrepareForWriteW(Info.GetGuiOwner(), NULL, installdir, SHPPFW_DIRCREATE);
483 if ((Info.Error = ErrorFromHResult(hr)) != 0)
484 return ErrorBox(Info.Error);
485
486 // Create the destination directory, and inside it, a temporary directory
487 // where we will extract the archive to before moving the files to their
488 // final location (adding uninstall entries as we go)
489 tempdir.Format(L"%s\\~RAM%u.tmp", installdir.GetString(), GetCurrentProcessId());
490 Info.Error = CreateDirectoryTree(tempdir.GetString());
491 if (Info.Error)
492 return ErrorBox(Info.Error);
493
494 if (!*GetGenerateString(DB_GENINST_LNK, shortcut))
495 shortcut.Format(L"%s.lnk", AppName);
496 Info.ShortcutFile = shortcut.Compare(None) ? shortcut.GetString() : NULL;
497
498 // Create the uninstall registration key
499 LPCWSTR arpkeyname = AppName;
500 tmp = BuildPath(REGPATH_UNINSTALL, arpkeyname);
503 Info.Error = arpkey.Create(hRoot, tmp, NULL, REG_OPTION_NON_VOLATILE, regsam);
504 if (!Info.Error)
505 {
507 Info.Error = Info.Entries.Create(arpkey, GENERATE_ARPSUBKEY);
508 }
509 if (Info.Error)
510 ErrorBox(Info.Error);
511
512 if (!Info.Error)
513 Info.Error = ExtractArchive(Archive, tempdir, ExtractCallback, &Info);
514
515 if (!Info.Error)
516 {
517 // We now know how many files we extracted, change from marquee to normal progress bar.
518 SendMessage(Info.hDlg, IM_STARTPROGRESS, 0, 0);
519
520 for (int pos = 1; pos > 0 && !Info.Error;)
521 {
522 pos = files.Find(L'|');
523 CStringW item = pos <= 0 ? files : files.Left(pos);
524 files = files.Mid(pos + 1);
525 InstallFiles(tempdir, item, installdir);
526 }
527
528 if (!Info.MainApp.IsEmpty())
529 {
536
537 WriteArpEntry(L"DisplayName", AppName);
538 WriteArpEntry(L"InstallLocation", Info.InstallDir); // Note: This value is used by the uninstaller!
539
540 LPWSTR p = tmp.GetBuffer(1 + MAX_PATH);
541 p[0] = L'\"';
543 tmp.ReleaseBuffer();
544 UINT cch = tmp.GetLength(), bitness = IsSystem64Bit() ? 64 : 32;
545 WCHAR modechar = Info.PerUser ? 'U' : 'M';
546 LPCWSTR unparamsfmt = L"\" /" CMD_KEY_UNINSTALL L" /K%s \"%c%d\\%s\"";
547 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L"", modechar, bitness, arpkeyname);
548 WriteArpEntry(L"UninstallString", tmp);
549 (tmp = tmp.Mid(0, cch)).AppendFormat(unparamsfmt, L" /S", modechar, bitness, arpkeyname);
550 WriteArpEntry(L"QuietUninstallString", tmp);
551
552 hr = GetCustomIconPath(Info, tmp);
554 WriteArpEntry(L"DisplayIcon", hr == S_OK ? tmp : Info.MainApp);
555
556 if (*GetCommonString(DB_VERSION, tmp))
557 WriteArpEntry(L"DisplayVersion", tmp);
558
559 SYSTEMTIME st;
560 GetSystemTime(&st);
561 tmp.Format(L"%.4u%.2u%.2u", st.wYear, st.wMonth, st.wDay);
562 WriteArpEntry(L"InstallDate", tmp);
563
564 if (*GetCommonString(DB_PUBLISHER, tmp))
565 WriteArpEntry(L"Publisher", tmp);
566
567#if DBG
568 tmp.Format(L"sys64=%d rapps%d", IsSystem64Bit(), sizeof(void*) * 8);
569 WriteArpEntry(L"_DEBUG", tmp);
570#endif
571 }
572
573 if (!Info.Error && Info.ShortcutFile)
574 {
575 tmp = CreateMainShortcut(Info.MainApp);
576 if (!tmp.IsEmpty() && !Info.Silent)
577 {
580 message.Format(format, const_cast<PCWSTR>(AppName));
581 if (MessageBoxW(Info.GetGuiOwner(), message, AppName, MB_YESNO | MB_ICONQUESTION) == IDYES)
582 {
583 SHELLEXECUTEINFOW sei = { sizeof(sei), SEE_MASK_NOASYNC, Info.GetGuiOwner() };
584 sei.lpFile = tmp;
585 sei.nShow = SW_SHOW;
586 ShellExecuteExW(&sei);
587 }
588 }
589 }
590 }
591
593 RemoveDirectory(installdir.GetString()); // This is harmless even if we installed something
594 return 0;
595}
#define DB_PUBLISHER
Definition: appinfo.h:91
#define GENERATE_ARPSUBKEY
Definition: appinfo.h:100
#define DB_VERSION
Definition: appinfo.h:89
#define DB_SCOPE
Definition: appinfo.h:96
bool ExpandEnvStrings(CStringW &Str)
Definition: misc.cpp:487
BOOL DeleteDirectoryTree(LPCWSTR Dir, HWND hwnd=NULL)
Definition: misc.cpp:513
UINT CreateDirectoryTree(LPCWSTR Dir)
Definition: misc.cpp:526
HRESULT GetProgramFilesPath(CStringW &Path, BOOL PerUser, HWND hwnd=NULL)
Definition: misc.cpp:569
BOOL IsSystem64Bit()
Definition: misc.cpp:382
#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:327
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL CALLBACK ExtractCallback(const EXTRACTCALLBACKINFO &, void *Context)
Definition: geninst.cpp:442
#define DB_GENINST_DIR
Definition: geninst.cpp:33
#define DB_GENINST_FILES
Definition: geninst.cpp:32
#define DB_GENINST_DELREG
Definition: geninst.cpp:39
#define DB_GENINST_DELDIR
Definition: geninst.cpp:37
static void AddUninstallOperationsFromDB(LPCWSTR Name, WCHAR UnOp, CStringW PathPrefix=CStringW(L""))
Definition: geninst.cpp:426
static UINT ExtractArchive(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:157
#define DB_GENINST_DELDIREMPTY
Definition: geninst.cpp:38
#define DB_NONE
Definition: geninst.cpp:31
#define DB_GENINST_LNK
Definition: geninst.cpp:35
#define REGPATH_UNINSTALL
Definition: geninst.cpp:29
#define DB_GENINST_DELFILE
Definition: geninst.cpp:36
static BOOL InstallFiles(const CStringW &SourceDirBase, const CStringW &Spec, const CStringW &DestinationDir)
Definition: geninst.cpp:357
#define DB_GENINST_DELREGEMPTY
Definition: geninst.cpp:40
static CStringW CreateMainShortcut(const CStringW &Target)
Definition: geninst.cpp:288
static void WriteArpEntry(LPCWSTR Name, LPCWSTR Value, UINT Type=REG_SZ)
Definition: geninst.cpp:219
static LPCWSTR GetCommonString(LPCWSTR Name, CStringW &Output, LPCWSTR Default=L"")
Definition: geninst.cpp:203
#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
#define SEE_MASK_NOASYNC
Definition: shellapi.h:35
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2472
WORD wYear
Definition: winbase.h:946
WORD wMonth
Definition: winbase.h:947
WORD wDay
Definition: winbase.h:949
Definition: format.c:58
Definition: tftpd.h:60
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define CMD_KEY_UNINSTALL
Definition: unattended.h:5
#define RemoveDirectory
Definition: winbase.h:3936
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define GetModuleFileName
Definition: winbase.h:3872
#define ERROR_CAN_NOT_COMPLETE
Definition: winerror.h:582
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
ACCESS_MASK REGSAM
Definition: winreg.h:69
#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:5928
#define MB_ICONQUESTION
Definition: winuser.h:800
#define IDYES
Definition: winuser.h:846
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ExtractAndRunGeneratedInstaller().

◆ ExtractAndRunGeneratedInstaller()

BOOL ExtractAndRunGeneratedInstaller ( const CAvailableApplicationInfo AppInfo,
LPCWSTR  Archive 
)

Definition at line 677 of file geninst.cpp.

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

Referenced by HandleGenerateInstallerCommand().

◆ ExtractArchive()

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

Definition at line 157 of file geninst.cpp.

158{
159 BOOL isCab = LOBYTE(ClassifyFile(Archive)) == 'C';
160 return isCab ? ExtractCab(Archive, OutputDir, Callback, Context)
161 : ExtractZip(Archive, OutputDir, Callback, Context);
162}
UINT ClassifyFile(PCWSTR Path)
Definition: misc.cpp:125
static UINT ExtractZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:138
static UINT ExtractCab(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:146
#define LOBYTE(W)
Definition: jmemdos.c:487
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

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 db.UpdateAvailable();
850 CAvailableApplicationInfo *pAppInfo = db.FindAvailableByPackageName(PackageName);
851 if (!pAppInfo)
853 CConfigParser *pCfg = pAppInfo->GetConfigParser();
854
855 if (!GetTempPathW(_countof(TempDirBuf), TempDirBuf))
856 return E_FAIL;
857 wsprintfW(UniqueDir, L"~%s-%u", RAPPS_NAME, GetCurrentProcessId());
858 TempDir = BuildPath(TempDirBuf, UniqueDir);
860 if (FAILED(hr))
861 return hr;
862
863 hr = HResultFromWin32(ExtractArchive(pszArchive, TempDir, NULL, NULL));
864 if (SUCCEEDED(hr))
865 {
868 {
870 HANDLE hFind = FindFirstFileW(Exe = BuildPath(TempDir, L"*.exe"), &wfd);
871 if (hFind != INVALID_HANDLE_VALUE)
872 {
873 FindClose(hFind);
874 Exe = wfd.cFileName;
875 }
876 }
877 App = BuildPath(TempDir, Exe);
880 }
881
882 if (FAILED(hr) && !TempDir.IsEmpty())
884 return hr;
885}
#define DB_EXEINZIPSECTION
Definition: appinfo.h:102
#define DB_EXEINZIP_EXE
Definition: appinfo.h:103
#define RAPPS_NAME
Definition: defines.h:34
Definition: appdb.h:9
static CStringW GetDefaultPath()
Definition: appdb.cpp:39
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:652
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:2080
#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
#define _countof(array)
Definition: sndvol32.h:70
Definition: xml2sdb.h:149
#define ERROR_NOT_FOUND
Definition: winerror.h:690
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)

Referenced by CDownloadManager::PerformDownloadAndInstall().

◆ ExtractCab()

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

Definition at line 146 of file geninst.cpp.

148{
149 if (ExtractFilesFromCab(Archive, OutputDir, Callback, Context))
150 return ERROR_SUCCESS;
152 return err ? err : ERROR_INTERNAL_ERROR;
153}
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:840

Referenced by ExtractArchive().

◆ ExtractCallback()

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

Definition at line 442 of file geninst.cpp.

443{
445 Info.Count += 1;
446 return TRUE;
447}

Referenced by ExtractAndInstallThread().

◆ ExtractFilesFromZip()

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

Definition at line 62 of file geninst.cpp.

64{
65 const UINT pkzefsutf8 = 1 << 11; // APPNOTE; APPENDIX D
68 unzFile hzf = unzOpen2_64(Archive, &zff);
69 if (!hzf)
70 return UNZ_BADZIPFILE;
71 CStringA narrow;
73 int zerr = unzGoToFirstFile(hzf);
74 for (; zerr == UNZ_OK; zerr = unzGoToNextFile(hzf))
75 {
77 zerr = unzGetCurrentFileInfo64(hzf, &fi, NULL, 0, NULL, 0, NULL, 0);
78 if (zerr != UNZ_OK)
79 break;
80 LPSTR file = narrow.GetBuffer(fi.size_filename);
81 zerr = unzGetCurrentFileInfo64(hzf, &fi, file, narrow.GetAllocLength(), NULL, 0, NULL, 0);
82 if (zerr != UNZ_OK)
83 break;
85 narrow.Replace('/', '\\');
86 while (narrow[0] == '\\')
87 narrow = narrow.Mid(1);
88 UINT codepage = (fi.flag & pkzefsutf8) ? CP_UTF8 : 1252;
89 UINT cch = MultiByteToWideChar(codepage, 0, narrow, -1, NULL, 0);
90 cch = MultiByteToWideChar(codepage, 0, narrow, -1, path.GetBuffer(cch - 1), cch);
91 if (!cch)
92 break;
93 path.ReleaseBuffer(cch - 1);
95 BYTE attsys = HIBYTE(fi.version), dos = 0, ntfs = 10, vfat = 14;
96 if ((attsys == dos || attsys == ntfs || attsys == vfat) && LOBYTE(fi.external_fa))
97 fileatt = LOBYTE(fi.external_fa);
98
101 continue; // Skip file
102
103 path = BuildPath(OutputDir, path);
105 if (!dir.IsEmpty() && (err = CreateDirectoryTree(dir)))
106 {
107 zerr = UNZ_ERRNO;
109 break;
110 }
111
112 if ((zerr = unzOpenCurrentFile(hzf)) != UNZ_OK)
113 break;
114 zerr = UNZ_ERRNO;
117 NULL, CREATE_ALWAYS, fileatt, NULL);
119 {
120 DWORD len = 1024 * 4, cb;
121 LPSTR buf = narrow.GetBuffer(len);
122 for (zerr = UNZ_OK; zerr == UNZ_OK;)
123 {
124 len = zerr = unzReadCurrentFile(hzf, buf, len);
125 if (zerr <= 0)
126 break;
127 zerr = WriteFile(hFile, buf, len, &cb, NULL) && cb == len ? UNZ_OK : UNZ_ERRNO;
128 }
130 }
132 }
133 unzClose(hzf);
134 return zerr == UNZ_END_OF_LIST_OF_FILE ? UNZ_OK : zerr;
135}
static BOOL NotifyFileExtractCallback(const CStringW &ItemPath, UINT64 UncompressedSize, UINT FileAttributes, EXTRACTCALLBACK Callback, void *Cookie)
Definition: misc.h:71
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 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 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
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 Context 
)
static

Definition at line 138 of file geninst.cpp.

140{
141 int zerr = ExtractFilesFromZip(Archive, OutputDir, Callback, Context);
142 return zerr == UNZ_ERRNO ? GetLastError() : zerr ? ERROR_INTERNAL_ERROR : 0;
143}
static int ExtractFilesFromZip(LPCWSTR Archive, const CStringW &OutputDir, EXTRACTCALLBACK Callback, void *Context)
Definition: geninst.cpp:62

Referenced by ExtractArchive().

◆ GetCommonString()

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

Definition at line 203 of file geninst.cpp.

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

Referenced by ExtractAndInstallThread().

◆ GetCustomIconPath()

static HRESULT GetCustomIconPath ( InstallInfo Info,
CStringW Path 
)
static

Definition at line 243 of file geninst.cpp.

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

Referenced by CreateMainShortcut(), and ExtractAndInstallThread().

◆ GetGenerateString()

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

Definition at line 211 of file geninst.cpp.

212{
213 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
215 return (r ? Output : Output = Default).GetString();
216}
#define DB_GENINSTSECTION
Definition: appinfo.h:99
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 263 of file geninst.cpp.

264{
265 CRegKey key;
266 if (key.Open(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion", KEY_READ) == ERROR_SUCCESS &&
267 GetRegString(key, WinVal, Output) && !Output.IsEmpty())
268 {
269 return TRUE;
270 }
271 WCHAR windir[MAX_PATH];
272 GetWindowsDirectoryW(windir, _countof(windir));
273 CStringW path = BuildPath(BuildPath(windir, L"inf"), RosInf), section;
274 DWORD lang = 0, lctype = LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER;
275 if (GetLocaleInfoW(GetUserDefaultLCID(), lctype, (LPWSTR) &lang, sizeof(lang) / sizeof(WCHAR)))
276 {
277 section.Format(L"Strings.%.4x", lang);
278 if (ReadIniValue(path, section, RosVal, Output) > 0)
279 return TRUE;
280 section.Format(L"Strings.%.2x", PRIMARYLANGID(lang));
281 if (ReadIniValue(path, section, RosVal, Output) > 0)
282 return TRUE;
283 }
284 return ReadIniValue(path, L"Strings", RosVal, Output) > 0;
285}
LPCWSTR GetRegString(CRegKey &Key, LPCWSTR Name, CStringW &Value)
Definition: misc.cpp:464
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:1211
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1666
#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:26

Referenced by CreateMainShortcut().

◆ InstallFiles()

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

Definition at line 357 of file geninst.cpp.

359{
360 InstallInfo &Info = *static_cast<InstallInfo *>(g_pInfo);
361 CStringW sourcedir, filespec;
362 filespec = SplitFileAndDirectory(Spec, &sourcedir); // Split "[OptionalDir\]*.ext"
363 sourcedir = BuildPath(SourceDirBase, sourcedir);
364 BOOL success = TRUE;
366 HANDLE hFind = FindFirstFileW(BuildPath(sourcedir, filespec), &wfd);
367 if (hFind == INVALID_HANDLE_VALUE)
368 {
371 return TRUE;
372 else
373 return !ErrorBox(error);
374 }
375
376 for (;;)
377 {
378 CStringW from = BuildPath(sourcedir, wfd.cFileName);
379 CStringW to = BuildPath(DestinationDir, wfd.cFileName);
380 CStringW uninstpath = to.Mid(Info.InstallDirLen - 1);
381 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
382 {
383 LPWSTR p = wfd.cFileName;
384 BOOL dots = p[0] == '.' && (!p[1] || (p[1] == '.' && !p[2]));
385 if (!dots)
386 {
387 Info.Error = CreateDirectoryTree(to);
388 if (Info.Error)
389 {
390 success = !ErrorBox(Info.Error);
391 }
392
393 if (success)
394 {
395 success = InstallFiles(from, filespec, to);
396 }
397 AddEntry(UNOP_EMPTYDIR, uninstpath);
398 }
399 }
400 else
401 {
403 if (success)
404 {
405 if (Info.MainApp.IsEmpty())
406 {
407 Info.MainApp = to;
408 }
409 success = AddEntry(UNOP_FILE, uninstpath);
410 }
411 else
412 {
413 ErrorBox();
414 }
415 SendMessage(g_pInfo->hDlg, IM_PROGRESS, 0, 0);
416 }
417
418 if (!success || !FindNextFileW(hFind, &wfd))
419 break;
420 }
421 FindClose(hFind);
422 return success;
423}
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
#define success(from, fromstr, to, tostr)
#define MoveFileEx
Definition: winbase.h:3919

Referenced by ExtractAndInstallThread(), and InstallFiles().

◆ IsZipFile()

BOOL IsZipFile ( PCWSTR  Path)

Definition at line 50 of file geninst.cpp.

51{
54 unzFile hzf = unzOpen2_64(Path, &zff);
55 if (!hzf)
56 return FALSE;
57 unzClose(hzf);
58 return TRUE;
59}

Referenced by ClassifyFile().

◆ UIDlgProc()

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

Definition at line 605 of file geninst.cpp.

606{
607 HWND hPB = GetDlgItem(hDlg, 1);
608 switch(uMsg)
609 {
610 case IM_STARTPROGRESS:
613 SendMessageW(hPB, PBM_SETRANGE32, 0, g_pInfo->Count);
614 SendMessageW(hPB, PBM_SETPOS, 0, 0);
615 break;
616 case IM_PROGRESS:
617 SendMessageW(hPB, PBM_DELTAPOS, 1, 0);
618 break;
619 case IM_END:
620 DestroyWindow(hDlg);
621 break;
622 case WM_INITDIALOG:
623 {
625 g_pInfo->hDlg = hDlg;
627 SendMessageW(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIco);
628 SendMessageW(hDlg, WM_SETTEXT, 0, (LPARAM)g_pInfo->AppName);
630 {
631 ErrorBox();
632 SendMessageW(hDlg, IM_END, 0, 0);
633 }
634 return TRUE;
635 }
636 case WM_CLOSE:
637 return TRUE;
638 case WM_DESTROY:
639 PostMessage(NULL, WM_QUIT, 0, 0);
640 break;
641 }
642 return FALSE;
643}
#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:598
#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:1981
#define ICON_BIG
Definition: tnclass.cpp:51
#define SetWindowLongPtr
Definition: treelist.c:70
#define WM_CLOSE
Definition: winuser.h:1640
#define WM_QUIT
Definition: winuser.h:1642
#define WM_INITDIALOG
Definition: winuser.h:1758
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_SETTEXT
Definition: winuser.h:1636
#define PostMessage
Definition: winuser.h:5917
#define WM_DESTROY
Definition: winuser.h:1628
#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:2412
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

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:77
static DWORD CALLBACK UninstallThread(LPVOID Parameter)
Definition: geninst.cpp:702
_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 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:446
#define IDS_INSTGEN_CONFIRMUNINST
Definition: resource.h:242
static DWORD RemoveInstalledAppFromRegistry(const CAppInfo *Info)
Definition: appdb.cpp:324
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:96
#define DeleteFile
Definition: winbase.h:3805
#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 MessageBox
Definition: winuser.h:5907

Referenced by UninstallGenerated().

◆ WorkerThread()

static DWORD CALLBACK WorkerThread ( LPVOID  Parameter)
static

Definition at line 598 of file geninst.cpp.

599{
601 return SendMessage(g_pInfo->hDlg, IM_END, 0, 0);
602}
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:764
_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 219 of file geninst.cpp.

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

Referenced by ExtractAndInstallThread().

Variable Documentation

◆ g_pInfo