prepared setup program for 1_update_2

This commit is contained in:
Basile Burg 2015-08-24 22:26:15 +02:00
parent 10cdbcd912
commit a57a0a69fa
2 changed files with 112 additions and 69 deletions

View File

@ -1,12 +1,13 @@
object CurrentProject: TCEProject object CurrentProject: TCENativeProject
OptionsCollection = < OptionsCollection = <
item item
name = 'win32' name = 'win32'
messagesOptions.tlsInformations = True
outputOptions.inlining = True outputOptions.inlining = True
outputOptions.boundsCheck = offAlways outputOptions.boundsCheck = offAlways
outputOptions.optimizations = True outputOptions.optimizations = True
outputOptions.release = True outputOptions.release = True
pathsOptions.outputFilename = 'coedit.1gold.win32.setup.exe' pathsOptions.outputFilename = 'coedit.1update2.win32.setup.exe'
pathsOptions.importStringPaths.Strings = ( pathsOptions.importStringPaths.Strings = (
'win32\' 'win32\'
) )
@ -17,7 +18,7 @@ object CurrentProject: TCEProject
outputOptions.boundsCheck = offAlways outputOptions.boundsCheck = offAlways
outputOptions.optimizations = True outputOptions.optimizations = True
outputOptions.release = True outputOptions.release = True
pathsOptions.outputFilename = 'coedit.1gold.linux32.setup' pathsOptions.outputFilename = 'coedit.1update2.linux32.setup'
pathsOptions.importStringPaths.Strings = ( pathsOptions.importStringPaths.Strings = (
'nux32\' 'nux32\'
) )
@ -28,7 +29,7 @@ object CurrentProject: TCEProject
outputOptions.boundsCheck = offAlways outputOptions.boundsCheck = offAlways
outputOptions.optimizations = True outputOptions.optimizations = True
outputOptions.release = True outputOptions.release = True
pathsOptions.outputFilename = 'coedit.1gold.linux64.setup' pathsOptions.outputFilename = 'coedit.1update2.linux64.setup'
pathsOptions.importStringPaths.Strings = ( pathsOptions.importStringPaths.Strings = (
'nux64\' 'nux64\'
) )

View File

@ -5,7 +5,7 @@ import std.file: mkdir, exists, remove, rmdir, getSize, FileException;
import std.stream: File, FileMode; import std.stream: File, FileMode;
import std.process: environment, executeShell; import std.process: environment, executeShell;
import std.path: dirSeparator; import std.path: dirSeparator;
import std.string: strip, toLower; import std.string: strip, toLower, center, leftJustify, rightJustify;
import std.getopt; import std.getopt;
version(X86) version(linux) version = nux32; version(X86) version(linux) version = nux32;
@ -15,28 +15,62 @@ version(X86) version(Windows)version = win32;
version(win32) enum exeExt = ".exe"; version(win32) enum exeExt = ".exe";
else enum exeExt = ""; else enum exeExt = "";
alias ImpType = immutable ubyte[];
alias ResType = immutable Resource;
struct Resource struct Resource
{ {
ubyte[] data; ImpType data;
string destName; immutable string destName;
bool isExe; immutable bool isExe;
} }
auto coedit = Resource(cast(ubyte[]) import("coedit" ~ exeExt), "coedit" ~ exeExt, true); ResType coedit = Resource(cast(ImpType) import("coedit" ~ exeExt), "coedit" ~ exeExt, true);
auto cesyms = Resource(cast(ubyte[]) import("cesyms" ~ exeExt), "cesyms" ~ exeExt, true); ResType cesyms = Resource(cast(ImpType) import("cesyms" ~ exeExt), "cesyms" ~ exeExt, true);
auto cetodo = Resource(cast(ubyte[]) import("cetodo" ~ exeExt), "cetodo" ~ exeExt, true); ResType cetodo = Resource(cast(ImpType) import("cetodo" ~ exeExt), "cetodo" ~ exeExt, true);
auto dcd_server = Resource(cast(ubyte[]) import("dcd-server" ~ exeExt), "dcd-server" ~ exeExt, true); ResType dcd_server = Resource(cast(ImpType) import("dcd-server" ~ exeExt), "dcd-server" ~ exeExt, true);
auto dcd_client = Resource(cast(ubyte[]) import("dcd-client" ~ exeExt), "dcd-client" ~ exeExt, true); ResType dcd_client = Resource(cast(ImpType) import("dcd-client" ~ exeExt), "dcd-client" ~ exeExt, true);
auto icon = Resource(cast(ubyte[]) import("coedit.ico"), "coedit.ico", false); ResType icon = Resource(cast(ImpType) import("coedit.ico"), "coedit.ico", false);
auto png = Resource(cast(ubyte[]) import("coedit.png"), "coedit.png", false); ResType png = Resource(cast(ImpType) import("coedit.png"), "coedit.png", false);
auto celic = Resource(cast(ubyte[]) import("coedit.license.txt"), "coedit.license.txt", false); ResType celic = Resource(cast(ImpType) import("coedit.license.txt"), "coedit.license.txt", false);
auto dcdlic = Resource(cast(ubyte[]) import("dcd.license.txt"), "dcd.license.txt", false); ResType dcdlic = Resource(cast(ImpType) import("dcd.license.txt"), "dcd.license.txt", false);
static string exePath, appDataPath, shortCutPath; static struct Formater
{
private enum width = 48;
private static __gshared char[] separator;
static this()
{
separator.length = width + 4;
separator[] = '-';
separator[0] = '+';
separator[$-1] = '+';
}
static void justify(char A, string s)()
{
static assert (s.length <= width, "too long to fit on a line...");
static if (A == 'L')
writeln("| ", leftJustify(s, width, ' '), " |");
else static if (A == 'C')
writeln("| ", center(s, width, ' '), " |");
else static if (A == 'R')
writeln("| ", rightJustify(s, width, ' '), " |");
else static assert(0, "invalid justification, L|C|R expected");
}
static void separate(){separator.writeln;}
static void emptyLine(){justify!('L', "");}
}
static immutable string exePath, appDataPath, shortCutPath;
version(win32){} else immutable bool asSu; version(win32){} else immutable bool asSu;
static this() static this()
@ -75,76 +109,81 @@ void main(string[] args)
"u|uninstall", &uninstall "u|uninstall", &uninstall
); );
writeln("|---------------------------------------------|"); Formater.separate;
if (!uninstall) if (!uninstall) Formater.justify!('C', "Coedit 1 update 2 setup");
writeln("| Coedit 1 gold setup |"); else Formater.justify!('C', "Coedit uninstaller");
else
writeln("| Coedit uninstaller |");
writeln("|---------------------------------------------|");
version(win32) Formater.separate;
writeln("| the setup program must be run as admin |"); version(win32) Formater.justify!('L', "the setup program must be run as admin");
else if(!asSu) else
writeln("| the program can be setup globally (sudo) |"); {
if(!asSu) Formater.justify!('L', "Coedit can also be setup globally (sudo)");
else Formater.justify!('L', "Coedit will be accessible from all the accounts");
}
writeln("| options: |"); Formater.separate;
writeln("| --nodcd: skip DCD setup |"); Formater.justify!('L', "options:");
writeln("| -u: uninstall |"); Formater.emptyLine;
writeln("| press A to abort or another key to start... |"); if (!uninstall)
writeln("|---------------------------------------------|"); {
if (!nodcd) Formater.justify!('L', "--nodcd: skip DCD setup");
Formater.justify!('L', "-u: uninstall");
}
else if (!nodcd) Formater.justify!('L', "--nodcd: do nort remove DCD");
Formater.justify!('L', "press A to abort or another key to start...");
Formater.separate;
const string inp = readln.strip; const string inp = readln.strip;
if (inp.toLower == "a") return; if (inp.toLower == "a") return;
writeln("|---------------------------------------------|"); Formater.separate;
size_t failures; size_t failures;
if(!uninstall) if(!uninstall)
{ {
if (installResource(coedit, exePath)) if (installResource(coedit, exePath))
writeln("| Coedit main application extracted |"); Formater.justify!('L', "Coedit main application extracted");
else failures++; else failures++;
if (installResource(cesyms, exePath)) if (installResource(cesyms, exePath))
writeln("| Coedit symbol list builder extracted |"); Formater.justify!('L', "Coedit symbol list builder extracted");
else failures++; else failures++;
if (installResource(cetodo, exePath)) if (installResource(cetodo, exePath))
writeln("| Coedit todo comment parser extracted |"); Formater.justify!('L', "Coedit todo comment parser extracted");
else failures++; else failures++;
if (installResource(celic, appDataPath)) if (installResource(celic, appDataPath))
writeln("| Coedit license file extracted |"); Formater.justify!('L', "Coedit license file extracted");
else failures++; else failures++;
if (installResource(icon, appDataPath)) if (installResource(icon, appDataPath))
writeln("| Coedit icon file extracted |"); Formater.justify!('L', "Coedit icon file extracted");
else failures++; else failures++;
if (installResource(png, appDataPath)) if (installResource(png, appDataPath))
writeln("| Coedit big png logo extracted |"); Formater.justify!('L', "Coedit big png logo extracted");
else failures++; else failures++;
if (!nodcd) if (!nodcd)
{ {
if (installResource(dcd_server, exePath)) if (installResource(dcd_server, exePath))
writeln("| Completion daemon server extracted |"); Formater.justify!('L', "Completion daemon server extracted");
else failures++; else failures++;
if (installResource(dcd_client, exePath)) if (installResource(dcd_client, exePath))
writeln("| Completion daemon client extracted |"); Formater.justify!('L', "Completion daemon client extracted");
else failures++; else failures++;
if (installResource(dcdlic, appDataPath)) if (installResource(dcdlic, appDataPath))
writeln("| Completion daemon license extracted |"); Formater.justify!('L', "Completion daemon license extracted");
else failures++; else failures++;
} }
writeln("|---------------------------------------------|"); Formater.separate;
if (failures) if (failures)
{ Formater.justify!('L', "there are ERRORS, plz contact the support");
writeln("| there are ERRORS, plz contact the support |");
}
else else
{ {
version(win32) win32PostInstall(); version(win32) win32PostInstall();
else nuxPostInstall(); else nuxPostInstall();
writeln("| the files are correctly extracted |"); Formater.justify!('L', "the files are correctly extracted...");
} }
writeln("| press a key to exit... |"); Formater.emptyLine;
writeln("|---------------------------------------------|"); Formater.justify!('R', "...press a key to exit");
Formater.separate;
readln; readln;
} }
else else
@ -155,9 +194,12 @@ void main(string[] args)
failures += !uninstallResource(celic, appDataPath); failures += !uninstallResource(celic, appDataPath);
failures += !uninstallResource(icon, appDataPath); failures += !uninstallResource(icon, appDataPath);
failures += !uninstallResource(png, appDataPath); failures += !uninstallResource(png, appDataPath);
failures += !uninstallResource(dcd_client, exePath); if (!nodcd)
failures += !uninstallResource(dcd_server, exePath); {
failures += !uninstallResource(dcdlic, appDataPath); failures += !uninstallResource(dcd_client, exePath);
failures += !uninstallResource(dcd_server, exePath);
failures += !uninstallResource(dcdlic, appDataPath);
}
version(win32) version(win32)
{ {
@ -166,21 +208,25 @@ void main(string[] args)
} }
if (failures) if (failures)
{ Formater.justify!('L', "there are ERRORS, plz contact the support");
writeln("| there are ERRORS, plz contact the support |");
}
else else
{ {
version(win32) win32PostUninstall(); version(win32) win32PostUninstall();
else nuxPostUninstall(); else nuxPostUninstall();
writeln("| the files are correctly removed |"); Formater.justify!('L', "the files are correctly removed...");
} }
writeln("| press a key to exit... |"); Formater.emptyLine;
writeln("|---------------------------------------------|"); Formater.justify!('R', "...press a key to exit");
Formater.separate;
readln; readln;
} }
} }
string extractedName(Resource resource, string path)
{
return path ~ dirSeparator ~ resource.destName;
}
bool installResource(Resource resource, string path) bool installResource(Resource resource, string path)
{ {
if (!path.exists) if (!path.exists)
@ -190,18 +236,14 @@ bool installResource(Resource resource, string path)
try try
{ {
const string fname = path ~ dirSeparator ~ resource.destName; const string fname = extractedName(resource, path);
File f = new File(fname, FileMode.OutNew); File f = new File(fname, FileMode.OutNew);
f.write(resource.data); f.write(resource.data);
f.close; f.close;
version(win32) {} else version(win32) {}
if (resource.isExe) else if (resource.isExe && fname.exists)
if (fname.exists) executeShell("chmod a+x " ~ fname);
{
string cmd = "chmod a+x " ~ fname;
executeShell(cmd);
}
} }
catch (Exception e) catch (Exception e)
return false; return false;
@ -211,7 +253,7 @@ bool installResource(Resource resource, string path)
bool uninstallResource(Resource resource, string path) bool uninstallResource(Resource resource, string path)
{ {
string fname = path ~ dirSeparator ~ resource.destName; const string fname = extractedName(resource, path);
if (!fname.exists) return true; if (!fname.exists) return true;
try remove(fname); try remove(fname);
catch (FileException e) return false; catch (FileException e) return false;
@ -239,7 +281,7 @@ void nuxPostUninstall()
void win32PostInstall() void win32PostInstall()
{ {
// notice: this is not a true shortcut, other options are // note: this is not a true shortcut, other options are
// - create a true lnk by generating and executing a vbs // - create a true lnk by generating and executing a vbs
// - use winapi... // - use winapi...
string target = exePath ~ "coedit.exe"; string target = exePath ~ "coedit.exe";