#include #include #include "install.h" #include "resource.h" #include #include extern "C" { #include #include } #include #include static void correctfilter(char *z) { char *c; while ((c=strrchr(z,'|'))!=NULL) *c=0; } static void CommDlgError(HWND owner, int error) { char *msg=0; switch (error) { case CDERR_DIALOGFAILURE: msg="CDERR_DIALOGFAILURE: The dialog box could not be created. The common dialog box function's call to the DialogBox function failed. For example, this error occurs if the common dialog box call specifies an invalid window handle. ";break; case CDERR_FINDRESFAILURE: msg="CDERR_FINDRESFAILURE: The common dialog box function failed to find a specified resource. ";break; case CDERR_INITIALIZATION: msg="CDERR_INITIALIZATION: The common dialog box function failed during initialization. This error often occurs when sufficient memory is not available. ";break; case CDERR_LOADRESFAILURE: msg="CDERR_LOADRESFAILURE: The common dialog box function failed to load a specified resource. ";break; case CDERR_LOADSTRFAILURE: msg="CDERR_LOADSTRFAILURE: The common dialog box function failed to load a specified string. ";break; case CDERR_LOCKRESFAILURE: msg="CDERR_LOCKRESFAILURE: The common dialog box function failed to lock a specified resource. ";break; case CDERR_MEMALLOCFAILURE: msg="CDERR_MEMALLOCFAILURE: The common dialog box function was unable to allocate memory for internal structures. ";break; case CDERR_MEMLOCKFAILURE: msg="CDERR_MEMLOCKFAILURE: The common dialog box function was unable to lock the memory associated with a handle. ";break; case CDERR_NOHINSTANCE: msg="CDERR_NOHINSTANCE: The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding instance handle. ";break; case CDERR_NOHOOK: msg="CDERR_NOHOOK: The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a pointer to a corresponding hook procedure. ";break; case CDERR_NOTEMPLATE: msg="CDERR_NOTEMPLATE: The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding template. ";break; case CDERR_REGISTERMSGFAIL: msg="CDERR_REGISTERMSGFAIL: The RegisterWindowMessage function returned an error code when it was called by the common dialog box function. ";break; case CDERR_STRUCTSIZE: msg="CDERR_STRUCTSIZE: The lStructSize member of the initialization structure for the corresponding common dialog box is invalid. ";break; case FNERR_BUFFERTOOSMALL: msg="FNERR_BUFFERTOOSMALL: The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the file name specified by the user. The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in TCHARs, required to receive the full name. ";break; case FNERR_INVALIDFILENAME: msg="FNERR_INVALIDFILENAME: A file name is invalid. ";break; case FNERR_SUBCLASSFAILURE: msg="FNERR_SUBCLASSFAILURE: An attempt to subclass a list box failed because sufficient memory was not available. ";;break; default: msg="Unknown CommDlgError.";break; } char *text=(char *)alloca(strlen(msg)+200); sprintf(text,"CommDlgError (%d / %04X)\r\n\r\nDescription:\r\n\r\n%s",error,error,msg); MessageBox(owner,text,NULL,MB_OK|MB_ICONEXCLAMATION); } static bool VyberSlozku(HWND owner, char *slozka) { OPENFILENAME ofn; char filter[100]; char title[100]; LoadString(GetModuleHandle(NULL),IDS_INSTALLFILTER,filter,sizeof(filter)); LoadString(GetModuleHandle(NULL),IDS_INSTALLTITLE,title,sizeof(title)); LoadString(GetModuleHandle(NULL),IDS_INSTALLPRENAME,slozka,MAX_PATH); correctfilter(filter); memset(&ofn,0,sizeof(ofn)); #ifdef OPENFILENAME_SIZE_VERSION_400 ofn.lStructSize=OPENFILENAME_SIZE_VERSION_400; #else ofn.lStructSize=sizeof(ofn); #endif ofn.hwndOwner=owner; ofn.lpstrFilter=filter; ofn.lpstrFile=slozka; ofn.nMaxFile=MAX_PATH*4; ofn.lpstrTitle=title; ofn.Flags=OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR; if (GetOpenFileName(&ofn)) return true; else { int err=CommDlgExtendedError(); if (err) CommDlgError(owner,err); return false; } } static bool VyberCD(HWND owner, char *slozka) { OPENFILENAME ofn; char filter[100]; char title[100]; LoadString(GetModuleHandle(NULL),IDS_INSTALLCDFILTER,filter,sizeof(filter)); LoadString(GetModuleHandle(NULL),IDS_INSTALLCDTITLE,title,sizeof(title)); LoadString(GetModuleHandle(NULL),IDS_INSTALLCDFILE,slozka,MAX_PATH); correctfilter(filter); memset(&ofn,0,sizeof(ofn)); #ifdef OPENFILENAME_SIZE_VERSION_400 ofn.lStructSize=OPENFILENAME_SIZE_VERSION_400; #else ofn.lStructSize=sizeof(ofn); #endif ofn.hwndOwner=owner; ofn.lpstrFilter=filter; ofn.lpstrFile=slozka; ofn.nMaxFile=MAX_PATH*4; ofn.lpstrTitle=title; ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR; if (GetOpenFileName(&ofn)) return true; else { int err=CommDlgExtendedError(); if (err) CommDlgError(owner,err); return false; } } static TSTR_LIST filetocopy=NULL; static void FileSingleCopy(const char *src, const char *trg) { if (filetocopy==NULL) filetocopy=create_list(100); str_add(&filetocopy,(char *)src); str_add(&filetocopy,(char *)trg); } static void FileCopy(HWND hWnd,const char *srcmask, const char *trgmask, const char *src, const char *trg) { char *fsrc=(char *)alloca((strlen(srcmask)+strlen(src))*2+MAX_PATH); char *ftrg=(char *)alloca((strlen(trgmask)+strlen(trg))*2+MAX_PATH); sprintf(fsrc,srcmask,src); sprintf(ftrg,trgmask,trg); strcat(ftrg,"\\"); char *trgplace=strchr(ftrg,0); char *srcplace=strrchr(fsrc,'\\')+1; WIN32_FIND_DATA fdata; HANDLE h=FindFirstFile(fsrc,&fdata); if (h==INVALID_HANDLE_VALUE) { ResMessageBox2(hWnd,IDS_INSTALLCHYBISOUBOR,MB_ICONEXCLAMATION|MB_OK,fsrc); return; } if (h) do { if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(trgplace,fdata.cFileName); strcpy(srcplace,fdata.cFileName); FileSingleCopy(fsrc,ftrg); } } while (FindNextFile(h,&fdata)); FindClose(h); } static void DirCreate(const char *srcmask, const char *src) { char *fsrc=(char *)alloca((strlen(srcmask)+strlen(src))*2+MAX_PATH); sprintf(fsrc,srcmask,src); CreateDirectory(fsrc,NULL); } static BOOL CommitCopy(HWND hWnd) { int size=0; int i; for (i=0;iSetPath(lpszPathObj); psl->SetDescription( lpszDesc); psl->SetWorkingDirectory(wkd); if (args!=NULL) psl->SetArguments(args); // Query IShellLink for the IPersistFile interface for saving the // shortcut in persistent storage. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); if (SUCCEEDED(hres)) { wchar_t wsz[MAX_PATH]; // Ensure that the string is ANSI. MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH); // Save the link by calling IPersistFile::Save. hres = ppf->Save(wsz, TRUE); ppf->Release(); } psl->Release(); } return hres; } static void CreateLinkSkeldal(char *buff,char *slozka) { CoInitialize(NULL); GetModuleFileName(NULL,buff,MAX_PATH*4); char *c=strrchr(buff,'\\'); strcat(slozka,c); SHGetSpecialFolderPath(NULL,buff,CSIDL_DESKTOPDIRECTORY,TRUE); strcat(buff,"\\"); c=strchr(buff,0); LoadString(GetModuleHandle(NULL),IDS_WINTITLE,c,50); strcat(c,".lnk"); CreateLink(slozka,buff,"",NULL); } BOOL RunInstall(HWND hWnd) { char slozka[MAX_PATH*4]; char cd[MAX_PATH*4]; char mypath[MAX_PATH*4]; TSTR_LIST ini; char *c; if (ResMessageBox(hWnd,IDS_INSTALLTEXT1,MB_OKCANCEL)==IDCANCEL) return FALSE; if (VyberCD(hWnd,cd)==false) return FALSE; if (ResMessageBox(hWnd,IDS_INSTALLTEXT2,MB_OKCANCEL)==IDCANCEL) return FALSE; opakuj1: if (VyberSlozku(hWnd,slozka)==false) return FALSE; c=strrchr(slozka,'\\'); if (c==NULL) goto opakuj1; c++; if (strstr(slozka,c)