| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
#include "stdafx.h" |
|---|
| 4 |
#include "resource.h" |
|---|
| 5 |
#include <string> |
|---|
| 6 |
|
|---|
| 7 |
#include "paths.h" |
|---|
| 8 |
|
|---|
| 9 |
using namespace std; |
|---|
| 10 |
|
|---|
| 11 |
#include "../regkey.h" |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
#define SWISHCTL_VERSION ("1007") |
|---|
| 16 |
|
|---|
| 17 |
const char *AUTORUN = "AutoRun"; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
enum dllnames { SWISHCTL=0, ZLIB=1 }; |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
char * installdlls[] = { |
|---|
| 25 |
"SwishCtl.dll", "zlib.dll" }; |
|---|
| 26 |
|
|---|
| 27 |
const char registrykey[] = "Software\\SWISH-E Team\\SwishCtl\\Options"; |
|---|
| 28 |
|
|---|
| 29 |
static const char uninstallkey[] = |
|---|
| 30 |
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" ; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
LRESULT CALLBACK SetupHandler(HWND, UINT, WPARAM, LPARAM); |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
class SetupApp { |
|---|
| 42 |
public: |
|---|
| 43 |
static HINSTANCE getInstance() {return hInst;}; |
|---|
| 44 |
~SetupApp(); |
|---|
| 45 |
SetupApp(HINSTANCE hInstance); |
|---|
| 46 |
static HINSTANCE hInst; |
|---|
| 47 |
|
|---|
| 48 |
}; |
|---|
| 49 |
|
|---|
| 50 |
SetupApp::SetupApp(HINSTANCE hInstance) |
|---|
| 51 |
{ |
|---|
| 52 |
hInst = hInstance; |
|---|
| 53 |
OleInitialize(NULL); |
|---|
| 54 |
|
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
SetupApp::~SetupApp() |
|---|
| 58 |
{ |
|---|
| 59 |
OleUninitialize(); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
HINSTANCE SetupApp::hInst = 0; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
class LibModule { |
|---|
| 74 |
public: |
|---|
| 75 |
LibModule() {m_hLib = NULL;}; |
|---|
| 76 |
~LibModule(); |
|---|
| 77 |
bool LoadLibrary( const char *pathname ); |
|---|
| 78 |
HINSTANCE getInstance(){ return m_hLib;}; |
|---|
| 79 |
|
|---|
| 80 |
private: |
|---|
| 81 |
HINSTANCE m_hLib; |
|---|
| 82 |
}; |
|---|
| 83 |
|
|---|
| 84 |
LibModule::~LibModule() |
|---|
| 85 |
{ |
|---|
| 86 |
if (m_hLib) ::FreeLibrary(m_hLib); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
bool LibModule::LoadLibrary( const char *pathname ) |
|---|
| 90 |
{ |
|---|
| 91 |
m_hLib = ::LoadLibrary(pathname); |
|---|
| 92 |
return m_hLib != NULL; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
typedef enum InstallResult { INSTALL_OK, ERR_INUSE, ERR_FAIL, ERR_ONREBOOT }; |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
bool AddStartProgramsFolder(char *FolderName, char *FullPathToFolder) |
|---|
| 106 |
{ |
|---|
| 107 |
LPITEMIDLIST pidlPrograms; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlPrograms); |
|---|
| 111 |
|
|---|
| 112 |
if ( !SHGetPathFromIDList( pidlPrograms, FullPathToFolder) ) |
|---|
| 113 |
{ |
|---|
| 114 |
return false; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
strcat( FullPathToFolder, FolderName); |
|---|
| 118 |
|
|---|
| 119 |
CreateDirectory(FullPathToFolder, NULL); |
|---|
| 120 |
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATH, FullPathToFolder, 0); |
|---|
| 121 |
|
|---|
| 122 |
return true; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
HRESULT CreateShortcut( LPCSTR Source, |
|---|
| 127 |
LPSTR Target, |
|---|
| 128 |
LPSTR Description) |
|---|
| 129 |
{ |
|---|
| 130 |
HRESULT hresult; |
|---|
| 131 |
IShellLink* ShellLink; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
hresult = CoCreateInstance( |
|---|
| 136 |
CLSID_ShellLink, |
|---|
| 137 |
NULL, |
|---|
| 138 |
CLSCTX_INPROC_SERVER, |
|---|
| 139 |
IID_IShellLink, |
|---|
| 140 |
(LPVOID*)&ShellLink); |
|---|
| 141 |
if (SUCCEEDED(hresult)) |
|---|
| 142 |
{ |
|---|
| 143 |
IPersistFile* PersistFile; |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
ShellLink->SetPath(Source); |
|---|
| 147 |
ShellLink->SetDescription(Description); |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
hresult = ShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&PersistFile); |
|---|
| 152 |
|
|---|
| 153 |
if (SUCCEEDED(hresult)) |
|---|
| 154 |
{ |
|---|
| 155 |
WCHAR WideTarget[MAX_PATH]; |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
MultiByteToWideChar( CP_ACP, |
|---|
| 159 |
0, |
|---|
| 160 |
Target, |
|---|
| 161 |
-1, |
|---|
| 162 |
WideTarget, |
|---|
| 163 |
MAX_PATH); |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
hresult = PersistFile->Save(WideTarget, TRUE); |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
PersistFile->Release(); |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
ShellLink->Release(); |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
return hresult; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
bool UnregisterIndexFile() |
|---|
| 181 |
{ |
|---|
| 182 |
RegKey key(HKEY_LOCAL_MACHINE); |
|---|
| 183 |
|
|---|
| 184 |
if ( ! key.OpenKey( "Software\\SWISH-E Team" ) ) return false; |
|---|
| 185 |
return key.DeleteKey( "SwishCtl" ); |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
bool RegisterIndexFile(char *indexdir, char *indexname) |
|---|
| 191 |
{ |
|---|
| 192 |
RegKey key(HKEY_LOCAL_MACHINE); |
|---|
| 193 |
string keyname(registrykey); |
|---|
| 194 |
if ( ! key.CreateKey( keyname.c_str() ) ) return false; |
|---|
| 195 |
|
|---|
| 196 |
bool kv = key.SetValue( "IndexLocation", indexdir ); |
|---|
| 197 |
kv &= key.SetValue( "IndexFiles", indexname ); |
|---|
| 198 |
|
|---|
| 199 |
kv &= key.SetValue( "DLLVersion", SWISHCTL_VERSION ); |
|---|
| 200 |
|
|---|
| 201 |
return kv; |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
bool UnregisterUninstall() |
|---|
| 207 |
{ |
|---|
| 208 |
RegKey key(HKEY_LOCAL_MACHINE); |
|---|
| 209 |
|
|---|
| 210 |
if ( ! key.OpenKey( uninstallkey ) ) return false; |
|---|
| 211 |
return key.DeleteKey( "SwishCtl" ); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
bool RegisterUninstall(const char *uninstallcommand) |
|---|
| 216 |
{ |
|---|
| 217 |
|
|---|
| 218 |
string keyname(uninstallkey); |
|---|
| 219 |
keyname += "SwishCtl"; |
|---|
| 220 |
|
|---|
| 221 |
RegKey key(HKEY_LOCAL_MACHINE); |
|---|
| 222 |
if ( ! key.CreateKey( keyname.c_str() ) ) return false; |
|---|
| 223 |
|
|---|
| 224 |
bool result = key.SetValue( "DisplayName", "ACC Index Search Tool" ); |
|---|
| 225 |
result &= key.SetValue( "UninstallString", uninstallcommand ); |
|---|
| 226 |
|
|---|
| 227 |
return result; |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
BOOL LaunchUrl( HWND hwnd, char *url ) |
|---|
| 231 |
{ |
|---|
| 232 |
if (ShellExecute( |
|---|
| 233 |
hwnd, |
|---|
| 234 |
"open", |
|---|
| 235 |
url, |
|---|
| 236 |
NULL, NULL, SW_SHOWNORMAL) < (HINSTANCE)32 ) |
|---|
| 237 |
{ |
|---|
| 238 |
char *buff[256] ; |
|---|
| 239 |
sprintf( (char *) buff, |
|---|
| 240 |
"Setup could not launch the search page (%s) \n" |
|---|
| 241 |
"please try opening the file from within Internet Explorer.", |
|---|
| 242 |
url |
|---|
| 243 |
); |
|---|
| 244 |
MessageBox( |
|---|
| 245 |
NULL, |
|---|
| 246 |
(char *) buff, |
|---|
| 247 |
"Swish Control Setup", |
|---|
| 248 |
MB_OK | MB_ICONASTERISK ); |
|---|
| 249 |
return FALSE; |
|---|
| 250 |
} |
|---|
| 251 |
return TRUE; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
bool DeleteShortcuts(char *shortcut, char *subdir) |
|---|
| 256 |
{ |
|---|
| 257 |
CStartProgramsDirectory startprograms; |
|---|
| 258 |
|
|---|
| 259 |
CDirectory newdir = startprograms + subdir; |
|---|
| 260 |
|
|---|
| 261 |
CPath Shortcut = newdir + shortcut; |
|---|
| 262 |
|
|---|
| 263 |
bool result = DeleteFile( Shortcut.getBuffer()) != 0; |
|---|
| 264 |
|
|---|
| 265 |
RemoveDirectory( newdir.getBuffer()); |
|---|
| 266 |
return result; |
|---|
| 267 |
|
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
bool AddShortcut(CDirectory &appdir) |
|---|
| 272 |
{ |
|---|
| 273 |
CStartProgramsDirectory startprograms; |
|---|
| 274 |
|
|---|
| 275 |
CDirectory newdir = startprograms.CreateChild( "ACC Index" ); |
|---|
| 276 |
|
|---|
| 277 |
CPath Shortcut = newdir + "index.lnk"; |
|---|
| 278 |
CPath IndexPage = appdir + "index.htm"; |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
CreateShortcut( IndexPage.getBuffer(), Shortcut.getBuffer(), |
|---|
| 282 |
"ACC Index database" ); |
|---|
| 283 |
startprograms.NotifyChanged(); |
|---|
| 284 |
return true; |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
typedef HRESULT (STDAPICALLTYPE *CTLREGPROC)() ; |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
bool registerOleDll( const char * pathname ) |
|---|
| 292 |
{ |
|---|
| 293 |
LibModule dll; |
|---|
| 294 |
if ( ! dll.LoadLibrary(pathname) ) return false; |
|---|
| 295 |
|
|---|
| 296 |
CTLREGPROC lpDllEntryPoint; |
|---|
| 297 |
lpDllEntryPoint = (CTLREGPROC) GetProcAddress (dll.getInstance(), |
|---|
| 298 |
_T("DllRegisterServer")); |
|---|
| 299 |
|
|---|
| 300 |
if (!lpDllEntryPoint) return false; |
|---|
| 301 |
|
|---|
| 302 |
HRESULT res = (*lpDllEntryPoint)(); |
|---|
| 303 |
return res == NOERROR; |
|---|
| 304 |
} |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
bool unregisterOleDll( const char * pathname ) |
|---|
| 308 |
{ |
|---|
| 309 |
LibModule dll; |
|---|
| 310 |
if ( ! dll.LoadLibrary(pathname) ) return false; |
|---|
| 311 |
|
|---|
| 312 |
CTLREGPROC lpDllEntryPoint; |
|---|
| 313 |
lpDllEntryPoint = (CTLREGPROC)GetProcAddress ( dll.getInstance(), |
|---|
| 314 |
_T("DllUnregisterServer")); |
|---|
| 315 |
if (!lpDllEntryPoint) return false; |
|---|
| 316 |
|
|---|
| 317 |
HRESULT res = (*lpDllEntryPoint)(); |
|---|
| 318 |
return res == NOERROR; |
|---|
| 319 |
} |
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
bool AppIsRegistered() |
|---|
| 323 |
{ |
|---|
| 324 |
CLSID clsid; |
|---|
| 325 |
return CLSIDFromProgID(L"SwishCtl.CSwishCtl", &clsid) == S_OK; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
BOOL ShowInstallDialog() |
|---|
| 329 |
{ |
|---|
| 330 |
return DialogBox (SetupApp::getInstance (), |
|---|
| 331 |
(LPCTSTR) IDD_SETUP, |
|---|
| 332 |
NULL, |
|---|
| 333 |
(DLGPROC) SetupHandler); |
|---|
| 334 |
} |
|---|
| 335 |
|
|---|
| 336 |
void SetAutorun( bool on ) |
|---|
| 337 |
{ |
|---|
| 338 |
RegKey key(HKEY_CURRENT_USER); |
|---|
| 339 |
key.OpenKey( registrykey, KEY_ALL_ACCESS ); |
|---|
| 340 |
if (on) { |
|---|
| 341 |
key.SetValue( AUTORUN, "true" ); |
|---|
| 342 |
} else { |
|---|
| 343 |
key.SetValue( AUTORUN, "false" ); |
|---|
| 344 |
} |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
typedef enum VERSION_AGE { NO_VER, OLDER_VER, CURRENT_VER, NEWER_VER }; |
|---|
| 348 |
|
|---|
| 349 |
VERSION_AGE CheckInstalledVersion() |
|---|
| 350 |
{ |
|---|
| 351 |
RegKey hkcu(HKEY_LOCAL_MACHINE) ; |
|---|
| 352 |
if (!hkcu.OpenKey( registrykey, KEY_READ )) { |
|---|
| 353 |
return NO_VER; |
|---|
| 354 |
} |
|---|
| 355 |
string verstring = hkcu.QueryValue( "DLLVersion" ); |
|---|
| 356 |
|
|---|
| 357 |
int installed = atoi( verstring.c_str() ); |
|---|
| 358 |
int current = atoi( SWISHCTL_VERSION ); |
|---|
| 359 |
if ( !installed ) { |
|---|
| 360 |
return NO_VER; |
|---|
| 361 |
} else if (installed < current) { |
|---|
| 362 |
return OLDER_VER; |
|---|
| 363 |
} else if (installed == current) { |
|---|
| 364 |
return CURRENT_VER; |
|---|
| 365 |
} else { |
|---|
| 366 |
return NEWER_VER; |
|---|
| 367 |
} |
|---|
| 368 |
} |
|---|
| 369 |
|
|---|
| 370 |
bool AllowAutorun() |
|---|
| 371 |
{ |
|---|
| 372 |
|
|---|
| 373 |
RegKey hkcu(HKEY_CURRENT_USER) ; |
|---|
| 374 |
if (hkcu.OpenKey( registrykey, KEY_READ )) { |
|---|
| 375 |
string autorun = hkcu.QueryValue( AUTORUN ); |
|---|
| 376 |
if ( autorun != "true") { |
|---|
| 377 |
return false; |
|---|
| 378 |
} |
|---|
| 379 |
} |
|---|
| 380 |
return true; |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
DWORD FindFile (char *filename, CDirectory &curdir, CDirectory &destdir) |
|---|
| 384 |
{ |
|---|
| 385 |
CWinDirectory win; |
|---|
| 386 |
unsigned int curdirsize = curdir.getSize(); |
|---|
| 387 |
unsigned int destdirsize = destdir.getSize(); |
|---|
| 388 |
DWORD result = VerFindFile( VFFF_ISSHAREDFILE, |
|---|
| 389 |
filename, win.getBuffer(), win.getBuffer(), |
|---|
| 390 |
curdir.getBuffer(), &curdirsize , |
|---|
| 391 |
destdir.getBuffer(), &destdirsize); |
|---|
| 392 |
|
|---|
| 393 |
return result; |
|---|
| 394 |
} |
|---|
| 395 |
|
|---|
| 396 |
bool ConfirmDiskAccessRetry(const char * windir) |
|---|
| 397 |
{ |
|---|
| 398 |
char *buff[256] ; |
|---|
| 399 |
sprintf( (char *) buff, |
|---|
| 400 |
"An error occured trying to write to your Windows drive " |
|---|
| 401 |
"you don't appear to have the correct access priviledges " |
|---|
| 402 |
"to write to %s, are you sure you want to replace the file?", |
|---|
| 403 |
windir |
|---|
| 404 |
); |
|---|
| 405 |
|
|---|
| 406 |
int choice = MessageBox( |
|---|
| 407 |
NULL, |
|---|
| 408 |
(char *) buff, "Swish Control Installation", |
|---|
| 409 |
MB_YESNO | MB_DEFBUTTON2 | MB_ICONINFORMATION ); |
|---|
| 410 |
return ( choice == IDYES ) ; |
|---|
| 411 |
} |
|---|
| 412 |
|
|---|
| 413 |
bool NoSpaceConfirmRetry() |
|---|
| 414 |
{ |
|---|
| 415 |
int choice = MessageBox( |
|---|
| 416 |
NULL, |
|---|
| 417 |
"Your Windows drive appears to be out of disk space" |
|---|
| 418 |
" - try emptying your recycle bin or deleting some files " |
|---|
| 419 |
"and try again...", |
|---|
| 420 |
"Swish Control Installation", |
|---|
| 421 |
MB_RETRYCANCEL | MB_DEFBUTTON2 | MB_ICONINFORMATION ); |
|---|
| 422 |
return ( choice == IDRETRY ) ; |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
bool InUseConfirmRetry(const char * filename) |
|---|
| 426 |
{ |
|---|
| 427 |
char *buff[256] ; |
|---|
| 428 |
sprintf( (char *) buff, |
|---|
| 429 |
"A file (%s) is in use, please close any open applications and retry.", |
|---|
| 430 |
filename |
|---|
| 431 |
); |
|---|
| 432 |
|
|---|
| 433 |
int choice = MessageBox( |
|---|
| 434 |
NULL, |
|---|
| 435 |
(char *) buff, "Swish Control Installation", |
|---|
| 436 |
MB_RETRYCANCEL | MB_DEFBUTTON2 | MB_ICONINFORMATION ); |
|---|
| 437 |
return ( choice == IDRETRY ) ; |
|---|
| 438 |
} |
|---|
| 439 |
|
|---|
| 440 |
bool ConfirmOverwriteOlder(const char * filename) |
|---|
| 441 |
{ |
|---|
| 442 |
char *buff[256] ; |
|---|
| 443 |
sprintf( (char *) buff, |
|---|
| 444 |
"An newer version of the file (%s) is already installed " |
|---|
| 445 |
"are you sure you want to overwrite it?", |
|---|
| 446 |
filename |
|---|
| 447 |
); |
|---|
| 448 |
int choice = MessageBox( |
|---|
| 449 |
NULL, |
|---|
| 450 |
(char *) buff, |
|---|
| 451 |
"Swish Control Installation", |
|---|
| 452 |
MB_YESNO | MB_ICONASTERISK | MB_DEFBUTTON2 ); |
|---|
| 453 |
return ( choice == IDYES ); |
|---|
| 454 |
|
|---|
| 455 |
} |
|---|
| 456 |
|
|---|
| 457 |
void MissingSourceFile( char *filename, char * sourcedir ) |
|---|
| 458 |
{ |
|---|
| 459 |
char *buff[256] ; |
|---|
| 460 |
sprintf( (char *) buff, |
|---|
| 461 |
"A required file (%s) is missing from the setup directory (%s). " |
|---|
| 462 |
"Please obtain an original copy of all the setup files " |
|---|
| 463 |
" and rerun Setup.", |
|---|
| 464 |
filename, sourcedir |
|---|
| 465 |
); |
|---|
| 466 |
MessageBox( |
|---|
| 467 |
NULL, |
|---|
| 468 |
(char *) buff, |
|---|
| 469 |
"Swish Control Installation", |
|---|
| 470 |
MB_OK | MB_ICONASTERISK ); |
|---|
| 471 |
|
|---|
| 472 |
} |
|---|
| 473 |
|
|---|
| 474 |
bool InstallFile (char * filename, |
|---|
| 475 |
CDirectory &SourceDir, CDirectory &DestDir) |
|---|
| 476 |
{ |
|---|
| 477 |
CPath TempFile; |
|---|
| 478 |
unsigned int buffsize = TempFile.getSize(); |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
DWORD flags = VIFF_DONTDELETEOLD; |
|---|
| 482 |
DWORD result = VerInstallFile( |
|---|
| 483 |
flags, |
|---|
| 484 |
filename, |
|---|
| 485 |
filename, |
|---|
| 486 |
SourceDir.getBuffer(), |
|---|
| 487 |
DestDir.getBuffer(), |
|---|
| 488 |
NULL, |
|---|
| 489 |
TempFile.getBuffer(), |
|---|
| 490 |
|
|---|
| 491 |
&buffsize |
|---|
| 492 |
); |
|---|
| 493 |
|
|---|
| 494 |
while ( result ) { |
|---|
| 495 |
flags = VIFF_DONTDELETEOLD; |
|---|
| 496 |
bool retry = false; |
|---|
| 497 |
|
|---|
| 498 |
if ( (result & VIF_FILEINUSE) && InUseConfirmRetry(filename) ) |
|---|
| 499 |
{ |
|---|
| 500 |
retry = true; |
|---|
| 501 |
} |
|---|
| 502 |
else if ( result & VIF_CANNOTREADSRC ) |
|---|
| 503 |
{ |
|---|
| 504 |
MissingSourceFile(filename, SourceDir.getBuffer()); |
|---|
| 505 |
} |
|---|
| 506 |
else if ( (result & VIF_SRCOLD ) && ConfirmOverwriteOlder(filename) ) |
|---|
| 507 |
{ |
|---|
| 508 |
flags |= VIFF_FORCEINSTALL; |
|---|
| 509 |
retry = true; |
|---|
| 510 |
|
|---|
| 511 |
} |
|---|
| 512 |
else if ( result & VIF_TEMPFILE ) { |
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
} else if ( result |
|---|
| 516 |
& (VIF_SHARINGVIOLATION|VIF_WRITEPROT|VIF_ACCESSVIOLATION) ) |
|---|
| 517 |
{ |
|---|
| 518 |
if ( ConfirmDiskAccessRetry( DestDir.getBuffer() ) ) { |
|---|
| 519 |
retry = true; |
|---|
| 520 |
flags |= VIFF_FORCEINSTALL; |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
} else if ( (result & VIF_OUTOFSPACE) && NoSpaceConfirmRetry() ) { |
|---|
| 524 |
retry = true; |
|---|
| 525 |
} |
|---|
| 526 |
if ( ! retry ) break; |
|---|
| 527 |
|
|---|
| 528 |
result = VerInstallFile( |
|---|
| 529 |
flags, filename, filename, |
|---|
| 530 |
SourceDir.getBuffer(), DestDir.getBuffer(), |
|---|
| 531 |
NULL, TempFile.getBuffer(), &buffsize); |
|---|
| 532 |
|
|---|
| 533 |
} |
|---|
| 534 |
return (result == 0); |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
void ShowRegistrationFailed(HWND hwnd) |
|---|
| 538 |
{ |
|---|
| 539 |
MessageBox( |
|---|
| 540 |
hwnd, |
|---|
| 541 |
"An (OLE) error occured registering the search application " |
|---|
| 542 |
"on your system. Setup cannot continue.", |
|---|
| 543 |
"Swish Control Installation", |
|---|
| 544 |
MB_OK | MB_ICONASTERISK ); |
|---|
| 545 |
|
|---|
| 546 |
} |
|---|
| 547 |
|
|---|
| 548 |
bool Uninstall( HWND hwnd ) |
|---|
| 549 |
{ |
|---|
| 550 |
CDirectory curdir, destdir; |
|---|
| 551 |
FindFile( installdlls[SWISHCTL], curdir, destdir ); |
|---|
| 552 |
|
|---|
| 553 |
CPath swishctlpath = curdir + installdlls[SWISHCTL]; |
|---|
| 554 |
|
|---|
| 555 |
unregisterOleDll(swishctlpath.getBuffer()); |
|---|
| 556 |
UnregisterUninstall(); |
|---|
| 557 |
|
|---|
| 558 |
BOOL result = DeleteFile( swishctlpath.getBuffer() ); |
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
swishctlpath = curdir + installdlls[PCRE]; |
|---|
| 562 |
DeleteFile( swishctlpath.getBuffer() ); |
|---|
| 563 |
swishctlpath = curdir + installdlls[PCRE]; |
|---|
| 564 |
DeleteFile( swishctlpath.getBuffer() ); |
|---|
| 565 |
|
|---|
| 566 |
DeleteShortcuts("index.lnk", "ACC Index"); |
|---|
| 567 |
|
|---|
| 568 |
if (result) { |
|---|
| 569 |
|
|---|
| 570 |
MessageBox( hwnd, |
|---|
| 571 |
"ACC Index Search Tool has been uninstalled", |
|---|
| 572 |
"Swish Control Setup", |
|---|
| 573 |
MB_OK |
|---|
| 574 |
); |
|---|
| 575 |
} else { |
|---|
| 576 |
MessageBox( hwnd, |
|---|
| 577 |
"ACC Index Search Tool has been uninstalled" |
|---|
| 578 |
" but some files could not be deleted perhaps" |
|---|
| 579 |
" they have been removed already." , |
|---|
| 580 |
"Swish Control Setup", |
|---|
| 581 |
MB_OK |
|---|
| 582 |
); |
|---|
| 583 |
} |
|---|
| 584 |
|
|---|
| 585 |
return TRUE; |
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
bool Install( HWND hwnd ) |
|---|
| 590 |
{ |
|---|
| 591 |
CDirectory curdir, destdir; |
|---|
| 592 |
CAppDirectory sourcedir(SetupApp::getInstance()); |
|---|
| 593 |
|
|---|
| 594 |
FindFile( installdlls[SWISHCTL], curdir, destdir ); |
|---|
| 595 |
if (!InstallFile( installdlls[SWISHCTL], sourcedir, destdir )) return false; |
|---|
| 596 |
|
|---|
| 597 |
CPath swishctlpath = destdir + installdlls[SWISHCTL]; |
|---|
| 598 |
|
|---|
| 599 |
if (!registerOleDll( swishctlpath.getBuffer())) |
|---|
| 600 |
{ |
|---|
| 601 |
ShowRegistrationFailed(hwnd); |
|---|
| 602 |
return false; |
|---|
| 603 |
} |
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
if ( ! RegisterIndexFile(sourcedir.getBuffer(), "docs.idx") ) { |
|---|
| 607 |
MessageBox( hwnd, |
|---|
| 608 |
"Setup was not able to write configuration details to " |
|---|
| 609 |
"your system registry. Please try running setup again", |
|---|
| 610 |
"Swish Control Setup Error", |
|---|
| 611 |
MB_OK | MB_ICONEXCLAMATION |
|---|
| 612 |
); |
|---|
| 613 |
return false; |
|---|
| 614 |
} |
|---|
| 615 |
FindFile( installdlls[PCRE], curdir, destdir ); |
|---|
| 616 |
if (!InstallFile( installdlls[PCRE], sourcedir, destdir )) return false; |
|---|
| 617 |
|
|---|
| 618 |
FindFile( installdlls[ZLIB], curdir, destdir ); |
|---|
| 619 |
if(!InstallFile( installdlls[ZLIB], sourcedir, destdir )) return false; |
|---|
| 620 |
|
|---|
| 621 |
AddShortcut(sourcedir); |
|---|
| 622 |
|
|---|
| 623 |
CPath uninstaller = sourcedir + "setup.exe /u"; |
|---|
| 624 |
RegisterUninstall(uninstaller.getBuffer()); |
|---|
| 625 |
|
|---|
| 626 |
MessageBox( hwnd, |
|---|
| 627 |
"Setup Complete", |
|---|
| 628 |
"Swish Control Setup", |
|---|
| 629 |
MB_OK | MB_ICONINFORMATION |
|---|
| 630 |
); |
|---|
| 631 |
return true; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
#if 0 |
|---|
| 636 |
void DoTests() |
|---|
| 637 |
{ |
|---|
| 638 |
char curdir[_MAX_PATH]; |
|---|
| 639 |
char destdir[_MAX_PATH]; |
|---|
| 640 |
UINT curdirlen = _MAX_PATH; |
|---|
| 641 |
UINT destdirlen = _MAX_PATH; |
|---|
| 642 |
|
|---|
| 643 |
AppDir appdir; |
|---|
| 644 |
char *ad = appdir.c_str(); |
|---|
| 645 |
|
|---|
| 646 |
FilePath fp("C:\\CRAP", _MAX_PATH); |
|---|
| 647 |
fp = fp + (const char *)"crap.exe"; |
|---|
| 648 |
|
|---|
| 649 |
FilePath fp2; |
|---|
| 650 |
|
|---|
| 651 |
fp2 = fp2 + (const char *)"whatever"; |
|---|
| 652 |
|
|---|
| 653 |
fp2 = fp + fp2; |
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
FilePath fp3(NULL, _MAX_PATH); |
|---|
| 657 |
DWORD copied = GetModuleFileName( SetupApp::getInstance(), |
|---|
| 658 |
fp3.c_str(), fp3.getSize()); |
|---|
| 659 |
|
|---|
| 660 |
string fname(_MAX_PATH, '\0'); |
|---|
| 661 |
|
|---|
| 662 |
copied = GetModuleFileName( SetupApp::getInstance(), |
|---|
| 663 |
(char *)fname.c_str(), fname.length()); |
|---|
| 664 |
} |
|---|
| 665 |
#endif |
|---|
| 666 |
|
|---|
| 667 |
bool ConfirmUpgrade() |
|---|
| 668 |
{ |
|---|
| 669 |
int choice = MessageBox( |
|---|
| 670 |
GetDesktopWindow(), |
|---|
| 671 |
"An older version of the search tool is installed." |
|---|
| 672 |
" Would you like to upgrade?", |
|---|
| 673 |
"Swish Control Installation", |
|---|
| 674 |
MB_YESNO | MB_ICONQUESTION ); |
|---|
| 675 |
return ( choice == IDYES ); |
|---|
| 676 |
} |
|---|
| 677 |
|
|---|
| 678 |
BOOL LaunchSearchPage( ) |
|---|
| 679 |
{ |
|---|
| 680 |
CAppDirectory appdir( SetupApp::getInstance()); |
|---|
| 681 |
CPath indexfile = appdir + "index.htm"; |
|---|
| 682 |
return LaunchUrl( NULL, indexfile.getBuffer() ); |
|---|
| 683 |
|
|---|
| 684 |
} |
|---|
| 685 |
|
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
int APIENTRY WinMain(HINSTANCE hInstance, |
|---|
| 692 |
HINSTANCE hPrevInstance, |
|---|
| 693 |
LPSTR lpCmdLine, |
|---|
| 694 |
int nCmdShow) |
|---|
| 695 |
{ |
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
SetupApp _app( hInstance ); |
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
if ( strstr( lpCmdLine, "/U" ) || strstr( lpCmdLine, "/u" )) { |
|---|
| 706 |
return Uninstall(NULL); |
|---|
| 707 |
} |
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
if ( strstr( lpCmdLine, "/F" ) |
|---|
| 711 |
|| strstr( lpCmdLine, "/f" ) |
|---|
| 712 |
|| !AppIsRegistered() ) |
|---|
| 713 |
{ |
|---|
| 714 |
if( ShowInstallDialog() ) { |
|---|
| 715 |
LaunchSearchPage (); |
|---|
| 716 |
} |
|---|
| 717 |
return 0; |
|---|
| 718 |
} |
|---|
| 719 |
|
|---|
| 720 |
switch ( CheckInstalledVersion() ) { |
|---|
| 721 |
case NO_VER: |
|---|
| 722 |
if( ShowInstallDialog() ) { |
|---|
| 723 |
LaunchSearchPage (); |
|---|
| 724 |
} |
|---|
| 725 |
break; |
|---|
| 726 |
case OLDER_VER: |
|---|
| 727 |
if ( !ConfirmUpgrade() ) break; |
|---|
| 728 |
|
|---|
| 729 |
if( ShowInstallDialog() ) { |
|---|
| 730 |
LaunchSearchPage (); |
|---|
| 731 |
} |
|---|
| 732 |
break; |
|---|
| 733 |
case CURRENT_VER: |
|---|
| 734 |
if ( AllowAutorun() ) |
|---|
| 735 |
{ |
|---|
| 736 |
LaunchSearchPage (); |
|---|
| 737 |
} |
|---|
| 738 |
break; |
|---|
| 739 |
case NEWER_VER: |
|---|
| 740 |
if ( AllowAutorun() ) |
|---|
| 741 |
{ |
|---|
| 742 |
LaunchSearchPage (); |
|---|
| 743 |
} |
|---|
| 744 |
break; |
|---|
| 745 |
} |
|---|
| 746 |
return 0; |
|---|
| 747 |
} |
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
LRESULT CALLBACK SetupHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) |
|---|
| 753 |
{ |
|---|
| 754 |
switch (message) |
|---|
| 755 |
{ |
|---|
| 756 |
case WM_INITDIALOG: |
|---|
| 757 |
return TRUE; |
|---|
| 758 |
|
|---|
| 759 |
case WM_COMMAND: |
|---|
| 760 |
if (LOWORD(wParam) == IDOK ) |
|---|
| 761 |
{ |
|---|
| 762 |
bool autorun = |
|---|
| 763 |
(IsDlgButtonChecked (hDlg, IDC_AUTORUN) != BST_CHECKED); |
|---|
| 764 |
|
|---|
| 765 |
SetAutorun( autorun ); |
|---|
| 766 |
|
|---|
| 767 |
Install( hDlg ); |
|---|
| 768 |
|
|---|
| 769 |
EndDialog(hDlg, (BOOL) autorun ); |
|---|
| 770 |
return TRUE; |
|---|
| 771 |
} |
|---|
| 772 |
else if ( LOWORD(wParam) == IDC_EXIT) |
|---|
| 773 |
{ |
|---|
| 774 |
EndDialog(hDlg, FALSE); |
|---|
| 775 |
return TRUE; |
|---|
| 776 |
} |
|---|
| 777 |
break; |
|---|
| 778 |
} |
|---|
| 779 |
return FALSE; |
|---|
| 780 |
} |
|---|
| 781 |
|
|---|
| 782 |
|
|---|