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

📄 os2setup.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1993-1998, 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.
*/

/* os2setup.c */
/* OS/2 installation program for GSview and Ghostscript */

#define INCL_DOS
#define INCL_WIN
#define INCL_GPI
#define INCL_DOSERRORS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <ctype.h>

#define IDOK DID_OK
#define IDYES MBID_YES
#define IDCANCEL MBID_CANCEL

#ifndef OS2
#define OS2
#endif
#define MAXSTR 256
#define LPSTR PCHAR

#include "gvcver.h"
#include "gvcbeta.h"
#include "gvcprf.h"
#include "gvcrc.h"
#include "os2setup.h"
#include "gvclang.h"
#include "setupc.h"



MRESULT EXPENTRY ModelessDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY MainDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);

HAB hab;
HINSTANCE phInstance;	/* = hab */
HMODULE hlanguage;
HWND hwnd_dlg;
char szUnzipDll[]="unzip2.dll";
char szIniName[]="gvpm.ini";

/* these should be removed */
char groupname[MAXSTR];
char groupfile[MAXSTR];

char no_error[] = "";
int emx;
int use_os2_fonts;

/* returns TRUE if language change successful */
BOOL
load_language(int language)
{   /* load language dependent resources */
char langdll[MAXSTR];
char buf[MAXSTR];
HMODULE hmodule;
APIRET rc;
    /* load language dependent resources */
    strcpy(langdll, sourcedir);
    strcat(langdll, "setup2");
    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:
	    hlanguage = 0;
	    return TRUE;
    }
    strcat(langdll, ".dll");
    rc = DosLoadModule((PBYTE)buf, sizeof(buf), (PCSZ)langdll, &hmodule);
    if (!rc) {
	hlanguage = hmodule;
	return TRUE;
    }

    hlanguage = 0;
    return FALSE;
}

MRESULT EXPENTRY 
LanguageDlgProc(HWND hwnd, ULONG mess, MPARAM mp1, MPARAM mp2)
{
    switch(mess) {
        case WM_COMMAND:
            switch(SHORT1FROMMP(mp1)) {
		case DID_CANCEL:
                case DID_OK:
                    WinDismissDlg(hwnd, 0);
                    break;
		case IDM_LANGEN:
		case IDM_LANGCT:
		case IDM_LANGDE:
		case IDM_LANGES:
		case IDM_LANGFR:
		case IDM_LANGGR:
		case IDM_LANGIT:
		case IDM_LANGNL:
		case IDM_LANGRU:
		case IDM_LANGSE:
		case IDM_LANGSK:
                    WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
            }
            break;
    }
    return WinDefDlgProc(hwnd, mess, mp1, mp2);
}

void 
check_language(void)
{
int language;
COUNTRYCODE pcc;
COUNTRYINFO pci;
ULONG pcbActual;
    pcc.country = 0;	/* ask about default country */
    pcc.codepage = 0;
    if (DosQueryCtryInfo(sizeof(pci), &pcc, &pci, &pcbActual) != 0)
	return;	/* give up */

   if (pcbActual == 0)
	return;

    if (  
	  !((pci.country == 99) || (pci.country == 61) ||
	    (pci.country == 44) || (pci.country == 1))
#ifdef BETA
	|| 1
#endif
       )
    {	/* language isn't English */
	language = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, LanguageDlgProc, hlanguage, IDD_LANG, NULL);
	switch (language) {
	    case IDM_LANGEN:
	    case IDM_LANGCT:
	    case IDM_LANGDE:
	    case IDM_LANGES:
	    case IDM_LANGFR:
	    case IDM_LANGGR:
	    case IDM_LANGIT:
	    case IDM_LANGNL:
	    case IDM_LANGRU:
	    case IDM_LANGSE:
	    case IDM_LANGSK:
		load_language(language);
	}
    }
}

int
dialog(int resource, PFNWP dlgproc)
{
    return WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, dlgproc, hlanguage, resource, 0);
}

int message_box(const char *str, int icon)
{
    return WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
                 (PCSZ)str, (PCSZ)szAppName, 0, icon);
}


