mirror of https://gitlab.com/basile.b/dexed.git
cesetup, use std.stdio.File instead of std.stream.File
+ refact + fix linux menu entry
This commit is contained in:
parent
a5fc2d59d1
commit
5695baa946
|
@ -1,12 +1,7 @@
|
||||||
module cesetup;
|
module cesetup;
|
||||||
|
|
||||||
import std.stdio;
|
import
|
||||||
import std.file: mkdirRecurse, exists, remove, rmdir, getSize, FileException;
|
std.stdio, std.file, std.process, std.path, std.string, std.getopt;
|
||||||
import std.stream: File, FileMode;
|
|
||||||
import std.process: environment, executeShell;
|
|
||||||
import std.path: dirSeparator;
|
|
||||||
import std.string: strip, toLower, center, leftJustify, rightJustify;
|
|
||||||
import std.getopt;
|
|
||||||
|
|
||||||
version(X86) version(linux) version = nux32;
|
version(X86) version(linux) version = nux32;
|
||||||
version(X86_64) version(linux) version = nux64;
|
version(X86_64) version(linux) version = nux64;
|
||||||
|
@ -18,28 +13,35 @@ else enum exeExt = "";
|
||||||
alias ImpType = immutable ubyte[];
|
alias ImpType = immutable ubyte[];
|
||||||
alias ResType = immutable Resource;
|
alias ResType = immutable Resource;
|
||||||
|
|
||||||
|
enum Kind
|
||||||
|
{
|
||||||
|
exe,
|
||||||
|
dat,
|
||||||
|
doc,
|
||||||
|
}
|
||||||
|
|
||||||
struct Resource
|
struct Resource
|
||||||
{
|
{
|
||||||
ImpType data;
|
ImpType data;
|
||||||
immutable string destName;
|
immutable string destName;
|
||||||
immutable bool isExe;
|
immutable Kind kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource[] ceResources =
|
Resource[] ceResources =
|
||||||
[
|
[
|
||||||
Resource(cast(ImpType) import("coedit" ~ exeExt), "coedit" ~ exeExt, true),
|
Resource(cast(ImpType) import("coedit" ~ exeExt), "coedit" ~ exeExt, Kind.exe),
|
||||||
Resource(cast(ImpType) import("cesyms" ~ exeExt), "cesyms" ~ exeExt, true),
|
Resource(cast(ImpType) import("cesyms" ~ exeExt), "cesyms" ~ exeExt, Kind.exe),
|
||||||
Resource(cast(ImpType) import("cetodo" ~ exeExt), "cetodo" ~ exeExt, true),
|
Resource(cast(ImpType) import("cetodo" ~ exeExt), "cetodo" ~ exeExt, Kind.exe),
|
||||||
Resource(cast(ImpType) import("coedit.ico"), "coedit.ico", false),
|
Resource(cast(ImpType) import("coedit.ico"), "coedit.ico", Kind.dat),
|
||||||
Resource(cast(ImpType) import("coedit.png"), "coedit.png", false),
|
Resource(cast(ImpType) import("coedit.png"), "coedit.png", Kind.dat),
|
||||||
Resource(cast(ImpType) import("coedit.license.txt"), "coedit.license.txt", false)
|
Resource(cast(ImpType) import("coedit.license.txt"), "coedit.license.txt", Kind.doc)
|
||||||
];
|
];
|
||||||
|
|
||||||
Resource[] dcdResources =
|
Resource[] dcdResources =
|
||||||
[
|
[
|
||||||
Resource(cast(ImpType) import("dcd-server" ~ exeExt), "dcd-server" ~ exeExt, true),
|
Resource(cast(ImpType) import("dcd-server" ~ exeExt), "dcd-server" ~ exeExt, Kind.exe),
|
||||||
Resource(cast(ImpType) import("dcd-client" ~ exeExt), "dcd-client" ~ exeExt, true),
|
Resource(cast(ImpType) import("dcd-client" ~ exeExt), "dcd-client" ~ exeExt, Kind.exe),
|
||||||
Resource(cast(ImpType) import("dcd.license.txt"), "dcd.license.txt", false)
|
Resource(cast(ImpType) import("dcd.license.txt"), "dcd.license.txt", Kind.doc)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,17 +79,15 @@ static struct Formater
|
||||||
static void emptyLine(){justify!'L'("");}
|
static void emptyLine(){justify!'L'("");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static immutable string exePath, datPath, shortCutPath;
|
||||||
static immutable string exePath, appDataPath, shortCutPath;
|
|
||||||
version(linux) immutable bool asSu;
|
version(linux) immutable bool asSu;
|
||||||
|
|
||||||
|
|
||||||
static this()
|
static this()
|
||||||
{
|
{
|
||||||
version(win32)
|
version(win32)
|
||||||
{
|
{
|
||||||
exePath = environment.get("PROGRAMFILES") ~ r"\Coedit\";
|
exePath = environment.get("PROGRAMFILES") ~ r"\Coedit\";
|
||||||
appDataPath = environment.get("APPDATA") ~ r"\Coedit\";
|
datPath = environment.get("APPDATA") ~ r"\Coedit\";
|
||||||
shortCutPath = environment.get("USERPROFILE") ~ r"\Desktop\";
|
shortCutPath = environment.get("USERPROFILE") ~ r"\Desktop\";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -96,13 +96,13 @@ static this()
|
||||||
if (asSu)
|
if (asSu)
|
||||||
{
|
{
|
||||||
exePath = "/usr/bin";
|
exePath = "/usr/bin";
|
||||||
appDataPath = "/home/" ~ environment.get("SUDO_USER") ~ "/.config/Coedit/";
|
datPath = "/home/" ~ environment.get("SUDO_USER") ~ "/.config/Coedit/";
|
||||||
shortCutPath = "/usr/share/applications/";
|
shortCutPath = "/usr/share/applications/";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exePath = "/home/" ~ environment.get("USER") ~ "/bin/";
|
exePath = "/home/" ~ environment.get("USER") ~ "/bin/";
|
||||||
appDataPath = "/home/" ~ environment.get("USER") ~ "/.config/Coedit/";
|
datPath = "/home/" ~ environment.get("USER") ~ "/.config/Coedit/";
|
||||||
shortCutPath = "/home/" ~ environment.get("USER") ~ "/.local/share/applications/";
|
shortCutPath = "/home/" ~ environment.get("USER") ~ "/.local/share/applications/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,6 @@ void main(string[] args)
|
||||||
|
|
||||||
Formater.separate;
|
Formater.separate;
|
||||||
|
|
||||||
|
|
||||||
if (listfiles)
|
if (listfiles)
|
||||||
{
|
{
|
||||||
static immutable fmtRes = "%s installed: %s";
|
static immutable fmtRes = "%s installed: %s";
|
||||||
|
@ -134,12 +133,12 @@ void main(string[] args)
|
||||||
|
|
||||||
foreach(res; ceResources)
|
foreach(res; ceResources)
|
||||||
{
|
{
|
||||||
fname = res.isExe ? exePath ~ res.destName : appDataPath ~ res.destName;
|
fname = targetFilename(res);
|
||||||
writefln(fmtRes, fname, exists(fname));
|
writefln(fmtRes, fname, exists(fname));
|
||||||
}
|
}
|
||||||
foreach(res; dcdResources)
|
foreach(res; dcdResources)
|
||||||
{
|
{
|
||||||
fname = res.isExe ? exePath ~ res.destName : appDataPath ~ res.destName;
|
fname = targetFilename(res);
|
||||||
writefln(fmtRes, fname, exists(fname));
|
writefln(fmtRes, fname, exists(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +153,8 @@ void main(string[] args)
|
||||||
version(win32) Formater.justify!'L'("the setup program must be run as admin");
|
version(win32) Formater.justify!'L'("the setup program must be run as admin");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!asSu) Formater.justify!'L'("Coedit can also be setup globally (sudo)");
|
if(!asSu) Formater.justify!'L'("Coedit will be accessible to the current user");
|
||||||
else Formater.justify!'L'("Coedit will be accessible from all the accounts");
|
else Formater.justify!'L'("Coedit will be accessible to all the users");
|
||||||
}
|
}
|
||||||
|
|
||||||
Formater.separate;
|
Formater.separate;
|
||||||
|
@ -183,69 +182,60 @@ void main(string[] args)
|
||||||
static immutable extractMsg = [": FAILURE", ": extracted"];
|
static immutable extractMsg = [": FAILURE", ": extracted"];
|
||||||
foreach(res; ceResources)
|
foreach(res; ceResources)
|
||||||
{
|
{
|
||||||
if (res.isExe)
|
done = installResource(res);
|
||||||
done = installResource(res, exePath);
|
|
||||||
else
|
|
||||||
done = installResource(res, appDataPath);
|
|
||||||
Formater.justify!'L'(res.destName ~ extractMsg[done]);
|
Formater.justify!'L'(res.destName ~ extractMsg[done]);
|
||||||
failures += !done;
|
failures += !done;
|
||||||
}
|
}
|
||||||
if (!nodcd) foreach(res; dcdResources)
|
if (!nodcd) foreach(res; dcdResources)
|
||||||
{
|
{
|
||||||
if (res.isExe)
|
done = installResource(res);
|
||||||
done = installResource(res, exePath);
|
|
||||||
else
|
|
||||||
done = installResource(res, appDataPath);
|
|
||||||
Formater.justify!'L'(res.destName ~ extractMsg[done]);
|
Formater.justify!'L'(res.destName ~ extractMsg[done]);
|
||||||
failures += !done;
|
failures += !done;
|
||||||
}
|
}
|
||||||
|
|
||||||
Formater.separate;
|
Formater.separate;
|
||||||
if (failures)
|
if (failures)
|
||||||
Formater.justify!'L'("there are ERRORS, plz contact the support");
|
Formater.justify!'L'("there are ERRORS, plz contact the support");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
version(win32) win32PostInstall();
|
postInstall();
|
||||||
else nuxPostInstall();
|
|
||||||
Formater.justify!'L'("the files are correctly extracted...");
|
Formater.justify!'L'("the files are correctly extracted...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!asSu && exists("/usr/bin/coedit"))
|
// check that uninstall is executed as install (sudo or not)
|
||||||
|
version(linux)
|
||||||
{
|
{
|
||||||
Formater.separate;
|
if (!asSu && exists("/usr/bin/coedit"))
|
||||||
Formater.justify!'L'("warning, CE seems to be installed with sudo");
|
{
|
||||||
Formater.justify!'L'("but the uninstaller is not launched with sudo.");
|
Formater.separate;
|
||||||
Formater.separate;
|
Formater.justify!'L'("warning, CE seems to be installed with sudo");
|
||||||
}
|
Formater.justify!'L'("but the uninstaller is not launched with sudo.");
|
||||||
else if (asSu && exists("/home/" ~ environment.get("USER") ~ "/bin/coedit"))
|
Formater.separate;
|
||||||
{
|
}
|
||||||
Formater.separate;
|
else if (asSu && exists("/home/" ~ environment.get("USER") ~ "/bin/coedit"))
|
||||||
Formater.justify!'L'("warning, CE seems not to be installed with sudo");
|
{
|
||||||
Formater.justify!'L'("...but the uninstaller is launched with sudo.");
|
Formater.separate;
|
||||||
Formater.separate;
|
Formater.justify!'L'("warning, CE seems not to be installed with sudo");
|
||||||
|
Formater.justify!'L'("...but the uninstaller is launched with sudo.");
|
||||||
|
Formater.separate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// uninstall
|
||||||
static immutable rmMsg = [": FAILURE", ": deleted"];
|
static immutable rmMsg = [": FAILURE", ": deleted"];
|
||||||
foreach(res; ceResources)
|
foreach(res; ceResources)
|
||||||
{
|
{
|
||||||
if (res.isExe)
|
done = uninstallResource(res);
|
||||||
done = uninstallResource(res, exePath);
|
|
||||||
else
|
|
||||||
done = uninstallResource(res, appDataPath);
|
|
||||||
Formater.justify!'L'(res.destName ~ rmMsg[done]);
|
Formater.justify!'L'(res.destName ~ rmMsg[done]);
|
||||||
failures += !done;
|
failures += !done;
|
||||||
}
|
}
|
||||||
if (!nodcd) foreach(res; dcdResources)
|
if (!nodcd) foreach(res; dcdResources)
|
||||||
{
|
{
|
||||||
if (res.isExe)
|
done = uninstallResource(res);
|
||||||
done = uninstallResource(res, exePath);
|
|
||||||
else
|
|
||||||
done = uninstallResource(res, appDataPath);
|
|
||||||
Formater.justify!'L'(res.destName ~ rmMsg[done]);
|
Formater.justify!'L'(res.destName ~ rmMsg[done]);
|
||||||
failures += !done;
|
failures += !done;
|
||||||
}
|
}
|
||||||
|
// remove $PF folder
|
||||||
version(win32)
|
version(win32)
|
||||||
{
|
{
|
||||||
try rmdir(exePath);
|
try rmdir(exePath);
|
||||||
|
@ -257,8 +247,7 @@ void main(string[] args)
|
||||||
Formater.justify!'L'("there are ERRORS, plz contact the support");
|
Formater.justify!'L'("there are ERRORS, plz contact the support");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
version(win32) win32PostUninstall();
|
postUninstall();
|
||||||
else nuxPostUninstall();
|
|
||||||
Formater.justify!'L'("the files are correctly removed...");
|
Formater.justify!'L'("the files are correctly removed...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,13 +257,22 @@ void main(string[] args)
|
||||||
readln;
|
readln;
|
||||||
}
|
}
|
||||||
|
|
||||||
string extractedName(Resource resource, string path)
|
/// Returns the resource target filename, according to its Kind
|
||||||
|
string targetFilename(Resource resource)
|
||||||
{
|
{
|
||||||
return path ~ dirSeparator ~ resource.destName;
|
with(Kind) final switch(resource.kind)
|
||||||
|
{
|
||||||
|
case Kind.exe: return exePath ~ resource.destName;
|
||||||
|
case Kind.dat: return datPath ~ resource.destName;
|
||||||
|
case Kind.doc: return datPath ~ resource.destName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool installResource(Resource resource, string path)
|
/// Extracts and write a resource to a file.
|
||||||
|
bool installResource(Resource resource)
|
||||||
{
|
{
|
||||||
|
const string fname = resource.targetFilename;
|
||||||
|
const string path = fname.dirName;
|
||||||
if (!path.exists)
|
if (!path.exists)
|
||||||
mkdirRecurse(path);
|
mkdirRecurse(path);
|
||||||
if (!path.exists)
|
if (!path.exists)
|
||||||
|
@ -282,13 +280,11 @@ bool installResource(Resource resource, string path)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const string fname = extractedName(resource, path);
|
File f = File(resource.targetFilename, "w");
|
||||||
File f = new File(fname, FileMode.OutNew);
|
f.rawWrite(resource.data);
|
||||||
f.write(resource.data);
|
|
||||||
f.close;
|
f.close;
|
||||||
|
|
||||||
version(win32) {}
|
version(linux) if (resource.kind == Kind.exe && fname.exists)
|
||||||
else if (resource.isExe && fname.exists)
|
|
||||||
executeShell("chmod a+x " ~ fname);
|
executeShell("chmod a+x " ~ fname);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -297,13 +293,15 @@ bool installResource(Resource resource, string path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uninstallResource(Resource resource, string path)
|
/// Deletes the file creates for a resource
|
||||||
{
|
bool uninstallResource(Resource resource)
|
||||||
const string fname = extractedName(resource, path);
|
{
|
||||||
|
const string fname = resource.targetFilename;
|
||||||
if (!fname.exists) return true;
|
if (!fname.exists) return true;
|
||||||
else return tryRemove(fname);
|
else return tryRemove(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// returns true if fname is deleted
|
||||||
bool tryRemove(string fname)
|
bool tryRemove(string fname)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -312,56 +310,64 @@ bool tryRemove(string fname)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
version(linux) void nuxPostInstall()
|
/// adds menu entry, shortcut, etc
|
||||||
|
void postInstall()
|
||||||
{
|
{
|
||||||
mkdirRecurse(shortCutPath);
|
version(Win32)
|
||||||
File f = new File(shortCutPath ~ "coedit.desktop", FileMode.OutNew);
|
{
|
||||||
f.writeLine("[Desktop Entry]");
|
import std.conv: to;
|
||||||
f.writeLine("Name=coedit");
|
import std.random: uniform;
|
||||||
f.writeLine("Exec=coedit %f");
|
|
||||||
f.writeLine("Icon=" ~ appDataPath ~ "/coedit.png");
|
// shortcut prior to v 1 upd 2 was actually an url.
|
||||||
f.writeLine("Type=Application");
|
tryRemove(shortCutPath ~ "Coedit.url");
|
||||||
f.writeLine("Categories=Utility;Application;Development;");
|
|
||||||
f.writeLine("Terminal=false");
|
string target = exePath ~ "coedit.exe";
|
||||||
f.close;
|
string vbsName;
|
||||||
|
do vbsName = environment.get("TEMP") ~ r"\cesh" ~ uniform(0,int.max).to!string ~ ".vbs";
|
||||||
|
while (vbsName.exists);
|
||||||
|
|
||||||
|
string vbsCode = "
|
||||||
|
set WshShell = CreateObject(\"WScript.shell\")
|
||||||
|
strDesktop = WshShell.SpecialFolders(\"Desktop\")
|
||||||
|
set lnk = WshShell.CreateShortcut(strDesktop + \"\\Coedit.lnk\")
|
||||||
|
lnk.TargetPath = \"%s\"
|
||||||
|
lnk.Save
|
||||||
|
";
|
||||||
|
File vbs = File(vbsName, "w");
|
||||||
|
vbs.writefln(vbsCode, target);
|
||||||
|
vbs.close;
|
||||||
|
executeShell(vbsName);
|
||||||
|
|
||||||
|
tryRemove(vbsName);
|
||||||
|
}
|
||||||
|
else version(linux)
|
||||||
|
{
|
||||||
|
mkdirRecurse(shortCutPath);
|
||||||
|
File f = File(shortCutPath ~ "coedit.desktop", "w");
|
||||||
|
f.writeln("[Desktop Entry]");
|
||||||
|
f.writeln("Name=coedit");
|
||||||
|
f.writeln("Exec=coedit %f");
|
||||||
|
f.writeln("Icon=" ~ datPath ~ "coedit.png");
|
||||||
|
f.writeln("Type=Application");
|
||||||
|
f.writeln("Categories=Application;IDE;Development;");
|
||||||
|
f.writeln("Keywords=editor;Dlang;IDE;dmd;");
|
||||||
|
f.writeln("Terminal=false");
|
||||||
|
f.close;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version(linux) void nuxPostUninstall()
|
/// removes menu entry shortcuts, etc
|
||||||
|
void postUninstall()
|
||||||
{
|
{
|
||||||
tryRemove(shortCutPath ~ "coedit.desktop");
|
version(Win32)
|
||||||
|
{
|
||||||
|
// shortcut prior to v 1 upd 2 was actually an url.
|
||||||
|
tryRemove(shortCutPath ~ "Coedit.url");
|
||||||
|
tryRemove(shortCutPath ~ "Coedit.lnk");
|
||||||
|
}
|
||||||
|
else version(linux)
|
||||||
|
{
|
||||||
|
tryRemove(shortCutPath ~ "coedit.desktop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version (win32) void win32PostInstall()
|
|
||||||
{
|
|
||||||
import std.conv: to;
|
|
||||||
import std.random: uniform;
|
|
||||||
|
|
||||||
// shortcut prior to v 1 upd 2 was actually an url.
|
|
||||||
tryRemove(shortCutPath ~ "Coedit.url");
|
|
||||||
|
|
||||||
string target = exePath ~ "coedit.exe";
|
|
||||||
string vbsName;
|
|
||||||
do vbsName = environment.get("TEMP") ~ r"\cesh" ~ uniform(0,int.max).to!string ~ ".vbs";
|
|
||||||
while (vbsName.exists);
|
|
||||||
|
|
||||||
string vbsCode = "
|
|
||||||
set WshShell = CreateObject(\"WScript.shell\")
|
|
||||||
strDesktop = WshShell.SpecialFolders(\"Desktop\")
|
|
||||||
set lnk = WshShell.CreateShortcut(strDesktop + \"\\Coedit.lnk\")
|
|
||||||
lnk.TargetPath = \"%s\"
|
|
||||||
lnk.Save
|
|
||||||
";
|
|
||||||
File vbs = new File(vbsName, FileMode.OutNew);
|
|
||||||
vbs.writefln(vbsCode, target);
|
|
||||||
vbs.close;
|
|
||||||
executeShell(vbsName);
|
|
||||||
|
|
||||||
tryRemove(vbsName);
|
|
||||||
}
|
|
||||||
|
|
||||||
version (win32) void win32PostUninstall()
|
|
||||||
{
|
|
||||||
// shortcut prior to v 1 upd 2 was actually an url.
|
|
||||||
tryRemove(shortCutPath ~ "Coedit.url");
|
|
||||||
tryRemove(shortCutPath ~ "Coedit.lnk");
|
|
||||||
}
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
2alpha1
|
2alpha2
|
Loading…
Reference in New Issue