📄 makesis.cpp
字号:
// MAKESIS.CPP// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.//// makesis main function//// ===========================================================================// INCLUDES// ===========================================================================#include <wchar.h>#include <cstdio>#include <iostream>#include "utils.h"#include <tchar.h>#include "makesis.h"// ===========================================================================// CONSTANTS// ===========================================================================// Set up the cout stream so that we can use it with either narrow or wide// chars at build timeusing namespace std;#undef OUT // coz it's an IDL thing...#ifdef _UNICODE#define OUT wcout#else#define OUT cout#endif// ===========================================================================// CMakeSIS// The main application object. Controls the SIS file generation process// ===========================================================================CMakeSIS::CMakeSIS():m_wLineNo(0),m_fVerbose(FALSE) { ; }int CMakeSIS::Run(int argc, _TCHAR* argv[], _TCHAR** /*envp*/)// Inputs : argc, argv, envp - The command line passed to the process { int err=1; try { m_SISWriter.SetObserver(this); m_CmdOptions.ParseCommandLine(argc, argv); if(m_CmdOptions.ShowSyntax()) { ShowSyntax(); return 0; } // We now have valid parameters m_fVerbose = m_CmdOptions.Flags() & CParseCmd::EOptVerbose; if (m_CmdOptions.Flags() & CParseCmd::EOptPassword) { m_SISWriter.SetCmdPassword(m_CmdOptions.GetPassword()); } if(ParseSource() && WriteTarget()) { LPCWSTR fileNameU=m_CmdOptions.TargetFile();#ifdef _UNICODE OUT << _T("Created ") << fileNameU << endl;#else DWORD len=wcslen(fileNameU); LPSTR fileName=MakeMBCSString(fileNameU,CP_ACP,len); OUT << _T("Created ") << fileName << endl;#endif err=0; } } catch(TCommandLineException err) { // Show the title ShowBanner(); ShowCommandLineError(err); ShowUsage(); } catch(TUtilsException err) { ShowUtilsError(err); } m_SISWriter.Release(); return err; }BOOL CMakeSIS::ParseSource()// Processes the input PKG file { BOOL fResult = TRUE; WCHAR pszTempSource[MAX_PATH]; BOOL converted=FALSE; HANDLE hFile=0;#ifdef _UNICODE OUT << _T("Processing ") << m_CmdOptions.SourceFile() << _T("...") << endl;#else DWORD length=wcslen(m_CmdOptions.SourceFile()); LPSTR fName=MakeMBCSString(m_CmdOptions.SourceFile(), CP_ACP, length); OUT << _T("Processing ") << fName << _T("...") << endl; delete [] fName;#endif BOOL stubFile=(m_CmdOptions.Flags() & CParseCmd::EOptMakeStub); try { CParsePkg psr; BOOL littleEndian; if (!FileIsUnicode(m_CmdOptions.SourceFile(),littleEndian)) { converted=TRUE; wcscpy(pszTempSource,ConvertFileToUnicode(m_CmdOptions.SourceFile())); hFile = ::MakeSISOpenFile(pszTempSource,GENERIC_READ,OPEN_EXISTING); } else if (!littleEndian) { converted=TRUE; wcscpy(pszTempSource,ConvertFileToLittleEndianUnicode(m_CmdOptions.SourceFile())); hFile = ::MakeSISOpenFile(pszTempSource,GENERIC_READ,OPEN_EXISTING); } else { hFile = ::MakeSISOpenFile(m_CmdOptions.SourceFile(),GENERIC_READ,OPEN_EXISTING); } if (hFile==INVALID_HANDLE_VALUE) throw ErrCannotOpenFile; // Set the search path if(m_CmdOptions.Flags() & CParseCmd::EOptDirectory) psr.SetSearchDirectory(m_CmdOptions.SearchPath()); psr.ParseL(hFile, &m_SISWriter, stubFile, this); } catch(TParseException x) { ShowParseError(x); fResult = FALSE; } if (hFile) ::CloseHandle(hFile); if (converted) { _wunlink(pszTempSource); } return fResult; }BOOL CMakeSIS::WriteTarget()// Endeavours to contruct the output SIS file, or stubs { // Turn off line number output... m_wLineNo = 0; BOOL fResult = TRUE; try { BOOL stubFile=(m_CmdOptions.Flags() & CParseCmd::EOptMakeStub); if (stubFile) DoVerbage(_T("Generating SIS stub file...\n")); else DoVerbage(_T("Generating SIS installation file...")); m_SISWriter.WriteSIS(m_CmdOptions.TargetFile(),stubFile); } catch(TGeneratorException err) { ShowGeneratorError(err); fResult = FALSE; } return fResult; }void CMakeSIS::ShowBanner()// Displays the copyright gumph... { short major = KInstallerVersion / 100, minor = KInstallerVersion % 100; // Show the title OUT << endl << _T("MakeSIS, version ") << major << _T(".") << minor << endl; OUT << _T("A utility for creating Software Installation (SIS) files.") << endl;#ifdef _DEBUG OUT << _T("Development Version") << endl;#endif OUT << _T("Copyright (c) 2000 Symbian Ltd. All rights reserved.") << endl; OUT << endl; }void CMakeSIS::ShowUtilsError(TUtilsException err)// Purpose : Write message for any error which occured whilst parsing the input pkg file // Inputs : err - the error ID { switch(err) { case ErrNotEnoughMemory: DoErrMsg(_T("not enough memory")); break; case ErrCannotOpenFile: DoErrMsg(_T("cannot open file, check filename and access rights")); break; case ErrCannotReadFile: DoErrMsg(_T("cannot read file, check access rights")); break; case ErrCannotWriteFile: DoErrMsg(_T("cannot write file, check disk space")); break; case ErrCannotConvertFile: DoErrMsg(_T("cannot convert file to unicode")); DoErrMsg(_T("make sure .PKG and .TXT files are either UTF8 or UNICODE")); break; case ErrCertFileKeyFileMismatch: DoErrMsg(_T("key file does not match certificate(s) given")); DoErrMsg(_T("make sure key and certificate(s) specified correspond")); break; } }void CMakeSIS::ShowParseError(TParseException err)// Purpose : Write message for any error which occured whilst parsing the input pkg file // Inputs : err - the error ID { switch(err) { case ErrUnknownLine: DoErrMsg(_T("unknown line")); break; case ErrHeaderAlreadyDefined: DoErrMsg(_T("installation header already found")); break; case ErrUnknownLanguagesId: DoErrMsg(_T("unknown language specified")); OUT << _T(" Usage : &aa,bb,...zz") << endl; OUT << _T(" AF - Afrikaans, SQ - Albanian, AH - Amharic") << endl; OUT << _T(" AR - Arabic, HY - Armenian, AU - Australian") << endl; OUT << _T(" AS - Austrian, BE - Belarussian, BN - Bengali")<< endl; OUT << _T(" BG - Bulgarian, MY - Burmese, CA - Catalan") << endl; OUT << _T(" TC - Taiwan Chinese, HK - Hong Kong Chinese")<< endl; OUT << _T(" ZH - PRC Chinese")<< endl; OUT << _T(" HR - Croatian, CS - Czech, DA - Danish, DU - Dutch") << endl; OUT << _T(" EN - English, AM - American English, CE - Canadian English")<< endl; OUT << _T(" IE - International English, SF - South African English") << endl; OUT << _T(" ET - Estonian, FA - Farsi, FI - Finnish, BL - Belgian Flemish") << endl; OUT << _T(" FR - French, BF - Belgian French, CF - Canadian French")<< endl; OUT << _T(" IF - International French, SF - Swiss French")<< endl; OUT << _T(" GD - Scots Gaelic, KA - Georgian, GE - German") << endl; OUT << _T(" SG - Swiss German, EL - Greek, GU - Gujarati")<< endl; OUT << _T(" HE - Hebrew, HI - Hindi, HU - Hungarian") << endl; OUT << _T(" IC - Icelandic, IN - Indonesian, GA - Irish")<< endl; OUT << _T(" IT - Italian, SZ - Swiss Italian, JA - Japanese, ") << endl; OUT << _T(" KN - Kannada, KK - Kazakh, KM - Khmer")<< endl; OUT << _T(" KO - Korean, LO - Laothian, LV - Latvian") << endl; OUT << _T(" LT - Lithuanian, MK - Macedonian, MS - Malay") << endl; OUT << _T(" ML - Malayalam, MR - Marathi, MO - Moldovian") << endl; OUT << _T(" MN - Mongolian, NZ - New Zealand, NO - Norwegian") << endl; OUT << _T(" NN - Norwegian Nynorsk, PL - Polish, PO - Portuguese")<< endl; OUT << _T(" BP - Brazilian Portuguese, PA - Punjabi, RO - Romanian") << endl; OUT << _T(" RU - Russian, SR - Serbian, SI - Sinhalese") << endl; OUT << _T(" SK - Slovak, SL - Slovenian, SO - Somali")<< endl; OUT << _T(" SP - Spanish, OS - International Spanish") << endl; OUT << _T(" LS - Latin American Spanish")<< endl; OUT << _T(" SH - Swahili, SW - Swedish, FS - Finland Swedish") << endl; OUT << _T(" TL - Tagalog, TA - Tamil, TE - Telugu, TH - Thai") << endl; OUT << _T(" BO - Tibetan, TI - Tigrinya, TU - Turkish")<< endl; OUT << _T(" CT - Cyprus Turkish, TK - Turkmen, UK - Ukrainian") << endl; OUT << _T(" UR - Urdu") << endl; //Put reserved here OUT << _T(" VI - Vietnamese, CY - Welsh, ZU - Zulu") << endl; break; case ErrLanguagesAlreadyDefined: DoErrMsg(_T("the languages have already been defined")); break; case ErrLanguagesNotDefined: DoErrMsg(_T("languages have not been defined yet")); break; case ErrHeaderNotDefined: DoErrMsg(_T("the installation header has not been defined")); break; case ErrNoMainDependency: DoErrMsg(_T("missing main component dependency")); OUT << _T("a dependency is required upon the main component being "); switch (m_SISWriter.GetType()) { case EInstSISConfig: OUT << _T("configured") << endl; break; case EInstSISPatch: OUT << _T("patched") << endl; break; case EInstSISUpgrade: OUT << _T("upgraded") << endl; break; default: break; } OUT << _T("the header UID should equal the UID of the main component and dependency") << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -