⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winsetup.cpp

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* Copyright (C) 1993-2002, Ghostgum Software Pty Ltd.  All rights reserved.
  
  This file is part of GSview.
  
  This program is distributed with NO WARRANTY OF ANY KIND.  No author
  or distributor accepts any responsibility for the consequences of using it,
  or for whether it serves any particular purpose or works at all, unless he
  or she says so in writing.  Refer to the GSview Free Public Licence 
  (the "Licence") for full details.
  
  Every copy of GSview must include a copy of the Licence, normally in a 
  plain ASCII text file named LICENCE.  The Licence grants you the right 
  to copy, modify and redistribute GSview, but only under certain conditions 
  described in the Licence.  Among other things, the Licence requires that 
  the copyright notice and this notice be preserved on all copies.
*/

/* winsetup.cpp */
/* MS-Windows installation program for GSview */

#ifndef __WIN32__
#error Win16 is NOT supported.
#endif
// You also can't compile this with BC++ 4.5, because it
// doesn't include the explorer shell interface

#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#include <objbase.h>
#include <shlobj.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <direct.h>
#else
#include <dir.h>
#endif
#include <ctype.h>
#include <io.h>

#ifdef MAX_PATH
#define MAXSTR MAX_PATH
#else
#define MAXSTR 256
#endif

#include "dwinst.h"

extern "C" {
#include "gvcver.h"
#include "gvcbeta.h"
#include "gvwgsver.h"
int message_box(const char *str, int icon);
int load_string(int id, char *str, int len);
typedef HRESULT (WINAPI *PFN_SHGetFolderPath)(
  HWND hwndOwner,
  int nFolder,
  HANDLE hToken,
  DWORD dwFlags,
  LPSTR pszPath);

typedef BOOL (WINAPI *PFN_SHGetSpecialFolderPath)(
  HWND hwndOwner,
  LPTSTR lpszPath,
  int nFolder,
  BOOL fCreate);
}
#include "gvcrc.h"
#include "winsetup.h"
#include "gvclang.h"


#define UNINSTALLPROG "uninstgs.exe"

#ifdef _MSC_VER
#define _export
#endif


/////////////////////////////////
// Globals

CInstall cinst;

// TRUE = Place Start Menu items in All Users.
// FALSE = Current User
BOOL g_bUseCommon;

// TRUE = Destination is the same as Source, so don't copy files.
BOOL g_bNoCopy;

// Source directory, usually a temporary directory created by
// unzip self extractor.
CHAR g_szSourceDir[MAXSTR];

// Target directory for program
// Default loaded from resources
CHAR g_szTargetDir[MAXSTR];

// Target Group for shortcut.
// Default loaded from resources
CHAR g_szTargetGroup[MAXSTR];
// Create group if checkbox selected
BOOL g_bCreateFolder = TRUE;

// Register file associations for these
BOOL g_bAssocPS;
BOOL g_bAssocPDF;

// Setup application name, loaded from resources
CHAR g_szAppName[MAXSTR];

BOOL g_bInstallFonts = TRUE;
BOOL g_bAllUsers = FALSE;


HWND g_hMain = HWND_DESKTOP;		// Main install dialog
HWND g_hWndText;	// Install log dialog
HINSTANCE g_hInstance;
HINSTANCE g_hLanguage;


// If a directory is listed on the command line, g_bBatch will
// be TRUE and a silent install will occur.
BOOL g_bBatch = FALSE;	

BOOL g_bQuit = FALSE;	// TRUE = Get out of message loop.
BOOL g_bError = FALSE;	// TRUE = Install was not successful
int is_win32s;
int is_win4;
BOOL is_winnt = FALSE;	// Disable "All Users" if not NT.

BOOL install_autoexec= TRUE;		/* update autoexec.bat or config.sys */
BOOL install_autoexecbak = TRUE;	/* keep backup of old autoexec.bak */
char error_message[MAXSTR];
char get_string_answer[MAXSTR];
char autoexec_bak[MAXSTR];
BOOL installing;


// prototypes
BOOL init();
void check_language(void);
BOOL make_filelist(int argc, char *argv[]);
BOOL CALLBACK _export ModelessDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK _export MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void gs_addmess_update(void);



char szIniName[]="gsview32.ini";
const char * const bootdrive = "c:";

/* early versions of Win32s don't support lstrcpyn */
#undef lstrcpyn
#define lstrcpyn(d,s,n) strncpy(d,s,n)

HWND hwnd_current;
HWND hwnd_previous;

typedef struct tagWIZPAGE {
   int id;		/* resource ID */
   int prev;		/* resource id of previous page */
   int next;		/* resource id of next page */
   int (*func)(HWND);	/* function to run on exit from page */
   HWND hwnd;		/* window handle of dialog */
} WIZPAGE;

WIZPAGE * find_page_from_id(int id);
void next_page(HWND hwnd);
int init_temp(void);
int check_dir(HWND hwnd);
int make_dir(HWND hwnd);
int done(HWND hwnd);
int finish(HWND hwnd);
void goto_page(HWND hwnd, int id);
int gs_chdir(char *dirname);
BOOL update_config(void);
BOOL update_ini(char *ininame);