int 
gs_chdir(char *dirname)
{
#ifdef __BORLANDC__
	if (isalpha(dirname[0]) && (dirname[1]==':'))
		(void) setdisk(toupper(dirname[0])-'A');
	if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
		chdir(dirname);
	return TRUE;
#else
#ifdef __IBMC__
	if (isalpha(dirname[0]) && (dirname[1]==':'))
	    if (_chdrive(toupper(dirname[0])-'A'+1))
		return -1;
	if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
	    return _chdir(dirname);
#else
	if (isalpha((int)(dirname[0])) && (dirname[1]==':'))
	    if (_chdrive(dirname[0]))
		return -1;
	return _chdir2(dirname);
#endif
#endif
}

int
load_string(int id, char *str, int len)
{
	return WinLoadString(hab, hlanguage, id, len, (PBYTE)str);
}

/* Update MLE to match twbuf */
void
gs_addmess_update(void)
{
IPT ipt = 0;
HWND hwndmess;
HWND hwnd_textwin = find_page_from_id(IDD_TEXTWIN)->hwnd;

    if (hwnd_textwin == (HWND)NULL)
	return;
    hwndmess = WinWindowFromID(hwnd_textwin, TEXTWIN_MLE);
    if (hwndmess == (HWND)NULL)
	return;

    WinEnableWindowUpdate(hwndmess, FALSE);
    WinSendMsg( hwndmess, MLM_DISABLEREFRESH, 0, 0);
    /* delete current contents */
    ipt = (IPT)WinSendMsg( hwndmess, MLM_QUERYTEXTLENGTH, 0, 0); /* get current length */
    WinSendMsg( hwndmess, MLM_SETSEL, (MPARAM)0, (MPARAM)ipt);
    WinSendMsg( hwndmess, MLM_CLEAR, (MPARAM)0, (MPARAM)0);
    /* add udpated buffer */
    ipt = 0;
    WinSendMsg(hwndmess, MLM_SETIMPORTEXPORT, (MPARAM)twbuf, (MPARAM)sizeof(twbuf));
    WinSendMsg( hwndmess, MLM_IMPORT, (MPARAM)&ipt, (MPARAM)twend);
    WinSendMsg( hwndmess, MLM_SETSEL, (MPARAM)twend, (MPARAM)twend);
    WinSendMsg( hwndmess, MLM_ENABLEREFRESH, 0, 0);
    WinEnableWindowUpdate(hwndmess, TRUE);
    WinInvalidateRect(hwndmess, (PRECTL)NULL, TRUE);
    WinUpdateWindow(hwndmess);
}


void
goto_page(HWND hwnd, int id)
{
WIZPAGE *page;
HWND hbutton;
    page = find_page_from_id(id);
    if (page) {
	WinShowWindow(hwnd, FALSE);		/* hide window */
	WinShowWindow(page->hwnd, TRUE);	/* show window */
	hwnd_current = page->hwnd;
	if (WinIsWindowEnabled(WinWindowFromID(page->hwnd, IDNEXT)))
	    hbutton = WinWindowFromID(page->hwnd, IDNEXT);
	else
	    hbutton = WinWindowFromID(page->hwnd, IDCANCEL);
	WinSendMsg(hbutton, BM_SETDEFAULT, (MPARAM)TRUE , (MPARAM)0);
	WinSetFocus(HWND_DESKTOP, hbutton);
	return;
    }
}

#pragma argsused
/* exit from program */
int
done(HWND hwnd)
{
    WinPostMsg(hwnd, WM_QUIT, (MPARAM)0, (MPARAM)0);
    return 0;
}

