cesetup, perfs, resources duplicated by non-ref foreach

This commit is contained in:
Basile Burg 2016-07-03 18:45:23 +02:00
parent fbc1ce9aaa
commit 693c1324f8
1 changed files with 28 additions and 18 deletions

View File

@ -49,7 +49,7 @@ Resource[] oldResources =
Resource(cast(ImpType) [], "cetodo" ~ exeExt, Kind.exe), Resource(cast(ImpType) [], "cetodo" ~ exeExt, Kind.exe),
]; ];
static struct Formater struct Formater
{ {
private enum width = 48; private enum width = 48;
private static __gshared char[] separator; private static __gshared char[] separator;
@ -128,23 +128,29 @@ void main(string[] args)
if (listfiles) if (listfiles)
{ {
static immutable fmtRes = "%s installed: %s"; static immutable fmtRes = "\"%s\" installed: %s";
static immutable fmtOldRes = "obsolete \"%s\" installed: %s";
string fname; string fname;
Formater.separate; Formater.separate;
Formater.justify!'C'("files list and status"); Formater.justify!'C'("files list and status");
Formater.separate; Formater.separate;
foreach(res; ceResources) foreach (ref res; ceResources)
{ {
fname = targetFilename(res); fname = targetFilename(res);
writefln(fmtRes, fname, exists(fname)); writefln(fmtRes, fname, exists(fname));
} }
foreach(res; dcdResources) foreach (ref res; dcdResources)
{ {
fname = targetFilename(res); fname = targetFilename(res);
writefln(fmtRes, fname, exists(fname)); writefln(fmtRes, fname, exists(fname));
} }
foreach (ref res; oldResources)
{
fname = targetFilename(res);
writefln(fmtOldRes, fname, exists(fname));
}
Formater.separate; Formater.separate;
return; return;
@ -183,15 +189,15 @@ void main(string[] args)
bool done; bool done;
if(!uninstall) if(!uninstall)
{ {
enum extractMsg = [": FAILURE", ": extracted"]; static immutable extractMsg = [": FAILURE", ": extracted"];
enum oldMsg = [": FAILURE", ": removed old file"]; static immutable oldMsg = [": FAILURE", ": removed old file"];
foreach(res; ceResources) foreach (ref res; ceResources)
{ {
done = installResource(res); done = installResource(res);
Formater.justify!'L'(res.destName ~ extractMsg[done]); Formater.justify!'L'(res.destName ~ extractMsg[done]);
failures += !done; failures += !done;
} }
foreach(res; oldResources) foreach (ref res; oldResources)
{ {
if (!res.targetFilename.exists) if (!res.targetFilename.exists)
continue; continue;
@ -199,7 +205,7 @@ void main(string[] args)
Formater.justify!'L'(res.destName ~ oldMsg[done]); Formater.justify!'L'(res.destName ~ oldMsg[done]);
failures += !done; failures += !done;
} }
if (!nodcd) foreach(res; dcdResources) if (!nodcd) foreach (ref res; dcdResources)
{ {
done = installResource(res); done = installResource(res);
Formater.justify!'L'(res.destName ~ extractMsg[done]); Formater.justify!'L'(res.destName ~ extractMsg[done]);
@ -236,19 +242,19 @@ void main(string[] args)
} }
// uninstall // uninstall
static immutable rmMsg = [": FAILURE", ": deleted"]; static immutable rmMsg = [": FAILURE", ": deleted"];
foreach(res; ceResources) foreach (ref res; ceResources)
{ {
done = uninstallResource(res); done = uninstallResource(res);
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 (ref res; dcdResources)
{ {
done = uninstallResource(res); done = uninstallResource(res);
Formater.justify!'L'(res.destName ~ rmMsg[done]); Formater.justify!'L'(res.destName ~ rmMsg[done]);
failures += !done; failures += !done;
} }
foreach(res; oldResources) foreach (ref res; oldResources)
{ {
if (!res.targetFilename.exists) if (!res.targetFilename.exists)
continue; continue;
@ -259,8 +265,10 @@ void main(string[] args)
// remove $PF folder // remove $PF folder
version(Windows) version(Windows)
{ {
try rmdir(exePath); try
catch(FileException e) failures++; rmdir(exePath);
catch(FileException e)
failures++;
} }
Formater.separate; Formater.separate;
@ -326,8 +334,10 @@ bool uninstallResource(Resource resource)
bool tryRemove(string fname) bool tryRemove(string fname)
{ {
bool result = true; bool result = true;
try remove(fname); try
catch (FileException e) {result = false;} remove(fname);
catch (FileException e)
result = false;
return result; return result;
} }
@ -392,8 +402,8 @@ void postUninstall()
/// splits the version identifier used in filenames /// splits the version identifier used in filenames
string splitVer() string splitVer()
{ {
import std.regex: matchAll, regex; import std.regex: matchAll, ctRegex;
return matchAll(import("version.txt"), regex("\\d+|\\D+")) return matchAll(import("version.txt"), ctRegex!("\\d+|\\D+"))
.join.join(" ").stripRight; .join.join(" ").stripRight;
} }