WIZPAGE pages[]={
	{IDD_INTRO, IDD_INTRO, IDD_COPYRIGHT, NULL, 0},
	{IDD_COPYRIGHT, IDD_INTRO, IDD_ASSOC, NULL, 0},
	{IDD_ASSOC, IDD_COPYRIGHT, IDD_DIR, NULL, 0},
	{IDD_DIR, IDD_ASSOC, IDD_MKDIR, check_dir, 0},
	{IDD_MKDIR, IDD_DIR, IDD_CONFIG, make_dir, 0},
	{IDD_CONFIG, IDD_DIR, IDD_FINISH, NULL, 0},
	{IDD_FINISH, IDD_DIR, IDD_TEXTWIN, finish, 0},
	{IDD_TEXTWIN, IDD_TEXTWIN, IDD_TEXTWIN, NULL, 0},
	{IDD_DONE, IDD_TEXTWIN, IDD_DONE, done, 0},
	{IDD_FAILED, IDD_TEXTWIN, IDD_FAILED, done, 0},
	{0, 0, 0, NULL, 0}
};


//////////////////////////////////////////////////////////////////////
// Entry point
//////////////////////////////////////////////////////////////////////

#ifdef __BORLANDC__
#pragma argsused
#endif
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
	g_hInstance = g_hLanguage = hInstance;

	// get source directory
	GetCurrentDirectory(sizeof(g_szSourceDir), g_szSourceDir);

	LoadString(g_hInstance, IDS_APPNAME, g_szAppName, sizeof(g_szAppName));
        if (!beta_warn()) {
	    if (!init()) {
		    MessageBox(HWND_DESKTOP, "Initialisation failed", 
			    g_szAppName, MB_OK);
		    return 1;
	    }
	    
	    if (!g_bBatch) {
		    while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
			    if (!IsDialogMessage(hwnd_current, &msg) && 
				    !IsDialogMessage(g_hMain, &msg)) {
				    TranslateMessage(&msg);
				    DispatchMessage(&msg);
			    }
		    }
		    DestroyWindow(g_hMain);
	    }
	}
	
	if (g_hLanguage != g_hInstance)
	    FreeLibrary(g_hLanguage);

	return (g_bError ? 1 : 0);
}



//////////////////////////////////////////////////////////////////////
// Browse dialog box 
//////////////////////////////////////////////////////////////////////

// nasty GLOBALS
char szFolderName[MAXSTR];
char szDirName[MAXSTR];

#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK 
DirDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	WORD notify_message;
	
	switch(message) {
	case WM_INITDIALOG:
		DlgDirList(hwnd, szDirName, IDC_FILES, IDC_FOLDER, 
			DDL_DRIVES | DDL_DIRECTORY);
		SetDlgItemText(hwnd, IDC_TARGET, szFolderName);
		return FALSE;
    case WM_COMMAND:
		notify_message = HIWORD(wParam);
		switch (LOWORD(wParam)) {
		case IDC_FILES:
			if (notify_message == LBN_DBLCLK) {
				CHAR szPath[MAXSTR];
				DlgDirSelectEx(hwnd, szPath, sizeof(szPath), IDC_FILES);
				DlgDirList(hwnd, szPath, IDC_FILES, IDC_FOLDER, 
					DDL_DRIVES | DDL_DIRECTORY);
			}
			return FALSE;
		case IDOK:
			GetDlgItemText(hwnd, IDC_FOLDER, szDirName, sizeof(szDirName));
			GetDlgItemText(hwnd, IDC_TARGET, szFolderName, sizeof(szFolderName));
			EndDialog(hwnd, TRUE);
			return TRUE;
		case IDCANCEL:
			EndDialog(hwnd, FALSE);
			return TRUE;
		}
		return FALSE;
	}
	return FALSE;
}


//////////////////////////////////////////////////////////////////////
// text window for log
//////////////////////////////////////////////////////////////////////
#define TWLENGTH 16384
#define TWSCROLL 1024
char twbuf[TWLENGTH];
int twend;

/* Add string for Ghostscript message window */
void
gs_addmess_count(const char *str, int count)
{
    const char *s;
    char *p;
    int i, lfcount;
    MSG msg;

    /* we need to add \r after each \n, so count the \n's */
    lfcount = 0;
    s = str;
    for (i=0; i<count; i++) {
	if (*s == '\n')
	    lfcount++;
	s++;
    }

    if (count + lfcount >= TWSCROLL)
	return;		/* too large */
    if (count + lfcount + twend >= TWLENGTH-1) {
	/* scroll buffer */
	twend -= TWSCROLL;
	memmove(twbuf, twbuf+TWSCROLL, twend);
    }
    p = twbuf+twend;
    for (i=0; i<count; i++) {
	if (*str == '\n') {
	    *p++ = '\r';
	}
	*p++ = *str++;
    }
    twend += (count + lfcount);
    *(twbuf+twend) = '\0';

	
    // Update the dialog box
    if (g_bBatch)
	    return;
    
    gs_addmess_update();
    while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) {
	    if (!IsDialogMessage(g_hWndText, &msg) && 
		    !IsDialogMessage(g_hMain, &msg)) {
		    TranslateMessage(&msg);
		    DispatchMessage(&msg);
	    }
    }
}

