📄 dwuninst.cpp
字号:
gs_addmess("\n");
if (RegSetValueEx(hkey, name, 0, REG_SZ, (CONST BYTE *)value,
strlen(value)+1) != ERROR_SUCCESS)
return FALSE;
}
}
if (hkey != HKEY_CLASSES_ROOT)
RegCloseKey(hkey);
return TRUE;
}
// recursive mkdir
// requires a full path to be specified, so ignores root \
// apart from root \, must not contain trailing \
// Examples:
// c:\ (OK, but useless)
// c:\gstools (OK)
// c:\gstools\ (incorrect)
// c:gstools (incorrect)
// gstools (incorrect)
// The following UNC names should work,
// but didn't under Win3.1 because gs_chdir wouldn't accept UNC names
// Needs to be tested under Windows 95.
// \\server\sharename\gstools (OK)
// \\server\sharename\ (OK, but useless)
//
BOOL MakeDir(char *dirname)
{
char newdir[MAXSTR];
char *p;
if (strlen(dirname) < 3)
return -1;
gs_addmess("Making Directory\n ");
gs_addmess(dirname);
gs_addmess("\n");
if (isalpha(dirname[0]) && dirname[1]==':' && dirname[2]=='\\') {
// drive mapped path
p = dirname+3;
}
else if (dirname[1]=='\\' && dirname[1]=='\\') {
// UNC path
p = strchr(dirname+2, '\\'); // skip servername
if (p == NULL)
return -1;
p++;
p = strchr(p, '\\'); // skip sharename
if (p == NULL)
return -1;
}
else {
// not full path so error
return -1;
}
while (1) {
strncpy(newdir, dirname, (int)(p-dirname));
newdir[(int)(p-dirname)] = '\0';
if (chdir(newdir)) {
if (mkdir(newdir))
return -1;
}
p++;
if (p >= dirname + strlen(dirname))
break; // all done
p = strchr(p, '\\');
if (p == NULL)
p = dirname + strlen(dirname);
}
return SetCurrentDirectory(dirname);
}
BOOL shell_new(void)
{
char *p, *q;
char group[MAXSTR];
// remove shell items added by Ghostscript
// We can only delete one group with this code
group[0] = '\0';
while (GetLine()) {
if (IsSection()) {
if (strlen(group) != 0) {
gs_addmess("Removing shell folder\n ");
gs_addmess(group);
gs_addmess("\n");
RemoveDirectory(group);
}
return TRUE;
}
p = strtok(szLine, "=");
q = strtok(NULL, "");
if (p == NULL) {
continue;
}
else if (strcmp(p, "Group")==0) {
if (q)
strncpy(group, q, sizeof(group)-1);
// defer this until we have remove contents
}
else if (strcmp(p, "Name") == 0) {
if (q) {
gs_addmess("Removing shell link\n ");
gs_addmess(q);
gs_addmess("\n");
DeleteFile(q);
}
}
}
return TRUE;
}
BOOL CreateShellLink(LPCSTR name, LPCSTR description, LPCSTR program,
LPCSTR arguments, LPCSTR directory, LPCSTR icon, int nIconIndex)
{
HRESULT hres;
IShellLink* psl;
// Ensure string is UNICODE.
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, name, -1, wsz, MAX_PATH);
// Save new shell link
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)&psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;
// Query IShellLink for the IPersistFile interface for
// saving the shell link in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres)) {
gs_addmess("Adding shell link\n ");
gs_addmess(name);
gs_addmess("\n");
// Set the path to the shell link target.
hres = psl->SetPath(program);
if (!SUCCEEDED(hres)) {
gs_addmess("SetPath failed!");
gError = TRUE;
}
// Set the description of the shell link.
hres = psl->SetDescription(description);
if (!SUCCEEDED(hres)) {
gs_addmess("SetDescription failed!");
gError = TRUE;
}
if ((arguments != (LPCSTR)NULL) && *arguments) {
// Set the arguments of the shell link target.
hres = psl->SetArguments(arguments);
if (!SUCCEEDED(hres)) {
gs_addmess("SetArguments failed!");
gError = TRUE;
}
}
if ((directory != (LPCSTR)NULL) && *directory) {
// Set the arguments of the shell link target.
hres = psl->SetWorkingDirectory(directory);
if (!SUCCEEDED(hres)) {
gs_addmess("SetWorkingDirectory failed!");
gError = TRUE;
}
}
if ((icon != (LPCSTR)NULL) && *icon) {
// Set the arguments of the shell link target.
hres = psl->SetIconLocation(icon, nIconIndex);
if (!SUCCEEDED(hres)) {
gs_addmess("SetIconLocation failed!");
gError = TRUE;
}
}
// Save the link via the IPersistFile::Save method.
hres = ppf->Save(wsz, TRUE);
// Release pointer to IPersistFile.
ppf->Release();
}
// Release pointer to IShellLink.
psl->Release();
}
return (hres == 0);
}
BOOL shell_old(void)
{
// Add shell items removed by Ghostscript
char *p, *q;
char name[MAXSTR];
char description[MAXSTR];
char program[MAXSTR];
char arguments[MAXSTR];
char directory[MAXSTR];
char icon[MAXSTR];
int nIconIndex;
// Remove shell items added by Ghostscript
name[0] = description[0] = program[0] = arguments[0]
= directory[0] = icon[0] = '\0';
nIconIndex = 0;
while (GetLine()) {
if (IsSection())
return TRUE;
p = strtok(szLine, "=");
q = strtok(NULL, "");
if (strlen(szLine) == 0) {
if (name[0] != '\0') {
// add start menu item
CreateShellLink(name, description, program, arguments,
directory, icon, nIconIndex);
}
name[0] = description[0] = program[0] = arguments[0]
= directory[0] = icon[0] = '\0';
nIconIndex = 0;
continue;
}
else if (p == (char *)NULL) {
continue;
}
else if (strcmp(p, "Group")==0) {
MakeDir(q);
}
else if (strcmp(p, "Name") == 0)
strncpy(name, q, sizeof(name)-1);
else if (strcmp(p, "Description") == 0)
strncpy(description, q, sizeof(description)-1);
else if (strcmp(p, "Program") == 0)
strncpy(program, q, sizeof(program)-1);
else if (strcmp(p, "Arguments") == 0)
strncpy(arguments, q, sizeof(arguments)-1);
else if (strcmp(p, "Directory") == 0)
strncpy(directory, q, sizeof(directory)-1);
else if (strcmp(p, "IconLocation") == 0)
strncpy(icon, q, sizeof(icon)-1);
else if (strcmp(p, "IconIndex") == 0)
nIconIndex = atoi(q);
}
return TRUE;
}
#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK _export
RemoveDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
SetWindowText(hwnd, szTitle);
if (bSilent)
PostMessage(hwnd, WM_COMMAND, IDOK, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_DONE:
// delete registry entries for uninstall
if (is_win4) {
HKEY hkey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
UNINSTALLKEY, 0, KEY_ALL_ACCESS, &hkey)
== ERROR_SUCCESS) {
RegDeleteKey(hkey, szTitle);
RegCloseKey(hkey);
}
}
SetWindowText(hText1, "Uninstall successful");
SetWindowText(hText2, "");
EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE);
SetDlgItemText(hwnd, IDCANCEL, "Exit");
SetFocus(GetDlgItem(hwnd, IDCANCEL));
if (bSilent)
PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
return TRUE;
case IDOK:
// Start removal
EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_PRESSOK), FALSE);
while (!bQuit) {
do_message();
if (!ReadSection()) {
SetWindowText(hText1, "Uninstall FAILED");
SetWindowText(hText2, "");
EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), TRUE);
SetDlgItemText(hwnd, IDCANCEL, "Exit");
SetFocus(GetDlgItem(hwnd, IDCANCEL));
bQuit = TRUE;
}
}
return TRUE;
case IDCANCEL:
bQuit = TRUE;
DestroyWindow(hwnd);
hDlgModeless = 0;
return TRUE;
}
case WM_CLOSE:
DestroyWindow(hwnd);
hDlgModeless = 0;
return TRUE;
}
return FALSE;
}
void
do_message(void)
{
MSG msg;
while (hDlgModeless && PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) {
if ((hDlgModeless == 0) || !IsDialogMessage(hDlgModeless, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
BOOL
init(void)
{
DWORD version = GetVersion();
char *p, *s;
int len;
BOOL inquote = FALSE;
// get location of uninstall log from command line as argv[1]
p = GetCommandLine();
s = p;
if (*s == '\042') {
// skip over program name
s++;
while (*s && *s!='\042')
s++;
if (*s)
s++;
}
else if (*s != ' ') {
// skip over program name
s++;
while (*s && *s!=' ')
s++;
if (*s)
s++;
}
while (*s && *s==' ')
s++;
if (*s == '\042') {
s++;
inquote = TRUE;
}
p = s;
if (inquote) {
while (*s && (*s != '\042'))
s++;
}
else {
while (*s && (*s != ' '))
s++;
}
len = s - p;
strncpy(szLogFile, p, min(len, sizeof(szLogFile)-1));
szLogFile[len] = '\0';
if (inquote && (*s == '\042')) {
s++;
inquote = FALSE;
}
if (strlen(szLogFile) == 0) {
message_box("Usage: uninstgs logfile.txt [-q]",
"GSview Uninstall", MB_OK);
return FALSE;
}
while (*s && *s==' ')
s++;
if (strncmp(s, "-q", 2) == 0)
bSilent = TRUE;
// read first few lines of file to get title
fLog = fopen(szLogFile, "r");
if (fLog == (FILE *)NULL) {
message_box(szLogFile, "Can't find file", MB_OK);
return FALSE;
}
GetLine();
if (!IsSection()) {
message_box(szLogFile, "Not valid uninstall log", MB_OK);
return FALSE;
}
GetLine();
if (strcmp(szLine, "UninstallName") != 0) {
message_box(szLogFile, "Not valid uninstall log", MB_OK);
return FALSE;
}
GetLine();
strcpy(szTitle, szLine);
NextSection();
if (LOBYTE(LOWORD(version)) >= 4)
is_win4 = TRUE;
return TRUE;
}
#ifdef __BORLANDC__
#pragma argsused
#endif
int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
MSG msg;
phInstance = hInstance;
if (!init())
return 1;
CoInitialize(NULL);
hDlgModeless = CreateDialogParam(hInstance,
MAKEINTRESOURCE(IDD_UNSET),
HWND_DESKTOP, RemoveDlgProc, (LPARAM)NULL);
hText1 = GetDlgItem(hDlgModeless, IDC_T1);
hText2 = GetDlgItem(hDlgModeless, IDC_T2);
SetWindowPos(hDlgModeless, HWND_TOP, 0, 0, 0, 0,
(bSilent ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) | SWP_NOMOVE | SWP_NOSIZE);
while (hDlgModeless && GetMessage(&msg, (HWND)NULL, 0, 0)) {
if ((hDlgModeless == 0) || !IsDialogMessage(hDlgModeless, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (fLog)
fclose(fLog);
CoUninitialize();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -