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

📄 uninstall.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: uninstall.cpp,v 1.1.2.1 2004/07/09 02:03:00 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** */#include "hxtypes.h"#if !(defined(_MSC_VER) && (_MSC_VER > 1100))typedef int INT_PTR; // VC5 needs this, VC6 gets it from hxbastsd.h#endif#include <windows.h>#include <stdio.h>#include <direct.h>#include <sys/stat.h>#include <commctrl.h>#include "wininstlib.h"#include "uninstdefs.h"#include "uninstall.h"#include "resource.h"INT_PTR CALLBACKProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){    switch(uMsg)    {        case WM_INITDIALOG:            return TRUE;    }    return FALSE;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                    LPSTR lpCmdLine, int nCmdShow){    char szLog[MAX_PATH + 1];    szLog[0] = '\0';    UINT32 ulFlags = 0;    if(lpCmdLine)    {        BOOL bInQuote = FALSE;                char* szOption = lpCmdLine;                char* szOptionEnd;        UINT uSize;        for(;*szOption != '\0' && isspace(*szOption); szOption++);                while(*szOption != '\0')        {            if(*szOption == '\"')            {                szOption++;                for(szOptionEnd = szOption;                     *szOptionEnd != '\0' && *szOptionEnd != '\"';                     szOptionEnd++);            }            else            {                for(szOptionEnd = szOption;                    szOptionEnd != '\0' && !isspace(*szOptionEnd);                    szOptionEnd++);            }            uSize = szOptionEnd - szOption;            if(strncmp(szOption, "-s", uSize) == 0 ||                strncmp(szOption, "--silent", uSize) == 0 ||                 strncmp(szOption, "/s", uSize) == 0)            {                ulFlags |= INST_SILENT | INST_NON_INTERACTIVE;            }            else if(strncmp(szOption, "-p", uSize) == 0 ||                    strncmp(szOption, "--progress-only", uSize) == 0)            {                ulFlags |= INST_NON_INTERACTIVE;            }            else if(*szOption != '-')            {                uSize = min(uSize, MAX_PATH);                strncpy(szLog, szOption, uSize);                szLog[uSize] = '\0';            }            for(szOption = *szOptionEnd == '\"' ?                 szOptionEnd + 1 : szOptionEnd;                *szOption != '\0' && isspace(*szOption);                 szOption++);        }    }    if(szLog[0] == '\0')    {        strcpy(szLog, "install.log");    }    CUninstaller uninst(hInstance);    uninst.Uninstall(szLog, ulFlags);    return 0;}CStringStack::~CStringStack() {    SNode* pHead;    while(m_pHead)    {        pHead = m_pHead;        m_pHead = pHead->pNext;        HX_VECTOR_DELETE(pHead->szString);                    delete pHead;    }}void CStringStack::Push(char* szVal){     SNode* pNode = new SNode(szVal);    pNode->pNext = m_pHead;    if(m_pHead)    {        m_pHead->pBack = pNode;    }        m_pHead = pNode;}char* CStringStack::Pop() {     if(!m_pHead)    {        return NULL;    }    SNode* pNode = m_pHead;    char* szData = pNode->szString;    m_pHead = m_pHead->pNext;    if(m_pHead)    {        m_pHead->pBack = NULL;    }    delete pNode;    return szData;}char*CStringStack::Top(){    if(!m_pHead)    {        return NULL;    }    return m_pHead->szString;}STACKPOSCStringStack::Find(const char* szVal){    for(SNode* pNode = m_pHead; pNode != NULL; pNode = pNode->pNext)    {        if(stricmp(szVal, pNode->szString) == 0)        {            return pNode;        }                }    return NULL;}char*CStringStack::Remove(STACKPOS pNode){    if(m_pHead == pNode)    {        m_pHead = pNode->pNext;    }    if(pNode->pNext)    {        pNode->pNext->pBack = pNode->pBack;    }    if(pNode->pBack)    {        pNode->pBack->pNext = pNode->pNext;    }    char* szData = pNode->szString;    delete[] pNode;    return szData;}char*CStringStack::FindAndRemove(const char* szVal){    STACKPOS pos = Find(szVal);    return pos ? Remove(pos) : NULL;}CUninstaller::CUninstaller(HINSTANCE hInstance) :     m_fpLog(NULL),    m_szLog(NULL),    m_ulInstFlags(0),    m_ulItems(0),    m_ulTotalItems(0),    m_hInstance(hInstance),    m_hwndDlg(NULL){    m_szTitle[0] = '\0';    m_szAppPath[0] = '\0';    m_szUninstPath[0] = '\0';}CUninstaller::~CUninstaller(){    if(m_fpLog)    {        fclose(m_fpLog);    }}/* * CUninstaller::Uninstall - does the whole uninstall */voidCUninstaller::Uninstall(const char* szLog, UINT32 ulFlags){    char szErr[MAX_PATH + 128];    m_ulInstFlags = ulFlags;    m_szLog = szLog;    // Get the uninstaller path    if(GetModuleFileName(NULL, m_szUninstPath, MAX_PATH+1))    {        // Get the short name        GetShortPathName(m_szUninstPath, m_szUninstPath, MAX_PATH+1);    }    // Open the log file    m_fpLog = fopen(m_szLog, "r");    if(!m_fpLog)    {        if(!(m_ulInstFlags & INST_NON_INTERACTIVE))        {             sprintf(szErr, STR_ERR_NO_LOG, m_szLog);            MessageBox(NULL, szErr, NULL, MB_OK);        }        return;    }    // Get the title and app path    if(!GetTitle())    {        if(!(m_ulInstFlags & INST_NON_INTERACTIVE))        {            sprintf(szErr, STR_ERR_BAD_LOG, m_szLog);            MessageBox(NULL, szErr, NULL, MB_OK);        }        fclose(m_fpLog);        m_fpLog = NULL;        return;    }    // Ask the user ....    if(!(m_ulInstFlags & INST_NON_INTERACTIVE) && !Confirm())    {        fclose(m_fpLog);        m_fpLog = NULL;        return;    }    // Check if the app is writeable. If not, warn the user to exit it.    if(m_szAppPath)    {                if(!CheckAppPath(m_szAppPath) &&             ((m_ulInstFlags & INST_NON_INTERACTIVE) ||             !WarnRunning()))        {            fclose(m_fpLog);            m_fpLog = NULL;            return;        }    }    GetNumItems();    // Display the progress    if(!(m_ulInstFlags & INST_SILENT))    {        ShowProgress();    }    // Services must be removed before files, since a file might    // be in use by a service    RemoveServices();    // Remove everything else    RemoveAll();    CloseProgress();    if(!(m_ulInstFlags & INST_NON_INTERACTIVE))    {        ShowDoneMessage();    }}/* * CUninstaller::GetTitle - gets the title item (e.g. "Helix Server") * from the log file */BOOLCUninstaller::GetTitle(){    char* szTitleStart = NULL;    SInstItem* pItem;    fseek(m_fpLog, 0, SEEK_SET);    // Search for title    while((m_szTitle[0] == '\0' || m_szAppPath[0] == '\0') &&             GetNextItem(pItem))    {        if(m_szTitle[0] == '\0' && stricmp(pItem->szName, UNINST_TITLE) == 0)        {            strncpy(m_szTitle, pItem->szValue, READ_SIZE-1);            m_szTitle[READ_SIZE-1] = '\0';        }        else if(m_szAppPath[0] == '\0' &&                 stricmp(pItem->szName, UNINST_APP_PATH) == 0)        {            strncpy(m_szAppPath, pItem->szValue, MAX_PATH);            m_szAppPath[MAX_PATH] = '\0';        }                delete pItem;    }    return m_szTitle[0] == '\0' ? FALSE : TRUE;}/* * CUninstaller::CheckAppPath - Returns FALSE if we can't write to the app * path, so we can warn the user if they are uninstalling a running app. */BOOLCUninstaller::CheckAppPath(const char* szAppPath){    // Check if we can write to the app path    WIN32_FIND_DATA findData;    HANDLE hFindFile = FindFirstFile(szAppPath, &findData);    if(hFindFile != INVALID_HANDLE_VALUE)    {        FindClose(hFindFile);        HANDLE hApp = CreateFile(szAppPath, GENERIC_WRITE, 0, NULL,             OPEN_EXISTING, 0, NULL);        if(hApp == INVALID_HANDLE_VALUE)        {            return FALSE;        }                CloseHandle(hApp);    }    return TRUE;}/* * CUninstaller::Confirm - Displays a dummy dialog, asking the user  * if they really want to uninstall */BOOLCUninstaller::Confirm(){    char szText[READ_SIZE + 512];    char szCaption[READ_SIZE + 64];    sprintf(szText, STR_CONFIRM, m_szTitle);    sprintf(szCaption, STR_CAPTION, m_szTitle);

⌨️ 快捷键说明

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