1 Commits
Author SHA1 Message Date
josephsmendoza 8c29691361 UI & search improvements 2019-10-17 01:17:50 -07:00
2 changed files with 57 additions and 18 deletions
+1
View File
@@ -15,6 +15,7 @@ configuration "application" {
"$TCLTK_PACKAGE_DIR/dist/library" \
"C:/windows/system32/msvcr110.dll" \
"C:/windows/system32/vcruntime140.dll" \
"lib/libcurl.dll" \
platform="windows"
}
configuration "cli" {
+56 -18
View File
@@ -1,11 +1,40 @@
import tkd.tkdapplication;
import tkd.tkdapplication, tkd.widget.widget;
import adbi;
import std.concurrency, std.parallelism, std.process, std.file, std.regex,
std.path, std.string, std.algorithm.searching;
std.path, std.string, std.algorithm.searching, std.stdio, std.uni;
import core.time;
string[] skip = ["temp"];
Widget packPreset(Widget w) {
return w.pack(0, 0, GeometrySide.top, GeometryFill.both, AnchorPosition.center, true);
}
bool isWriteable(DirEntry d) {
try
File(d.name, "a").close();
catch (Exception e)
return false;
return true;
}
bool isInstallable(DirEntry d) {
if (!d.isWriteable)
return false;
foreach (s; skip) {
if (d.name.toLower.canFind(s)) {
return false;
}
}
return true;
}
class Application : TkdApplication {
private Label instructionLabel;
private Label statusLabel;
private Tid searchThread;
enum {
STATUS = LogLevel.max + 1,
INSTRUCT,
@@ -15,17 +44,19 @@ class Application : TkdApplication {
static void search() {
version (Windows) {
skip ~= "recycle.bin";
string regex = "(.*)(\\\\)(adb.exe|fastboot.exe)($)";
string[] dirs = [
"C:\\Program Files", "C:\\Program Files (x86)",
"C:"~environment.get("HOMEPATH"), "C:\\"
"C:" ~ environment.get("HOMEPATH"), "C:\\"
];
} else
string regex = "(.*)(\\/)(adb|fastboot)($)";
version (linux) string[] dirs = ["/usr", "/opt"];
version (OSX) string[] dirs = ["/Library", "/Applications"];
version (Posix)
version (Posix) {
dirs ~= ["~".expandTilde, "/"];
}
adbi.log = &Application.log;
string[] results;
void search(DirEntry dir) {
@@ -42,7 +73,7 @@ class Application : TkdApplication {
search(d);
else if (d.name.matchFirst(regex)) {
string s = d.name.dirName.strip;
if (!results.canFind(s) && s != "") {
if (!results.canFind(s) && d.isInstallable) {
results ~= s;
log(s, OPTION);
}
@@ -57,17 +88,13 @@ class Application : TkdApplication {
log(defaultAllUsersDir, OPTION);
log(defaultUserDir, OPTION);
log("Select install location", INSTRUCT);
results ~= [defaultAllUsersDir, defaultUserDir];
results ~= [defaultAllUsersDir, defaultUserDir, ""];
foreach (string dir; dirs) {
search(DirEntry(dir));
}
log("Search done");
}
private Frame frame;
private Label instructionLabel;
private Label statusLabel;
private Tid searchThread;
static void log(string message, int messageMode = INFO) {
ownerTid.send(messageMode);
ownerTid.send(message);
@@ -88,8 +115,8 @@ class Application : TkdApplication {
adbi.installTools(dir);
adbi.installPath(dir);
log("You can close this window", INSTRUCT);
} catch (Exception e) {
log(cast(string) e.message, ERROR);
} catch (immutable Exception e) {
ownerTid.send(e);
}
}
@@ -105,7 +132,7 @@ class Application : TkdApplication {
case OPTION:
new Button(message).setCommand(delegate(CommandArgs args) {
spawn(&install, message);
}).pack();
}).packPreset();
break;
case ERROR:
import std.stdio;
@@ -118,19 +145,30 @@ class Application : TkdApplication {
mode = INFO;
}
private void receiveException(immutable Exception e) {
throw e;
}
private void idleCommand(CommandArgs args) {
this.mainWindow.setIdleCommand(&idleCommand);
receiveTimeout(seconds(-1), &receiveString, &receiveInt);
receiveTimeout(seconds(-1), &receiveString, &receiveInt, &receiveException);
}
private void exitCommand(CommandArgs args) {
this.exit();
}
private void directoryDialog(CommandArgs args) {
string dir = new DirectoryDialog().show().getResult();
if (dir.isDir)
spawn(&install, dir);
}
override protected void initInterface() {
frame = new Frame().pack();
instructionLabel = new Label(frame, "Please wait").pack();
statusLabel = new Label(frame, "Loading").pack();
this.mainWindow.setMinSize(300, 0);
instructionLabel = new Label("Please wait").pack();
statusLabel = new Label("Loading").pack();
new Button("Manually select folder").setCommand(&directoryDialog).packPreset();
this.mainWindow.setIdleCommand(&idleCommand);
this.mainWindow.setProtocolCommand(WindowProtocol.deleteWindow, &exitCommand);
searchThread = spawn(&search);