📄 winsetup.cpp
字号:
gs_addmess("Failed to add Start Menu item\n");
return FALSE;
}
strcpy(szReadme, g_szTargetDir);
strcat(szReadme, "\\");
strcat(szReadme, cinst.GetMainDir());
strcat(szReadme, "\\Readme.htm");
sprintf(szDescription, "GSview Readme %s", GSVIEW_DOT_VERSION);
if (!cinst.StartMenuAdd(szDescription, szReadme, NULL)) {
gs_addmess("Failed to add Start Menu item\n");
return FALSE;
}
if (!cinst.StartMenuEnd()) {
gs_addmess("Failed to end Start Menu update\n");
return FALSE;
}
}
else {
gs_addmess("NOT Adding Start Menu items\n");
}
// consolidate logs into one uninstall file
if (cinst.MakeLog()) {
// add uninstall entry for "Add/Remove Programs"
gs_addmess("Adding uninstall program\n");
if (!cinst.WriteUninstall(UNINSTALLPROG, g_bNoCopy)) {
gs_addmess("Failed to write uninstall entry\n");
return FALSE;
}
}
else {
gs_addmess("Failed to write uninstall log\n");
// If batch install, files might be on a server
// in a write protected directory.
// Don't return an error for batch install.
if (g_bBatch)
return TRUE;
return FALSE;
}
get_inipath(buf, sizeof(buf)-1);
gs_addmess("Updating INI file ");
gs_addmess(buf);
gs_addmess("\n");
if (!update_ini(buf))
return FALSE;
if (g_bAllUsers) {
/* Write a gsview32.ini file to allow use of GSview
* by any user, not just the one who installed GSview.
* This INI file will cause auto-configuration if
* the user runs GSview for the first time, or was
* previously using a different version of GSview.
* If Ghostscript isn't already installed, don't bother.
*/
int gsver = 0;
int count;
int *ver;
count = 1;
get_gs_versions(&count);
if (count >= 1) {
ver = (int *)malloc((count+1)*sizeof(int));
if (ver == (int *)NULL)
return FALSE;
ver[0] = count+1;
if (get_gs_versions(ver)) {
for (int i=1; i<=ver[0]; i++) {
if (ver[i] > gsver)
gsver = ver[i];
}
}
free(ver);
}
if (gsver == 0) {
gs_addmess("If installing for all users, you must install Ghostscript first.\n");
}
else {
FILE *f;
char buf[256];
const char *p = cinst.GetUninstallName();
strcpy(szProgram, g_szTargetDir);
strcat(szProgram, "\\");
strcat(szProgram, cinst.GetMainDir());
strcat(szProgram, "\\");
strcat(szProgram, szIniName);
gs_addmess("Writing ");
gs_addmess(szProgram);
gs_addmess("\n");
if ((f = fopen(szProgram, "w")) == (FILE *)NULL) {
gs_addmess("Failed\n");
return FALSE;
}
/* Skip over "GSview 3.6" to get to version number */
while (*p && *p != ' ')
p++;
while (*p && *p == ' ')
p++;
fprintf(f, "[GSview-%s]\n", p);
fprintf(f, "Version=%s\n", p);
fprintf(f, "GSversion=%d\n", gsver);
if (!get_gs_string(gsver, "GS_DLL", buf, sizeof(buf))) {
return FALSE;
fclose(f);
}
fprintf(f, "GhostscriptDLL=%s\n", buf);
if (!get_gs_string(gsver, "GS_LIB", buf, sizeof(buf))) {
return FALSE;
fclose(f);
}
fprintf(f, "GhostscriptInclude=%s\n", buf);
fprintf(f, "GhostscriptOther=-dNOPLATFONTS -sFONTPATH=\042c:\\psfonts\042\n");
fprintf(f, "Configured=1\n");
fclose(f);
}
}
if (install_autoexec)
if (!update_config()) {
gs_addmess(error_message);
gs_addmess("\n");
return FALSE;
}
gs_addmess("Program install successful\n");
return TRUE;
}
// install program and files
BOOL
install_all()
{
gs_addmess("Source Directory=");
gs_addmess(g_szSourceDir);
gs_addmess("\n");
gs_addmess("Target Directory=");
gs_addmess(g_szTargetDir);
gs_addmess("\n");
gs_addmess("Target Shell Folder=");
gs_addmess(g_szTargetGroup);
gs_addmess("\n");
gs_addmess(g_bAllUsers ? " All users\n" : " Current user\n");
if (stricmp(g_szSourceDir, g_szTargetDir) == 0) {
// Don't copy files
if (!g_bBatch)
if (::MessageBox(g_hWndText, "Install location is the same as the current file location. No files will be copied.", g_szAppName, MB_OKCANCEL)
!= IDOK) {
return FALSE;
}
g_bNoCopy = TRUE;
}
if (g_bQuit)
return FALSE;
if (!install_prog()) {
cinst.CleanUp();
g_bError = TRUE;
return FALSE;
}
gs_addmess("Install successful\n");
// show start menu folder
if (!g_bBatch) {
char szFolder[MAXSTR];
szFolder[0] = '\0';
cinst.GetPrograms(g_bAllUsers, szFolder, sizeof(szFolder));
strcat(szFolder, "\\");
strcat(szFolder, g_szTargetGroup);
ShellExecute(HWND_DESKTOP, "open", szFolder,
NULL, NULL, SW_SHOWNORMAL);
}
#ifdef DEBUG
return FALSE;
#endif
return TRUE;
}
/* Simplified from gvwreg.cpp */
#define REG_KEY_NAME "Software\\Ghostgum\\GSview"
#define REGISTRATION_RECEIPT "Receipt"
#define REGISTRATION_NUMBER "Number"
#define REGISTRATION_NAME "Name"
BOOL
write_registration(unsigned int reg_receipt, unsigned int reg_number,
char *reg_name)
{
LONG rc;
HKEY hkey;
DWORD dwValue;
HKEY root;
char *name;
char *value;
root = HKEY_LOCAL_MACHINE;
name = REG_KEY_NAME;
value = NULL;
if ((rc = RegOpenKeyEx(root, name, 0,
KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS) {
/* failed to open key, so try to create it */
rc = RegCreateKey(root, name, &hkey);
}
if (rc == ERROR_SUCCESS) {
dwValue = (DWORD)reg_receipt;
value = REGISTRATION_RECEIPT;
rc = RegSetValueEx(hkey, value, 0, REG_DWORD,
(CONST BYTE *)&dwValue, sizeof(DWORD));
dwValue = (DWORD)(reg_number ^ 0xffff);
if (rc == ERROR_SUCCESS) {
value = REGISTRATION_NUMBER;
rc = RegSetValueEx(hkey, value, 0, REG_DWORD,
(CONST BYTE *)&dwValue, sizeof(DWORD));
}
if (rc == ERROR_SUCCESS) {
value = REGISTRATION_NAME;
rc = RegSetValueEx(hkey, value, 0, REG_SZ,
(CONST BYTE *)reg_name, lstrlen(reg_name)+1);
}
RegCloseKey(hkey);
}
if (rc != ERROR_SUCCESS) {
/*
registry_error(root, name, value, FALSE, rc);
*/
return FALSE;
}
return TRUE;
}
#ifndef CSIDL_PROGRAM_FILES
#define CSIDL_PROGRAM_FILES 0x0026
#endif
#ifndef CSIDL_FLAG_CREATE
#define CSIDL_FLAG_CREATE 0x8000
#endif
#ifndef SHGFP_TYPE_CURRENT
#define SHGFP_TYPE_CURRENT 0
#endif
BOOL
GetProgramFiles(LPTSTR path)
{
PFN_SHGetSpecialFolderPath PSHGetSpecialFolderPath = NULL;
PFN_SHGetFolderPath PSHGetFolderPath = NULL;
HMODULE hModuleShell32 = NULL;
HMODULE hModuleShfolder = NULL;
BOOL fOk = FALSE;
hModuleShfolder = LoadLibrary("shfolder.dll");
hModuleShell32 = LoadLibrary("shell32.dll");
if (hModuleShfolder) {
PSHGetFolderPath = (PFN_SHGetFolderPath)
GetProcAddress(hModuleShfolder, "SHGetFolderPathA");
if (PSHGetFolderPath) {
fOk = (PSHGetFolderPath(HWND_DESKTOP,
CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, path) == S_OK);
}
}
if (!fOk && hModuleShell32) {
PSHGetFolderPath = (PFN_SHGetFolderPath)
GetProcAddress(hModuleShell32, "SHGetFolderPathA");
if (PSHGetFolderPath) {
fOk = (PSHGetFolderPath(HWND_DESKTOP,
CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, path) == S_OK);
}
}
if (!fOk && hModuleShell32) {
PSHGetSpecialFolderPath = (PFN_SHGetSpecialFolderPath)
GetProcAddress(hModuleShell32, "SHGetSpecialFolderPathA");
if (PSHGetSpecialFolderPath) {
fOk = PSHGetSpecialFolderPath(HWND_DESKTOP, path,
CSIDL_PROGRAM_FILES, TRUE);
}
}
if (!fOk) {
/* If all else fails (probably Win95), try the registry */
LONG rc;
HKEY hkey;
DWORD cbData;
DWORD keytype;
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hkey);
if (rc == ERROR_SUCCESS) {
cbData = MAX_PATH;
keytype = REG_SZ;
if (rc == ERROR_SUCCESS)
rc = RegQueryValueEx(hkey, "ProgramFilesDir", 0, &keytype,
(LPBYTE)path, &cbData);
RegCloseKey(hkey);
}
fOk = (rc == ERROR_SUCCESS);
}
return fOk;
}
BOOL
init()
{
DWORD dwVersion = GetVersion();
char *szRegName = NULL;
int nRegReceipt = 0;
int nRegNumber = 0;
/* find out if we are running under Win32s */
/* Win32s */
if ( ((HIWORD(dwVersion) & 0x8000)!=0) &&
((HIWORD(dwVersion) & 0x4000)==0) )
is_win32s = TRUE;
/* Windows 4.0 */
if (LOBYTE(LOWORD(dwVersion)) >= 4)
is_win4 = TRUE;
/* Windows NT */
if ( (HIWORD(dwVersion) & 0x8000) == 0)
is_winnt = TRUE;
if (is_winnt)
g_bAllUsers = TRUE;
// load strings
LoadString(g_hInstance, IDS_TARGET_GROUP,
g_szTargetGroup, sizeof(g_szTargetGroup));
// other defaults
g_bAssocPS = TRUE;
g_bAssocPDF = FALSE;
if (LOBYTE(LOWORD(dwVersion)) < 4) {
MessageBox(HWND_DESKTOP,
"This install program needs Windows 4.0 or later",
g_szAppName, MB_OK);
return FALSE;
}
cinst.SetMessageFunction(message_box);
#define MAXCMDTOKENS 128
int argc;
LPSTR argv[MAXCMDTOKENS];
LPSTR p;
char command[256];
char *args;
char *d, *e;
int i;
p = GetCommandLine();
argc = 0;
args = (char *)malloc(lstrlen(p)+1);
if (args == (char *)NULL)
return 1;
// Parse command line handling quotes.
d = args;
while (*p) {
// for each argument
if (argc >= MAXCMDTOKENS - 1)
break;
e = d;
while ((*p) && (*p != ' ')) {
if (*p == '\042') {
// Remove quotes, skipping over embedded spaces.
// Doesn't handle embedded quotes.
p++;
while ((*p) && (*p != '\042'))
*d++ =*p++;
}
else
*d++ = *p;
if (*p)
p++;
}
*d++ = '\0';
argv[argc++] = e;
while ((*p) && (*p == ' '))
p++; // Skip over trailing spaces
}
argv[argc] = NULL;
if (strlen(argv[0]) == 0) {
GetModuleFileName(g_hInstance, command, sizeof(command)-1);
argv[0] = command;
}
if ((argc > 2) && (strcmp("-filelist", argv[1])==0)) {
// Probably creating filelist.txt
return make_filelist(argc, argv);
}
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-name") == 0) {
i++;
szRegName = argv[i];
}
else if (strcmp(argv[i], "-number") == 0) {
char *n;
i++;
n = argv[i];
while (*n && *n != '-')
n++;
if (*n == '-')
n++;
nRegReceipt = atoi(argv[i]);
nRegNumber = atoi(n);
}
else {
// Directory specified, so batch mode requested
strncpy(g_szTargetDir, argv[i], sizeof(g_szTargetDir));
g_bBatch = TRUE;
init_temp(); /* find out if TEMP is defined */
}
}
if (szRegName && nRegReceipt)
write_registration(nRegReceipt, nRegNumber, szRegName);
if (g_bBatch) {
if (!install_all()) {
// display log showing error
g_bBatch = FALSE;
create_dialog();
goto_page(hwnd_current, IDD_TEXTWIN);
WIZPAGE *page = find_page_from_id(IDD_TEXTWIN);
page->next = IDD_FAILED; /* KLUDGE */
EnableWindow(GetDlgItem(page->hwnd, IDNEXT), TRUE);
gs_addmess_update();
}
return TRUE;
}
// Interactive setup
check_language();
if (!GetProgramFiles(g_szTargetDir))
strcpy(g_szTargetDir, "C:\\Program Files");
strcat(g_szTargetDir, "\\");
LoadString(g_hInstance, IDS_TARGET_DIR,
g_szTargetDir+strlen(g_szTargetDir),
sizeof(g_szTargetDir)-strlen(g_szTargetDir));
// main dialog box
if (!create_dialog())
return FALSE;
return (g_hMain != (HWND)NULL); /* success */
}
/* returns TRUE if language change successful */
BOOL
load_language(int language)
{ /* load language dependent resources */
char langdll[MAXSTR];
HINSTANCE hInstance;
/* load language dependent resources */
strcpy(langdll, g_szSourceDir);
#ifdef DECALPHA
strcat(langdll, "\\setpda");
#else
strcat(langdll, "\\setp32");
#endif
switch (language) {
case IDM_LANGCT:
strcat(langdll, "ct");
break;
case IDM_LANGDE:
strcat(langdll, "de");
break;
case IDM_LANGES:
strcat(langdll, "es");
break;
case IDM_LANGFR:
strcat(langdll, "fr");
break;
case IDM_LANGGR:
strcat(langdll, "gr");
break;
case IDM_LANGIT:
strcat(langdll, "it");
break;
case IDM_LANGNL:
strcat(langdll, "nl");
break;
case IDM_LANGRU:
strcat(langdll, "ru");
break;
case IDM_LANGSE:
strcat(langdll, "se");
break;
case IDM_LANGSK:
strcat(langdll, "sk");
break;
case IDM_LANGEN:
default:
g_hLanguage = g_hInstance;
return TRUE;
}
strcat(langdll, ".dll");
hInstance = LoadLibrary(langdll);
if (hInstance >= (HINSTANCE)HINSTANCE_ERROR) {
g_hLanguage = hInstance;
return TRUE;
}
g_hLanguage = g_hInstance;
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -