1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include <stdio.h> 23 24 //-------------------------------------------------------------------------- 25 26 struct LanguageData 27 { 28 long m_nLanguageID; 29 LPTSTR m_pTransform; 30 31 LanguageData( LPTSTR pData ); 32 ~LanguageData(); 33 }; 34 35 //-------------------------------------------------------------------------- 36 37 class SetupApp 38 { 39 DWORD m_nOSVersion; 40 DWORD m_nMinorVersion; 41 boolean m_bIsWin9x : 1; 42 boolean m_bNeedReboot : 1; 43 boolean m_bAdministrative : 1; 44 45 HINSTANCE m_hInst; 46 HANDLE m_hMapFile; 47 LPTSTR m_pAppTitle; 48 LPTSTR m_pCmdLine; 49 LPTSTR m_pDatabase; 50 LPTSTR m_pReqVersion; 51 LPTSTR m_pProductName; 52 LPTSTR m_pAdvertise; 53 LPTSTR m_pTmpName; 54 LPTSTR m_pErrorText; 55 LPTSTR m_pModuleFile; 56 LPTSTR m_pPatchFiles; 57 LPCTSTR m_pUpgradeKey; 58 LPCTSTR m_pProductVersion; 59 int *m_pMSIErrorCode; 60 61 boolean m_bQuiet : 1; 62 boolean m_bIgnoreAlreadyRunning : 1; 63 boolean m_bRegNoMsoTypes :1; 64 boolean m_bRegAllMsoTypes :1; 65 boolean m_bIsMinorUpgrade :1; 66 boolean m_bSupportsPatch :1; 67 68 FILE *m_pLogFile; 69 70 long m_nLanguageID; 71 long m_nLanguageCount; 72 LanguageData** m_ppLanguageList; 73 74 private: 75 76 boolean GetPathToFile( TCHAR* pFileName, TCHAR **pPath ); 77 LPCTSTR GetPathToMSI(); 78 79 int GetNameValue( TCHAR* pLine, TCHAR **pName, TCHAR **pValue ); 80 boolean GetProfileSection( LPCTSTR pFileName, LPCTSTR pSection, 81 DWORD& rSize, LPTSTR *pRetBuf ); 82 LPTSTR CopyIniFile( LPCTSTR pIniFile ); 83 void ConvertNewline( LPTSTR pText ) const; 84 85 boolean LaunchInstaller( LPCTSTR pParam ); 86 HMODULE LoadMsiLibrary(); 87 DWORD WaitForProcess( HANDLE hHandle ); 88 89 boolean GetCmdLineParameters( LPTSTR *pCmdLine ); 90 DWORD GetNextArgument( LPCTSTR pStr, LPTSTR *pArg, 91 LPTSTR *pNext, boolean bStripQuotes = false ); 92 boolean IsAdmin(); 93 94 boolean GetCommandLine(); 95 96 boolean IsTerminalServerInstalled() const; 97 void AddFileToPatchList( TCHAR* pPath, TCHAR* pFile ); 98 boolean IsPatchInstalled( TCHAR* pBaseDir, TCHAR* pFileName ); 99 boolean InstallRuntimes( TCHAR* pProductCode, TCHAR* pFileName ); 100 101 public: 102 UINT m_uiRet; 103 SetupApp(); 104 virtual ~SetupApp(); 105 106 virtual boolean Initialize( HINSTANCE hInst ); 107 virtual boolean AlreadyRunning() const; 108 virtual boolean ReadProfile(); 109 virtual boolean GetPatches(); 110 virtual boolean ChooseLanguage( long& rLanguage ); 111 virtual boolean CheckVersion(); 112 virtual boolean CheckForUpgrade(); 113 virtual boolean InstallRuntimes(); 114 virtual boolean Install( long nLanguage ); 115 116 virtual UINT GetError() const; 117 virtual void DisplayError( UINT nErr ) const; 118 SetError(UINT nErr)119 void SetError( UINT nErr ) { m_uiRet = nErr; } IsWin9x() const120 boolean IsWin9x() const { return m_bIsWin9x; } GetOSVersion() const121 DWORD GetOSVersion() const { return m_nOSVersion; } GetMinorVersion() const122 DWORD GetMinorVersion() const { return m_nMinorVersion; } 123 IsAdminInstall()124 boolean IsAdminInstall() { return m_bAdministrative; } SetAdminInstall(boolean bValue)125 void SetAdminInstall( boolean bValue ) { m_bAdministrative = bValue; } 126 SetRebootNeeded(boolean bNeedReboot)127 void SetRebootNeeded( boolean bNeedReboot ) { m_bNeedReboot = bNeedReboot; } NeedReboot() const128 boolean NeedReboot() const { return m_bNeedReboot; } 129 130 void Log( LPCTSTR pMessage, LPCTSTR pText = NULL ) const; 131 GetLanguageCount() const132 long GetLanguageCount() const { return m_nLanguageCount; } 133 long GetLanguageID( long nIndex ) const; 134 void GetLanguageName( long nLanguage, LPTSTR sName ) const; 135 GetAppTitle() const136 LPCTSTR GetAppTitle() const { return m_pAppTitle; } 137 LPTSTR SetProdToAppTitle( LPCTSTR pProdName ); GetHInst() const138 HINSTANCE GetHInst() const { return m_hInst; } 139 }; 140 141 //-------------------------------------------------------------------------- 142