// Miguel de Icaza
//
// (C) Novell, Inc 2004
+// (C) 2016 Xamarin Inc
+//
+// Missing features:
+// * Add support for packaging native libraries, extracting at runtime and setting the library path.
+// * Implement --list-targets lists all the available remote targets
//
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using IKVM.Reflection;
-
-
+using System.Linq;
+using System.Diagnostics;
+using System.Net;
using System.Threading.Tasks;
class MakeBundle {
static string machine_config_file = null;
static string config_dir = null;
static string style = "linux";
+ static string os_message = "";
static bool compress;
static bool nomain;
+ static string custom_main = null;
static bool? use_dos2unix = null;
static bool skip_scan;
static string ctor_func;
+ static bool quiet;
+ static string cross_target = null;
+ static string fetch_target = null;
+ static bool custom_mode = true;
+ static string embedded_options = null;
+ static string runtime = null;
+ static string target_server = "https://download.mono-project.com/runtimes/raw/";
static int Main (string [] args)
{
Help ();
return 1;
+ case "--simple":
+ custom_mode = false;
+ autodeps = true;
+ break;
+
+ case "--custom":
+ custom_mode = true;
+ break;
+
case "-c":
compile_only = true;
break;
+
+ case "--local-targets":
+ CommandLocalTargets ();
+ return 0;
+
+ case "--cross":
+ if (i+1 == top){
+ Help ();
+ return 1;
+ }
+ custom_mode = false;
+ autodeps = true;
+ cross_target = args [++i];
+ break;
+
+ case "--fetch-target":
+ if (i+1 == top){
+ Help ();
+ return 1;
+ }
+ fetch_target = args [++i];
+ break;
+
+ case "--list-targets":
+ var wc = new WebClient ();
+ var s = wc.DownloadString (new Uri (target_server + "target-list.txt"));
+ Console.WriteLine ("Cross-compilation targets available:\n" + s);
+
+ return 0;
+ case "--target-server":
+ if (i+1 == top){
+ Help ();
+ return 1;
+ }
+ target_server = args [++i];
+ break;
+
case "-o":
if (i+1 == top){
Help ();
output = args [++i];
break;
+ case "--options":
+ if (i+1 == top){
+ Help ();
+ return 1;
+ }
+ embedded_options = args [++i];
+ break;
+ case "--runtime":
+ if (i+1 == top){
+ Help ();
+ return 1;
+ }
+ runtime = args [++i];
+ break;
case "-oo":
if (i+1 == top){
Help ();
case "--keeptemp":
keeptemp = true;
break;
+
case "--static":
static_link = true;
- Console.WriteLine ("Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking.");
- Console.WriteLine ("See http://www.mono-project.com/Licensing for details on licensing.");
break;
case "--config":
if (i+1 == top) {
machine_config_file = args [++i];
- Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
+ if (!quiet)
+ Console.WriteLine ("WARNING:\n Check that the machine.config file you are bundling\n doesn't contain sensitive information specific to this machine.");
break;
case "--config-dir":
if (i+1 == top) {
case "--nomain":
nomain = true;
break;
+ case "--custom-main":
+ if (i+1 == top) {
+ Help ();
+ return 1;
+ }
+ custom_main = args [++i];
+ break;
case "--style":
if (i+1 == top) {
Help ();
case "--dos2unix=false":
use_dos2unix = false;
break;
+ case "-q":
+ case "--quiet":
+ quiet = true;
+ break;
default:
sources.Add (args [i]);
break;
}
- Console.WriteLine ("Sources: {0} Auto-dependencies: {1}", sources.Count, autodeps);
+ if (!quiet) {
+ Console.WriteLine (os_message);
+ Console.WriteLine ("Sources: {0} Auto-dependencies: {1}", sources.Count, autodeps);
+ }
if (sources.Count == 0 || output == null) {
Help ();
Environment.Exit (1);
foreach (string file in assemblies)
if (!QueueAssembly (files, file))
return 1;
-
- GenerateBundles (files);
- //GenerateJitWrapper ();
+
+ if (fetch_target != null){
+ var truntime = Path.Combine (targets_dir, fetch_target, "mono");
+ Directory.CreateDirectory (Path.GetDirectoryName (truntime));
+ var wc = new WebClient ();
+ var uri = new Uri ($"{target_server}{fetch_target}");
+ try {
+ wc.DownloadFile (uri, truntime);
+ } catch {
+ Console.Error.WriteLine ($"Failure to download the specified runtime from {uri}");
+ File.Delete (truntime);
+ return 1;
+ }
+ return 0;
+ }
+
+ if (custom_mode)
+ GenerateBundles (files);
+ else {
+ if (cross_target == "default")
+ runtime = null;
+ else {
+ var truntime = Path.Combine (targets_dir, cross_target, "mono");
+ if (!File.Exists (truntime)){
+ Console.Error.WriteLine ($"The runtime for the {cross_target} does not exist, use --fetch-target {cross_target} to download first");
+ return 1;
+ }
+ }
+ GeneratePackage (files);
+ }
return 0;
}
+ static string targets_dir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".mono", "targets");
+
+ static void CommandLocalTargets ()
+ {
+ string [] targets;
+
+ Console.WriteLine ("Available targets:");
+ Console.WriteLine ("\tdefault\t- Current System Mono");
+ try {
+ targets = Directory.GetDirectories (targets_dir);
+ } catch {
+ return;
+ }
+ foreach (var target in targets){
+ var p = Path.Combine (target, "mono");
+ if (File.Exists (p))
+ Console.WriteLine ("\t{0}", Path.GetFileName (target));
+ }
+ }
+
static void WriteSymbol (StreamWriter sw, string name, long size)
{
switch (style){
ts.WriteLine ();
}
+
+ class PackageMaker {
+ Dictionary<string, Tuple<long,int>> locations = new Dictionary<string, Tuple<long,int>> ();
+ const int align = 4096;
+ Stream package;
+
+ public PackageMaker (string output)
+ {
+ package = File.Create (output, 128*1024);
+ if (IsUnix){
+ File.SetAttributes (output, unchecked ((FileAttributes) 0x80000000));
+ }
+ }
+
+ public int AddFile (string fname)
+ {
+ using (Stream fileStream = File.OpenRead (fname)){
+ var ret = fileStream.Length;
+
+ Console.WriteLine ("At {0:x} with input {1}", package.Position, fileStream.Length);
+ fileStream.CopyTo (package);
+ package.Position = package.Position + (align - (package.Position % align));
+
+ return (int) ret;
+ }
+ }
+
+ public void Add (string entry, string fname)
+ {
+ var p = package.Position;
+ var size = AddFile (fname);
+
+ locations [entry] = Tuple.Create(p, size);
+ }
+
+ public void AddString (string entry, string text)
+ {
+ var bytes = Encoding.UTF8.GetBytes (text);
+ locations [entry] = Tuple.Create (package.Position, bytes.Length);
+ package.Write (bytes, 0, bytes.Length);
+ package.Position = package.Position + (align - (package.Position % align));
+ }
+
+ public void Dump ()
+ {
+ foreach (var floc in locations.Keys){
+ Console.WriteLine ($"{floc} at {locations[floc]:x}");
+ }
+ }
+
+ public void WriteIndex ()
+ {
+ var indexStart = package.Position;
+ var binary = new BinaryWriter (package);
+
+ binary.Write (locations.Count);
+ foreach (var entry in from entry in locations orderby entry.Value.Item1 ascending select entry){
+ var bytes = Encoding.UTF8.GetBytes (entry.Key);
+ binary.Write (bytes.Length+1);
+ binary.Write (bytes);
+ binary.Write ((byte) 0);
+ binary.Write (entry.Value.Item1);
+ binary.Write (entry.Value.Item2);
+ }
+ binary.Write (indexStart);
+ binary.Write (Encoding.UTF8.GetBytes ("xmonkeysloveplay"));
+ binary.Flush ();
+ }
+
+ public void Close ()
+ {
+ WriteIndex ();
+ package.Close ();
+ package = null;
+ }
+ }
+
+ static bool MaybeAddFile (PackageMaker maker, string code, string file)
+ {
+ if (file == null)
+ return true;
+
+ if (!File.Exists (file)){
+ Console.Error.WriteLine ("The file {0} does not exist", file);
+ return false;
+ }
+ maker.Add (code, file);
+ return true;
+ }
+
+ static bool GeneratePackage (List<string> files)
+ {
+ if (runtime == null){
+ if (IsUnix)
+ runtime = Process.GetCurrentProcess().MainModule.FileName;
+ else {
+ Console.Error.WriteLine ("You must specify at least one runtime with --runtime or --cross");
+ Environment.Exit (1);
+ }
+ }
+ if (!File.Exists (runtime)){
+ Console.Error.WriteLine ($"The specified runtime at {runtime} does not exist");
+ Environment.Exit (1);
+ }
+
+ if (ctor_func != null){
+ Console.Error.WriteLine ("--static-ctor not supported with package bundling, you must use native compilation for this");
+ return false;
+ }
+
+ var maker = new PackageMaker (output);
+ maker.AddFile (runtime);
+
+ foreach (var url in files){
+ string fname = LocateFile (new Uri (url).LocalPath);
+ string aname = Path.GetFileName (fname);
+
+ maker.Add ("assembly:" + aname, fname);
+ if (File.Exists (fname + ".config"))
+ maker.Add ("config:" + aname, fname + ".config");
+ }
+ if (!MaybeAddFile (maker, "systemconfig:", config_file) || !MaybeAddFile (maker, "machineconfig:", machine_config_file))
+ return false;
+
+ if (config_dir != null)
+ maker.Add ("config_dir:", config_dir);
+ if (embedded_options != null)
+ maker.AddString ("options:", embedded_options);
+ maker.Dump ();
+ maker.Close ();
+ return true;
+ }
static void GenerateBundles (List<string> files)
{
// Do the file reading and compression in parallel
Action<string> body = delegate (string url) {
- string fname = new Uri (url).LocalPath;
+ string fname = LocateFile (new Uri (url).LocalPath);
Stream stream = File.OpenRead (fname);
long real_size = stream.Length;
// The non-parallel part
byte [] buffer = new byte [8192];
+ // everything other than a-zA-Z0-9_ needs to be escaped in asm symbols.
+ var symbolEscapeRE = new System.Text.RegularExpressions.Regex ("[^\\w_]");
foreach (var url in files) {
- string fname = new Uri (url).LocalPath;
+ string fname = LocateFile (new Uri (url).LocalPath);
string aname = Path.GetFileName (fname);
- string encoded = aname.Replace ("-", "_").Replace (".", "_");
+ string encoded = symbolEscapeRE.Replace (aname, "_");
if (prog == null)
prog = aname;
var stream = streams [url];
var real_size = sizes [url];
- Console.WriteLine (" embedding: " + fname);
+ if (!quiet)
+ Console.WriteLine (" embedding: " + fname);
WriteSymbol (ts, "assembly_data_" + encoded, stream.Length);
tc.WriteLine ("static CompressedAssembly assembly_bundle_{0} = {{{{\"{1}\"," +
" assembly_data_{0}, {2}}}, {3}}};",
encoded, aname, real_size, stream.Length);
- double ratio = ((double) stream.Length * 100) / real_size;
- Console.WriteLine (" compression ratio: {0:.00}%", ratio);
+ if (!quiet) {
+ double ratio = ((double) stream.Length * 100) / real_size;
+ Console.WriteLine (" compression ratio: {0:.00}%", ratio);
+ }
} else {
tc.WriteLine ("extern const unsigned char assembly_data_{0} [];", encoded);
tc.WriteLine ("static const MonoBundledAssembly assembly_bundle_{0} = {{\"{1}\", assembly_data_{0}, {2}}};",
try {
FileStream cf = File.OpenRead (fname + ".config");
- Console.WriteLine (" config from: " + fname + ".config");
+ if (!quiet)
+ Console.WriteLine (" config from: " + fname + ".config");
tc.WriteLine ("extern const unsigned char assembly_config_{0} [];", encoded);
WriteSymbol (ts, "assembly_config_" + encoded, cf.Length);
WriteBuffer (ts, cf, buffer);
Error (String.Format ("Failure to open {0}", config_file));
return;
}
- Console.WriteLine ("System config from: " + config_file);
+ if (!quiet)
+ Console.WriteLine ("System config from: " + config_file);
tc.WriteLine ("extern const char system_config;");
WriteSymbol (ts, "system_config", config_file.Length);
Error (String.Format ("Failure to open {0}", machine_config_file));
return;
}
- Console.WriteLine ("Machine config from: " + machine_config_file);
+ if (!quiet)
+ Console.WriteLine ("Machine config from: " + machine_config_file);
tc.WriteLine ("extern const char machine_config;");
WriteSymbol (ts, "machine_config", machine_config_file.Length);
string template = s.ReadToEnd ();
tc.Write (template);
- if (!nomain) {
+ if (!nomain && custom_main == null) {
Stream template_main_stream = System.Reflection.Assembly.GetAssembly (typeof(MakeBundle)).GetManifestResourceStream ("template_main.c");
StreamReader st = new StreamReader (template_main_stream);
string maintemplate = st.ReadToEnd ();
tc.Close ();
+ string assembler = GetEnv("AS", "as");
+ string as_cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
+ Execute(as_cmd);
+
if (compile_only)
return;
- Console.WriteLine("Compiling:");
+
+ if (!quiet)
+ Console.WriteLine("Compiling:");
if (style == "windows")
{
- string assembler = GetEnv("AS", "as");
- string as_cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
- Execute(as_cmd);
Func<string, string> quote = (pp) => { return "\"" + pp + "\""; };
string compiler = GetEnv("CC", "cl.exe");
string winsdkPath = GetEnv("WINSDK", @"C:\Program Files (x86)\Windows Kits\8.1");
- string vsPath = GetEnv("VSINCLUDE", @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC");
+ string vsPath = GetEnv("VSINCLUDE", @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC");
string monoPath = GetEnv("MONOPREFIX", @"C:\Program Files (x86)\Mono");
- string[] includes = new string[] {winsdkPath + @"\Include\um", winsdkPath + @"\Include\shared", vsPath + @"\include", monoPath + @"\include\mono-2.0"};
+ string[] includes = new string[] {winsdkPath + @"\Include\um", winsdkPath + @"\Include\shared", vsPath + @"\include", monoPath + @"\include\mono-2.0", "." };
string[] libs = new string[] { winsdkPath + @"\Lib\winv6.3\um\x86" , vsPath + @"\lib" };
- string monoFile;
+ var linkLibraries = new string[] { "kernel32.lib",
+ "version.lib",
+ "Ws2_32.lib",
+ "Mswsock.lib",
+ "Psapi.lib",
+ "shell32.lib",
+ "OleAut32.lib",
+ "ole32.lib",
+ "winmm.lib",
+ "user32.lib",
+ "libvcruntime.lib",
+ "advapi32.lib",
+ "OLDNAMES.lib",
+ "libucrt.lib" };
+
+ string glue_obj = "mkbundle_glue.obj";
+ string monoLib;
- var compilerArgs = new List<string>();
- foreach (string include in includes)
- compilerArgs.Add(String.Format ("/I {0}", quote (include)));
+ if (static_link)
+ monoLib = LocateFile (monoPath + @"\lib\monosgen-2.0-static.lib");
- if (static_link) {
- compilerArgs.Add("/MT");
- monoFile = monoPath + @"\lib\mono-2.0.lib";
- }
else {
- compilerArgs.Add("/MD");
- monoFile = monoPath + @"\lib\mono-2.0.dll";
+ Console.WriteLine ("WARNING: Dynamically linking the Mono runtime on Windows is not a tested option.");
+ monoLib = LocateFile (monoPath + @"\lib\monosgen-2.0.lib");
+ LocateFile (monoPath + @"\lib\monosgen-2.0.dll"); // in this case, the .lib is just the import library, and the .dll is also needed
}
- compilerArgs.Add(temp_c);
- compilerArgs.Add(temp_o);
- compilerArgs.Add("/link");
+ var compilerArgs = new List<string>();
+ compilerArgs.Add("/MT");
- foreach (string lib in libs)
- compilerArgs.Add(String.Format ("/LIBPATH:{0}", quote(lib)));
- compilerArgs.Add (quote(monoFile));
+ foreach (string include in includes)
+ compilerArgs.Add(String.Format ("/I {0}", quote (include)));
- string cl_cmd = String.Format("{0} {1}", compiler, String.Join(" ", compilerArgs.ToArray()));
- Execute (cl_cmd);
+ if (!nomain || custom_main != null) {
+ compilerArgs.Add(quote(temp_c));
+ compilerArgs.Add(quote(temp_o));
+ if (custom_main != null)
+ compilerArgs.Add(quote(custom_main));
+ compilerArgs.Add(quote(monoLib));
+ compilerArgs.Add("/link");
+ compilerArgs.Add("/NODEFAULTLIB");
+ compilerArgs.Add("/SUBSYSTEM:windows");
+ compilerArgs.Add("/ENTRY:mainCRTStartup");
+ compilerArgs.AddRange(linkLibraries);
+ compilerArgs.Add("/out:"+ output);
+
+ string cl_cmd = String.Format("{0} {1}", compiler, String.Join(" ", compilerArgs.ToArray()));
+ Execute (cl_cmd);
+ }
+ else
+ {
+ // we are just creating a .lib
+ compilerArgs.Add("/c"); // compile only
+ compilerArgs.Add(temp_c);
+ compilerArgs.Add(String.Format("/Fo" + glue_obj)); // .obj output name
+
+ string cl_cmd = String.Format("{0} {1}", compiler, String.Join(" ", compilerArgs.ToArray()));
+ Execute (cl_cmd);
+
+ string librarian = GetEnv ("LIB", "lib.exe");
+ var librarianArgs = new List<string> ();
+ librarianArgs.Add (String.Format ("/out:{0}.lib" + output));
+ librarianArgs.Add (temp_o);
+ librarianArgs.Add (glue_obj);
+ librarianArgs.Add (monoLib);
+ string lib_cmd = String.Format("{0} {1}", librarian, String.Join(" ", librarianArgs.ToArray()));
+ Execute (lib_cmd);
+ }
}
else
{
- string assembler = GetEnv("AS", "as");
- string cmd = String.Format("{0} -o {1} {2} ", assembler, temp_o, temp_s);
- Execute(cmd);
-
string zlib = (compress ? "-lz" : "");
string debugging = "-g";
string cc = GetEnv("CC", "cc");
+ string cmd = null;
if (style == "linux")
debugging = "-ggdb";
smonolib = "`pkg-config --variable=libdir mono-2`/libmono-2.0.a ";
else
smonolib = "-Wl,-Bstatic -lmono-2.0 -Wl,-Bdynamic ";
- cmd = String.Format("{4} -o {2} -Wall `pkg-config --cflags mono-2` {0} {3} " +
+ cmd = String.Format("{4} -o '{2}' -Wall `pkg-config --cflags mono-2` {0} {3} " +
"`pkg-config --libs-only-L mono-2` " + smonolib +
"`pkg-config --libs-only-l mono-2 | sed -e \"s/\\-lmono-2.0 //\"` {1}",
temp_c, temp_o, output, zlib, cc);
else
{
- cmd = String.Format("{4} " + debugging + " -o {2} -Wall {0} `pkg-config --cflags --libs mono-2` {3} {1}",
+ cmd = String.Format("{4} " + debugging + " -o '{2}' -Wall {0} `pkg-config --cflags --libs mono-2` {3} {1}",
temp_c, temp_o, output, zlib, cc);
}
Execute (cmd);
}
- Console.WriteLine ("Done");
+ if (!quiet)
+ Console.WriteLine ("Done");
}
}
} finally {
}
assemblies.Add (a.CodeBase);
- } catch (Exception e) {
+ } catch (Exception) {
if (skip_scan) {
- Console.WriteLine ("File will not be scanned: {0}", name);
+ if (!quiet)
+ Console.WriteLine ("File will not be scanned: {0}", name);
assemblies.Add (new Uri (new FileInfo (name).FullName).ToString ());
} else {
throw;
if (!QueueAssembly (files, a.CodeBase))
return false;
}
- } catch (Exception e) {
+ } catch (Exception) {
if (!skip_scan)
throw;
}
}
}
Error ("Cannot find assembly `" + assembly + "'" );
- Console.WriteLine ("Log: \n" + total_log);
+ if (!quiet)
+ Console.WriteLine ("Log: \n" + total_log);
} catch (IKVM.Reflection.BadImageFormatException f) {
if (skip_scan)
throw;
{
Console.WriteLine ("Usage is: mkbundle [options] assembly1 [assembly2...]\n\n" +
"Options:\n" +
- " -c Produce stub only, do not compile\n" +
+ " --config F Bundle system config file `F'\n" +
+ " --config-dir D Set MONO_CFG_DIR to `D'\n" +
+ " --deps Turns on automatic dependency embedding (default on simple)\n" +
+ " -L path Adds `path' to the search path for assemblies\n" +
+ " --machine-config F Use the given file as the machine.config for the application.\n" +
" -o out Specifies output filename\n" +
+ " --nodeps Turns off automatic dependency embedding (default on custom)\n" +
+ " --skip-scan Skip scanning assemblies that could not be loaded (but still embed them).\n" +
+ "\n" +
+ "--simple Simple mode does not require a C toolchain and can cross compile\n" +
+ " --cross TARGET Generates a binary for the given TARGET\n"+
+ " --local-targets Lists locally available targets\n" +
+ " --list-targets Lists available targets on the remote server\n" +
+ " --options OPTIONS Embed the specified Mono command line options on target\n" +
+ " --runtime RUNTIME Manually specifies the Mono runtime to use\n" +
+ " --target-server URL Specified a server to download targets from, default is " + target_server + "\n" +
+ "\n" +
+ "--custom Builds a custom launcher, options for --custom\n" +
+ " -c Produce stub only, do not compile\n" +
" -oo obj Specifies output filename for helper object file\n" +
- " -L path Adds `path' to the search path for assemblies\n" +
- " --nodeps Turns off automatic dependency embedding (default)\n" +
- " --deps Turns on automatic dependency embedding\n" +
" --dos2unix[=true|false]\n" +
" When no value provided, or when `true` specified\n" +
" `dos2unix` will be invoked to convert paths on Windows.\n" +
" When `--dos2unix=false` used, dos2unix is NEVER used.\n" +
" --keeptemp Keeps the temporary files\n" +
- " --config F Bundle system config file `F'\n" +
- " --config-dir D Set MONO_CFG_DIR to `D'\n" +
- " --machine-config F Use the given file as the machine.config for the application.\n" +
" --static Statically link to mono libs\n" +
" --nomain Don't include a main() function, for libraries\n" +
+ " --custom-main C Link the specified compilation unit (.c or .obj) with entry point/init code\n" +
" -z Compress the assemblies before embedding.\n" +
- " --skip-scan Skip scanning assemblies that could not be loaded (but still embed them).\n" +
" --static-ctor ctor Add a constructor call to the supplied function.\n" +
" You need zlib development headers and libraries.\n");
}
static void DetectOS ()
{
if (!IsUnix) {
- Console.WriteLine ("OS is: Windows");
+ os_message = "OS is: Windows";
style = "windows";
return;
}
IntPtr buf = Marshal.AllocHGlobal (8192);
if (uname (buf) != 0){
- Console.WriteLine ("Warning: Unable to detect OS");
+ os_message = "Warning: Unable to detect OS";
Marshal.FreeHGlobal (buf);
return;
}
string os = Marshal.PtrToStringAnsi (buf);
- Console.WriteLine ("OS is: " + os);
+ os_message = "OS is: " + os;
if (os == "Darwin")
style = "osx";
static void Execute (string cmdLine)
{
if (IsUnix) {
- Console.WriteLine (cmdLine);
+ if (!quiet)
+ Console.WriteLine ("[execute cmd]: " + cmdLine);
int ret = system (cmdLine);
if (ret != 0)
{
psi.Arguments = String.Format("-c \"{0}\"", cmdLine);
}
- Console.WriteLine(cmdLine);
+ if (!quiet)
+ Console.WriteLine(cmdLine);
using (Process p = Process.Start (psi)) {
p.WaitForExit ();
int ret = p.ExitCode;
string val = Environment.GetEnvironmentVariable(name);
if (val != null)
{
- Console.WriteLine("{0} = {1}", name, val);
+ if (!quiet)
+ Console.WriteLine("{0} = {1}", name, val);
}
else
{
val = defaultValue;
- Console.WriteLine("{0} = {1} (default)", name, val);
+ if (!quiet)
+ Console.WriteLine("{0} = {1} (default)", name, val);
}
return val;
}
+
+ static string LocateFile(string default_path)
+ {
+ var override_path = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileName(default_path));
+ if (File.Exists(override_path))
+ return override_path;
+ else if (File.Exists(default_path))
+ return default_path;
+ else
+ throw new FileNotFoundException(default_path);
+ }
}