Continue OS X installer work.

This commit is contained in:
Steve Checkoway
2003-09-09 01:00:48 +00:00
parent 95f387ce5c
commit 3226a2fa6d
4 changed files with 25 additions and 11 deletions
@@ -17,7 +17,7 @@ using namespace std;
#include <stack> #include <stack>
#include <map> #include <map>
void HandleFile(const char *file, const char *archivePath, bool overwrite) void HandleFile(const CString& file, const CString& archivePath, bool overwrite)
{ {
static bool archiveMade = false; static bool archiveMade = false;
CString command; CString command;
@@ -29,14 +29,11 @@ void HandleFile(const char *file, const char *archivePath, bool overwrite)
archiveMade = true; archiveMade = true;
command = "tar cfP '"; command = "tar cfP '";
} }
command += archivePath; command += archivePath + "' '" + file + "'";
command += "' '";
command += file;
command += "'";
system(command); system(command);
printf("%s\n", file); printf("%s\n", file.c_str());
} }
void PrintUsage(int err) void PrintUsage(int err)
@@ -75,6 +72,7 @@ int main(int argc, char *argv[])
if (inFile == "help" || inFile == "-h" || inFile == "--help") if (inFile == "help" || inFile == "-h" || inFile == "--help")
PrintUsage(0); PrintUsage(0);
outDir += "/files";
InstallerFile config(inFile); InstallerFile config(inFile);
unsigned nextLine = 0; unsigned nextLine = 0;
@@ -96,11 +94,15 @@ int main(int argc, char *argv[])
CString archivePath = outDir + "/archive.tar"; CString archivePath = outDir + "/archive.tar";
Processor p(archivePath, HandleFile, NULL, false); Processor p(archivePath, HandleFile, NULL, NULL, false);
while (nextLine < config.GetNumLines()) while (nextLine < config.GetNumLines())
p.ProcessLine(config.GetLine(nextLine), nextLine); p.ProcessLine(config.GetLine(nextLine), nextLine);
/* Compress the archive after it is created */
command = "gzip '" + archivePath + "'";
system(command);
if (!config.WriteFile(outDir + "/config")) if (!config.WriteFile(outDir + "/config"))
{ {
printf("%s\n", strerror(errno)); printf("%s\n", strerror(errno));
@@ -10,9 +10,12 @@
#ifndef INSTALLER_FILE_H #ifndef INSTALLER_FILE_H
#define INSTALLER_FILE_H #define INSTALLER_FILE_H
#include "StdString.h"
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
using namespace std;
class InstallerFile { class InstallerFile {
private: private:
CString mPath; CString mPath;
@@ -209,6 +209,13 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return; return;
} }
if (parts[0] == "ASK")
{
if (parts.size() != 3)
goto error;
mVars[parts[1]] = (*mAsk)(parts[2]);
}
error: error:
(*mError)("%s is an invalid command", line.c_str()); (*mError)("%s is an invalid command", line.c_str());
++nextLine; ++nextLine;
+6 -4
View File
@@ -18,9 +18,10 @@ using namespace std;
class Processor class Processor
{ {
private: private:
typedef void (*handleFileFunc)(const char *file, const char *archivePath, bool overwrite); typedef void (*handleFileFunc)(const CString& file, const CString& archivePath, bool overwrite);
typedef const char *(*getPathFunc)(const char *id); typedef const CString (*getPathFunc)(const CString& ID);
typedef void (*errorFunc)(const char *fmt, ...); typedef void (*errorFunc)(const char *fmt, ...);
typedef bool (*askFunc)(const CString& question);
stack<unsigned> mReturnStack; stack<unsigned> mReturnStack;
bool mDoGoto; bool mDoGoto;
@@ -32,6 +33,7 @@ private:
CString mCWD; CString mCWD;
handleFileFunc mHandleFile; handleFileFunc mHandleFile;
getPathFunc mGetPath; getPathFunc mGetPath;
askFunc mAsk;
errorFunc mError; errorFunc mError;
bool mInstalling; bool mInstalling;
@@ -39,8 +41,8 @@ private:
bool ResolveConditional(const CString& cond); bool ResolveConditional(const CString& cond);
static void DefaultError(const char *fmt, ...); static void DefaultError(const char *fmt, ...);
public: public:
Processor(CString& path, handleFileFunc f, getPathFunc p, bool i) Processor(CString& path, handleFileFunc f, getPathFunc p, askFunc a, bool i)
: mDoGoto(false), mPath(path), mCWD("."), mHandleFile(f), mGetPath(p), : mDoGoto(false), mPath(path), mCWD("."), mHandleFile(f), mGetPath(p), mAsk(a),
mError(Processor::DefaultError), mInstalling(i) { } mError(Processor::DefaultError), mInstalling(i) { }
void ProcessLine(const CString& line, unsigned& nextLine); void ProcessLine(const CString& line, unsigned& nextLine);
void SetErrorFunc(errorFunc f) { mError = f; } void SetErrorFunc(errorFunc f) { mError = f; }