diff --git a/dvm/commands/DvmInstall.d b/dvm/commands/DvmInstall.d index 3f2f667..9c57081 100644 --- a/dvm/commands/DvmInstall.d +++ b/dvm/commands/DvmInstall.d @@ -22,8 +22,8 @@ class DvmInstall : Command { private { - const postInstallInstrcutions = import("post_install_instructions.txt"); - const failedInstallInstrcutions = import("failed_install_instructions.txt"); + const postInstallInstructions = import("post_install_instructions.txt"); + const failedInstallInstructions = import("failed_install_instructions.txt"); version (Posix) const dvmScript = import("dvm.sh"); @@ -49,7 +49,7 @@ private: copyExecutable; writeScript; setPermissions; - installBashInclude(createBashInclude); + version (Posix) installBashInclude(createBashInclude); } void update () @@ -87,11 +87,15 @@ private: void setPermissions () { - verbose("Setting permissions:"); - permission(options.path.dvmScript, "+x"); - permission(options.path.dvmExecutable, "+x"); + version (Posix) + { + verbose("Setting permissions:"); + permission(options.path.dvmScript, "+x"); + permission(options.path.dvmExecutable, "+x"); + } } + version (Posix) void installBashInclude (ShellScript sh) { auto home = homeFolder; @@ -107,12 +111,12 @@ private: else throw new DvmException(format(`Cannot find "{}" or "{}". Please perform the post installation manually by following the instructions below:{}{}`, - bashrc, bash_profile, "\n\n", failedInstallInstrcutions), __FILE__, __LINE__); + bashrc, bash_profile, "\n\n", failedInstallInstructions), __FILE__, __LINE__); verbose("Installing dvm in the shell loading file: ", shPath); File.append(shPath, sh.content); - println(postInstallInstrcutions); + println(postInstallInstructions); } void createPath (string path) @@ -123,10 +127,13 @@ private: void permission (string path, string mode) { - verbose(options.indentation, "mode: " ~ mode); - verbose(options.indentation, "file: " ~ path, '\n'); - - Path.permission(path, mode); + version (Posix) + { + verbose(options.indentation, "mode: " ~ mode); + verbose(options.indentation, "file: " ~ path, '\n'); + + Path.permission(path, mode); + } } void copy (string source, string destination) diff --git a/dvm/commands/Fetch.d b/dvm/commands/Fetch.d index 650639f..33765fb 100644 --- a/dvm/commands/Fetch.d +++ b/dvm/commands/Fetch.d @@ -78,9 +78,22 @@ protected: const int width = 40; int num = width; - const clearLine = "\033[1K"; // clear backwards - const saveCursor = "\0337"; - const restoreCursor = "\0338"; + version (Posix) + { + const clearLine = "\033[1K"; // clear backwards + const saveCursor = "\0337"; + const restoreCursor = "\0338"; + } + + else + { + const clearLine = "\r"; + + // Leaving these empty string causes a linker error: + // http://d.puremagic.com/issues/show_bug.cgi?id=4324 + const saveCursor = "\0"; + const restoreCursor = "\0"; + } print(saveCursor); @@ -119,6 +132,7 @@ protected: void writeFile (void[] data, string filename) { auto file = new File(filename, File.WriteCreate); + scope(exit) file.close(); file.write(data); } diff --git a/dvm/commands/Install.d b/dvm/commands/Install.d index 52c1b6d..c83af01 100644 --- a/dvm/commands/Install.d +++ b/dvm/commands/Install.d @@ -311,10 +311,13 @@ private: void permission (string path, string mode) { - verbose(options.indentation, "mode: " ~ mode); - verbose(options.indentation, "file: " ~ path, '\n'); - - Path.permission(path, mode); + version (Posix) + { + verbose(options.indentation, "mode: " ~ mode); + verbose(options.indentation, "file: " ~ path, '\n'); + + Path.permission(path, mode); + } } string getLibSource (string platformRoot) diff --git a/dvm/commands/Use.d b/dvm/commands/Use.d index 12844fe..9f7d00c 100644 --- a/dvm/commands/Use.d +++ b/dvm/commands/Use.d @@ -86,10 +86,13 @@ private: void setPermission (string path, string mode) { - verbose(options.indentation, "mode: ", mode); - verbose(options.indentation, "file: ", path); + version (Posix) + { + verbose(options.indentation, "mode: ", mode); + verbose(options.indentation, "file: ", path); - permission(path, mode); + permission(path, mode); + } } ShellScript createShellScript () diff --git a/dvm/dvm/Application.d b/dvm/dvm/Application.d index 513263d..9a79073 100644 --- a/dvm/dvm/Application.d +++ b/dvm/dvm/Application.d @@ -19,6 +19,8 @@ import dvm.util._; import dvm.commands._; import dvm.commands.Install; +version (Windows) pragma(lib, "zlib.lib"); + class Application { private static Application instance_; diff --git a/dvm/dvm/Options.d b/dvm/dvm/Options.d index cd07ccb..b16b8db 100644 --- a/dvm/dvm/Options.d +++ b/dvm/dvm/Options.d @@ -7,6 +7,7 @@ module dvm.dvm.Options; import tango.io.Path; +import tango.sys.Environment; import tango.sys.HomeFolder; import dvm.core.string; @@ -107,8 +108,12 @@ private struct Path { if (home_.length > 0) return home_; + + version (Posix) + return home_ = homeFolder; - return home_ = homeFolder; + version (Windows) + return home_ = standard(Environment.get("APPDATA")); } string dvm () diff --git a/dvm/dvm/ShellScript.d b/dvm/dvm/ShellScript.d index cef257f..e95dd1f 100644 --- a/dvm/dvm/ShellScript.d +++ b/dvm/dvm/ShellScript.d @@ -57,12 +57,20 @@ class ShellScript return this; } + version (Posix) ShellScript exec (string name, string args = "", string a = "") { append(Sh.exec(name, args, a)); return this; } + version (Windows) + ShellScript exec (string name, string args = "") + { + append(Sh.exec(name, args)); + return this; + } + ShellScript export_ (string name, string content, bool quote = true) { append(Sh.export_(name, content, quote)); @@ -256,7 +264,7 @@ struct Sh return "%*"; } - string command (string c) + string comment (string c) { return "rem " ~ c; } @@ -266,7 +274,7 @@ struct Sh return format("set {}={}", name, value); } - void export_ (string name, string content, bool quote = true) + string export_ (string name, string content, bool quote = true) { return format("set {}={}", name, content); } @@ -276,14 +284,22 @@ struct Sh return format("call {}", path); } - string exec (string command) + string exec (string name, string args = ""/+, string a = ""+/) { - return source(command); + /+a = a == "" ? "" : format("-a {} ", a); + args = args == "" ? "" : ' ' ~ args;+/ + + return format("call {}{}", name, args); } string ifFileIsNotEmpty (string path, string delegate () block) { - return format("if exist {} {}", path, block()); + return format("if exist {} ( {} )", path, block()); + } + + string variable (string name, bool quote = true) + { + return quote ? format(`"%{}%"`, name) : '%' ~ name ~ '%'; } } } diff --git a/dvm/dvm/Wrapper.d b/dvm/dvm/Wrapper.d index 0948499..c972312 100644 --- a/dvm/dvm/Wrapper.d +++ b/dvm/dvm/Wrapper.d @@ -44,7 +44,8 @@ struct Wrapper sh.nl; sh.ifFileIsNotEmpty(dmdPath, { - sh.exec(dmdPath, Sh.allArgs, dmdPath); + version (Posix) sh.exec(dmdPath, Sh.allArgs, dmdPath); + version (Windows) sh.exec(dmdPath, Sh.allArgs); }, { sh.printError(format(`Missing target: "{}"`, target), true); }); diff --git a/dvm/io/Path.d b/dvm/io/Path.d index dc76965..19492ca 100644 --- a/dvm/io/Path.d +++ b/dvm/io/Path.d @@ -8,7 +8,7 @@ module dvm.io.Path; import tango.core.Exception; public import tango.io.Path; -import tango.stdc.posix.sys.stat; +version (Posix) import tango.stdc.posix.sys.stat; import tango.sys.Common; import dvm.core._; @@ -56,6 +56,7 @@ int remove (string path, bool recursive = false) return removePath(path) ? result + 1 : result; } +version (Posix) enum Owner { Read = S_IRUSR, @@ -64,6 +65,7 @@ enum Owner All = S_IRWXU } +version (Posix) enum Group { Read = S_IRGRP, @@ -72,6 +74,7 @@ enum Group All = S_IRWXG } +version (Posix) enum Others { Read = S_IROTH, @@ -80,12 +83,14 @@ enum Others All = S_IRWXO } +version (Posix) void permission (string path, ushort mode) { if (chmod((path ~ '\0').ptr, mode) == -1) throw new IOException(path ~ ": " ~ SysError.lastMsg); } +version (Posix) private template permissions (alias reference) { const permissions = "if (add) @@ -118,6 +123,7 @@ void validatePath (string path) throw new IOException("File not found \"" ~ path ~ "\""); } +version (Posix) void permission (string path, string mode) { ushort m = permission(path); @@ -182,6 +188,7 @@ void permission (string path, string mode) permission(path, m); } +version (Posix) private ushort permission (string path) { int status; diff --git a/resources/dvm.bat b/resources/dvm.bat new file mode 100644 index 0000000..dd63c5b --- /dev/null +++ b/resources/dvm.bat @@ -0,0 +1,30 @@ +@echo off + +set dvm_prefix=%APPDATA%\ +set dvm_path=%dvm_prefix%dvm + +set dvm_tmp_path=%dvm_path%/tmp +set dvm_result_path=%dvm_tmp_path%/result.bat +set dvm_bin_path=%dvm_path%/bin +set dvm_exe_path=%dvm_bin_path%/dvm.exe +set dvm_default_env_path=%dvm_path%/env/default +set dvm_default_bin_path=%dvm_bin_path%/dvm-default-dc +set dvm_current_path=%dvm_bin_path%/dvm-current-dc + +set PATH=%dvm_bin_path%;%PATH% + +if exist "%dvm_exe_path%" ( + call "%dvm_default_env_path%" +) + +copy /Y "%dvm_default_bin_path%" "%dvm_current_path%" > NUL + +if exist "%dvm_exe_path%" ( + "%dvm_exe_path%" %* +) + +if exist "%dvm_result_path%" ( + call "%dvm_result_path%" +) + +del /Q /F /S "%dvm_tmp_path%" > NUL diff --git a/zlib.lib b/zlib.lib new file mode 100644 index 0000000..531b6ee Binary files /dev/null and b/zlib.lib differ