/* commence installation */
int
finish(HWND hwnd)
{
WIZPAGE *page;
char groupname[MAXSTR];
    page = find_page_from_id(IDD_GSVER);
    install_gsview = (BOOL)WinSendMsg( WinWindowFromID(page->hwnd, PARTIAL_GSVIEW),
	BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
    install_gs =     (BOOL)WinSendMsg( WinWindowFromID(page->hwnd, PARTIAL_GS),
	BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));

    /* assume gsver is already correct */

    page = find_page_from_id(IDD_CONFIG);
    install_autoexec = (BOOL)WinSendMsg( WinWindowFromID(page->hwnd, IDM_AUTOEXECBAT),
	BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
    install_autoexecbak = (BOOL)WinSendMsg( WinWindowFromID(page->hwnd, IDM_AUTOEXECBAK),
	BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
    /* assume destdir is already correct */

    page = find_page_from_id(IDD_FINISH);
    install_group = (BOOL)WinSendMsg( WinWindowFromID(page->hwnd, IDM_PROGMAN1),
	BM_QUERYCHECK, MPFROMLONG(0), MPFROMLONG(0));
    WinQueryWindowText( WinWindowFromID(page->hwnd, IDM_PROGMAN2), sizeof(groupname), (PBYTE)groupname);

    WinPostMsg(hwnd, WM_COMMAND, (MPARAM)IDFINISH, (MPARAM)0);
    return 0;
}



int
cleanup(void)
{
    return 0;
}


int
update_config(void)
{
FILE *infile, *outfile;
char inname[MAXSTR], outname[MAXSTR];
char line[1024];
char tempname[MAXSTR];
char buf[MAXSTR];
BOOL got_temp = FALSE;
BOOL changed = FALSE;
int i;
    
    strcpy(inname, bootdrive);
    strcat(inname, "\\config.sys");

    strcpy(tempname, bootdrive);
    strcat(tempname, "\\GSXXXXXX");
    if (mktemp(tempname) == (char *)NULL) {
	load_string(IDS_CANTCREATETEMPFILE, error_message, sizeof(error_message));
	return 1;
    }

    if ( (infile = fopen(inname, "r")) == (FILE *)NULL) {
	load_string(IDS_CANTOPENREAD, buf, sizeof(buf));
	sprintf(error_message, buf, inname);
	return 1;
    }
    if ( (outfile = fopen(tempname, "w")) == (FILE *)NULL)  {
	load_string(IDS_CANTOPENWRITE, buf, sizeof(buf));
	sprintf(error_message, buf, outname);
	return 1;
    }
    while (fgets(line, sizeof(line), infile)) {
	if (strnicmp(line, "SET TEMP=", 9)==0) {
	    /* it has been added recently */
	    got_temp = TRUE;
	}
        if (strncmp(line, "LIBPATH=", 8) == 0) {
	    if (!emx) {
		sprintf(line+strlen(line)-1, ";%s\\emx\\dll\n", bootdrive);
		changed = TRUE;
	    }
	}
        if (strncmp(line, "SET PATH=", 9) == 0) {
	    if (!emx) {
		sprintf(line+strlen(line)-1, ";%s\\emx\\bin\n", bootdrive);
		changed = TRUE;
	    }
	}
	fputs(line, outfile);
    }
    if (!got_temp) {
	sprintf(line, "SET TEMP=%s\\\n", bootdrive);
	changed = TRUE;
    }
    fputs(line, outfile);

    fclose(outfile);
    fclose(infile);

    if (!changed) {
	/* no changes were necessary, so bail out */
	unlink(tempname);
	return 0;
    }

    if (install_autoexecbak) {
	for (i=0; i<=999; i++) {
	    sprintf(outname, "%s\\config.%03d", bootdrive, i);
	    if ( (infile = fopen(outname, "r")) != (FILE *)NULL)
		fclose(infile);
	    else
		break;   /* found a suitable name */
	}
        if (rename(inname, outname)) {
	    load_string(IDS_ERRORRENAME, buf, sizeof(buf));
	    sprintf(error_message, buf, inname, outname);
	    return 1;
	}
	strcpy(autoexec_bak, outname);
    }
    else
	unlink(inname);

    if (rename(tempname, inname)) {
	load_string(IDS_ERRORRENAME, buf, sizeof(buf));
	sprintf(error_message, buf, tempname, inname);
	return 1;
    }

    return 0;
}

int
update_ini(char *ininame)
{
PROFILE *prf;
char buf[16];
char secver[64];
    prf = profile_open(ininame);
    if (prf == (PROFILE *)NULL) {
	char mess[MAXSTR];
	load_string(IDS_CANTOPENREAD, mess, sizeof(mess));
	sprintf(error_message, mess, ininame);

⌨️ 快捷键说明

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