void
gs_addmess(const char *str)
{
    gs_addmess_count(str, strlen(str));
}

//////////////////////////////////////////////////////////////////////

int
message_box(const char *str, int icon)
{
    return MessageBox(g_hMain, str, g_szAppName, icon);
}

void
message_box(const char *str)
{
    MessageBox(g_hMain, str, g_szAppName, MB_OK);
}

//////////////////////////////////////////////////////////////////////

WIZPAGE *
find_page_from_id(int id)
{
WIZPAGE *page;
    for (page=pages; page->id; page++) {
	if (page->id == id)
	    return page;
    }
    return NULL;
}

void
next_page(HWND hwnd)
{
WIZPAGE *page;
int id;
    for (page=pages; page->id; page++) {
	if (page->hwnd == hwnd) {
	    if (page->func) {
		/* need to execute a function before continuing */
		if ( (id = page->func(hwnd)) != 0) {
		    goto_page(hwnd, id);
		    return;
		}
	    }
	    goto_page(hwnd, page->next);
	    return;
	}
    }
}

void
prev_page(HWND hwnd)
{
WIZPAGE *page;
    for (page=pages; page->id; page++) {
	if (page->hwnd == hwnd) {
	    goto_page(hwnd, page->prev);
	}
    }
}

int
init_temp(void)
{
    if (getenv("TEMP")) {
	install_autoexec = FALSE;
	return 0;	/* assume TEMP is in autoexec.bat */
    }
    return 1;
}


int
check_dir(HWND hwnd)
{
int i;
WIZPAGE *page;
    GetDlgItemText(hwnd, ID_ANSWER, g_szTargetDir, sizeof(g_szTargetDir));
    page = find_page_from_id(IDD_MKDIR);
    if (page)
	SetDlgItemText((page->hwnd), IDD_MKDIR_TEXT, g_szTargetDir);

    /* check if directory exists */
    i = strlen(g_szTargetDir) - 1;
    if ((i >= 2) && (g_szTargetDir[i] == '\\') )
       g_szTargetDir[i] = '\0';
    if (strlen(g_szTargetDir)==0)
	return IDD_DIR;

    if (!gs_chdir(g_szTargetDir)) {
	if (init_temp())
            return IDD_CONFIG;
	else
	    return IDD_FINISH;
    }

    /* if it does not, continue to IDD_MKDIR */
    return 0;
}

#ifdef __BORLANDC__
#pragma argsused
#endif
int
make_dir(HWND hwnd)
{
char buf[MAXSTR];
    if (cinst.MakeDir(g_szTargetDir)) {
	/* succeeded */
	if (init_temp())
            return 0;
	else
	    return IDD_FINISH;
    }

    /* failed */ 
    load_string(IDS_MKDIRFAIL, buf, sizeof(buf)-1);
    message_box(buf);
    return IDD_DIR;
}

void
centre_dialog(HWND hwnd)
{
    // centre dialog on screen
    int width = GetSystemMetrics(SM_CXFULLSCREEN);
    int height = GetSystemMetrics(SM_CYFULLSCREEN);
    RECT rect;
    GetWindowRect(hwnd, &rect);
    if (width / height >= 2)
	width = width / 2;	/* dual monitors */
    MoveWindow(hwnd, (width - (rect.right - rect.left))/2,
	    (height - (rect.bottom - rect.top))/2,
	    (rect.right - rect.left),
	    (rect.bottom - rect.top), FALSE);
}

int
dialog(int resource, DLGPROC dlgproc) 
{
int flag;
    flag = DialogBoxParam(g_hLanguage, MAKEINTRESOURCE(resource), g_hMain, dlgproc, (LPARAM)NULL);
    return flag;
}



/* change directory and drive */
int
gs_chdir(char *dirname)
{
    return !SetCurrentDirectory(dirname);
}

/* extern "C" */ int
load_string(int id, char *str, int len)
{
	return LoadString(g_hLanguage, id, str, len);
}

void
gs_addmess_update(void)
{
  HWND hwndmess = find_page_from_id(IDD_TEXTWIN)->hwnd;

  if (IsWindow(hwndmess)) {
    HWND hwndtext = GetDlgItem(hwndmess, TEXTWIN_MLE);
    DWORD linecount;
    SendMessage(hwndtext, WM_SETREDRAW, FALSE, 0);
    SetDlgItemText(hwndmess, TEXTWIN_MLE, twbuf);
    /* EM_SETSEL, followed by EM_SCROLLCARET doesn't work */
    linecount = SendDlgItemMessage(hwndmess, TEXTWIN_MLE, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
    SendDlgItemMessage(hwndmess, TEXTWIN_MLE, EM_LINESCROLL, (WPARAM)0, (LPARAM)linecount-14);
    SendMessage(hwndtext, WM_SETREDRAW, TRUE, 0);
    InvalidateRect(hwndtext, (LPRECT)NULL, TRUE);
    UpdateWindow(hwndtext);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -