Skip to content

Commit

Permalink
continuation of commits 3e82bda + 337dc9e : make the compiled target …
Browse files Browse the repository at this point in the history
…directory tree available to the DevStudio Design View to grab external files, e.g. the splash screen image.
  • Loading branch information
GerHobbelt committed Oct 22, 2019
1 parent 3e82bda commit 6f95dd6
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 203 deletions.
100 changes: 17 additions & 83 deletions Qiqqa.Build/patch_settings_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ if (opts._.length != 1) {



// construct the path to the settings.settings file as managed by Visual Studio: we're going to patch these values into that master file:
var settings_path = path.join(opts._[0], "Properties/Settings.settings");
// construct the path to the Misc/Constants.cs file: we're going to patch these values into that master file:
var settings_path = path.join(opts._[0], "Misc/Constants.cs");
if (fs.existsSync(settings_path))
{
var xml_str = fs.readFileSync(settings_path, 'utf8');
var original_xml_str = xml_str;
var cs_str = fs.readFileSync(settings_path, 'utf8');
var original_cs_str = cs_str;

var names = [ "TargetDir", "ProjectDir", "SolutionDir", "Build" ];
for (var key in names) {
Expand All @@ -54,38 +54,28 @@ if (fs.existsSync(settings_path))
console.error(`key ${name} not found in provided commandline parameters?!`);
}

// <Setting Name="TargetDir" Type="System.String" Scope="Application">
// <Value Profile="(Default)">$(TargetDir)</Value>
// </Setting>
var re = new RegExp(`Name="${name}"[^]+?</Setting>`, 'g');
if (opts.debug) console.log("NAME regexp + match = ", re, re.exec(xml_str));
// public const string QiqqaDevProjectDir = "VANILLA_REFERENCE";
var re = new RegExp(`public\\s+const\\s+string\\s+QiqqaDev${name}\\s*=\\s*"[^"]*";`, 'g');
if (opts.debug) console.log("NAME regexp + match = ", re, re.exec(cs_str));

xml_str = xml_str.replace(re, function (m) {
var re2 = new RegExp('<Value Profile="([^"]*)">([^]*?)</Value>|<Value Profile="([^"]*)" />', 'g');
cs_str = cs_str.replace(re, function (m) {
if (opts.debug) console.log("processing NAME match = ", name, m);

if (opts.debug) console.log("processing NAME match = ", name, m, re2, re2.exec(m));
var dst = opts[name];
dst = dst.replace(/[\\/]/g, '/');

m = m.replace(re2, function (m2, p1, p2) {
if (opts.debug) console.log("processing NAME SUBmatch = ", name, m2, p1, p2, re2);

var dst = opts[name];
dst = dst.replace(/[\\/]/g, '/');

return `<Value Profile="${p1}">${dst}</Value>`;
});

return m;
return `public const string QiqqaDev${name} = "${dst}";`;
});
}

if (opts.debug) console.log("Resulting XML:", xml_str);
if (opts.debug) console.log("Resulting C#:", cs_str);

if (original_xml_str != xml_str) {
console.log("Rewriting the settings file: ", settings_path);
if (original_cs_str != cs_str) {
console.log("Rewriting the constants file: ", settings_path);

fs.writeFileSync(settings_path, xml_str, 'utf8');
fs.writeFileSync(settings_path, cs_str, 'utf8');
} else {
console.log("Nothing to rewrite in the settings file: ", settings_path);
console.log("Nothing to rewrite in the constants file: ", settings_path);
}
}
else
Expand All @@ -94,61 +84,5 @@ else
}



// construct the path to the app.config file as managed by Visual Studio: we're going to patch these values into that master file:
var settings_path = path.join(opts._[0], "app.config");
if (fs.existsSync(settings_path))
{
var xml_str = fs.readFileSync(settings_path, 'utf8');
var original_xml_str = xml_str;

var names = [ "TargetDir", "ProjectDir", "SolutionDir", "Build" ];
for (var key in names) {
var name = names[key];

if (!opts[name]) {
console.error(`key ${name} not found in provided commandline parameters?!`);
}

// <setting name="TargetDir" serializeAs="String">
// <value>$(TargetDir)</value>
// </setting>
var re = new RegExp(`<setting name="${name}"[^]+?</setting>`, 'g');
if (opts.debug) console.log("NAME regexp + match = ", re, re.exec(xml_str));

xml_str = xml_str.replace(re, function (m) {
var re2 = new RegExp('<value>([^]*?)</value>|<value />', 'g');

if (opts.debug) console.log("processing NAME match = ", name, m, re2, re2.exec(m));
m = m.replace(re2, function (m2, p1) {
if (opts.debug) console.log("processing NAME SUBmatch = ", name, m2, p1, re2);

var dst = opts[name];
dst = dst.replace(/[\\/]/g, '/');

return `<value>${dst}</value>`;
});

return m;
});
}

if (opts.debug) console.log("Resulting XML:", xml_str);

if (original_xml_str != xml_str) {
console.log("Rewriting the settings file: ", settings_path);

fs.writeFileSync(settings_path, xml_str, 'utf8');
} else {
console.log("Nothing to rewrite in the settings file: ", settings_path);
}
}
else
{
throw new Error("file does not exist: " + settings_path);
}



process.exit(0);

44 changes: 43 additions & 1 deletion Qiqqa/Main/SplashScreenStuff/SplashScreenWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Utilities;
using Utilities.GUI;
using Utilities.Misc;
using Application = System.Windows.Forms.Application;

namespace Qiqqa.Main.SplashScreenStuff
Expand All @@ -18,7 +21,46 @@ public static BitmapImage GetSplashImage()
string image_filename = Path.GetFullPath(Path.Combine(Common.Configuration.ConfigurationManager.Instance.StartupDirectoryForQiqqa, @"Qiqqa.jpg"));
if (!File.Exists(image_filename))
{
throw new ApplicationException($"Cannot locate the application splash image file '{image_filename}'. Looks like the Qiqqa installation is buggered. Please report this at https://github.com/jimmejardine/qiqqa-open-source/issues");
try
{
throw new ApplicationException($"Cannot locate the application splash image file '{image_filename}'. Looks like the Qiqqa installation is buggered. Please report this at https://github.com/jimmejardine/qiqqa-open-source/issues");
}
catch (Exception ex)
{
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);

StringBuilder sb = new StringBuilder();

sb.AppendLine(ex.Message + "\n -- ");
sb.AppendLine($"Designer: {Runtime.IsRunningInVisualStudioDesigner},");
sb.AppendLine($"S1:{System.Reflection.Assembly.GetExecutingAssembly().CodeBase},");
sb.AppendLine($"s2:{System.Reflection.Assembly.GetExecutingAssembly().Location},");
sb.AppendLine($"S3:{System.Windows.Forms.Application.StartupPath},");

// c# getassembly is a type, which is not valid in the given context
TriState to = new TriState();
Type t = to.GetType();

sb.AppendLine($"S4:{System.Reflection.Assembly.GetAssembly(t).CodeBase},");
sb.AppendLine($"s5:{System.Reflection.Assembly.GetAssembly(t).Location},");

// Output to the console.
sb.AppendLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine("New domain: " + domain.FriendlyName);
sb.AppendLine("Application base is: " + domain.BaseDirectory);
sb.AppendLine("Relative search path is: " + domain.RelativeSearchPath);
sb.AppendLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
AppDomain.Unload(domain);

sb.AppendLine(Utilities.Constants.QiqqaDevSolutionDir);
sb.AppendLine(Utilities.Constants.QiqqaDevProjectDir);
sb.AppendLine(Utilities.Constants.QiqqaDevTargetDir);
sb.AppendLine(Utilities.Constants.QiqqaDevBuild);

Logging.Error(sb.ToString());

throw new Exception(sb.ToString(), ex);
}
}
BitmapImage bi = new BitmapImage();
bi.BeginInit();
Expand Down
6 changes: 4 additions & 2 deletions Utilities/DetectUnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public static string StartupDirectoryForQiqqa
if (Runtime.IsRunningInVisualStudioDesigner && null == _StartupDirectoryForQiqqa)
{
//string s1 = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
string loc = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string s2 = System.Reflection.Assembly.GetExecutingAssembly().Location;
//string s3 = System.Windows.Forms.Application.StartupPath;
string basedir = Path.GetFullPath(Path.GetDirectoryName(Path.GetFullPath(loc)));
//string basedir = Path.GetFullPath(Path.GetDirectoryName(Path.GetFullPath(loc)));
string loc = Path.Combine(Utilities.Constants.QiqqaDevSolutionDir, "Qiqqa/bin/", Utilities.Constants.QiqqaDevBuild);
string basedir = Path.GetFullPath(loc);
_StartupDirectoryForQiqqa = basedir;
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions Utilities/Misc/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@ public class Constants
public const string UNKNOWN_YEAR = "(unknown year)";

public const string VanillaReferenceFileType = "VANILLA_REFERENCE";

// These 4 constants are live-patched by the Pre-build task (Qiqqa.Build/patch_settings_file.js)
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
public const string QiqqaDevProjectDir = "W:/Users/Ger/Projects/sites/library.visyond.gov/80/lib/tooling/qiqqa/Utilities/";
public const string QiqqaDevSolutionDir = "W:/Users/Ger/Projects/sites/library.visyond.gov/80/lib/tooling/qiqqa/";
public const string QiqqaDevTargetDir = "W:/Users/Ger/Projects/sites/library.visyond.gov/80/lib/tooling/qiqqa/Utilities/bin/Debug/";
public const string QiqqaDevBuild = "Debug";
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// These 4 constants are live-patched by the Pre-build task (Qiqqa.Build/patch_settings_file.js)
}
}
53 changes: 0 additions & 53 deletions Utilities/Properties/Settings.Designer.cs

This file was deleted.

15 changes: 0 additions & 15 deletions Utilities/Properties/Settings.settings

This file was deleted.

28 changes: 0 additions & 28 deletions Utilities/Settings.cs

This file was deleted.

21 changes: 0 additions & 21 deletions Utilities/app.config

This file was deleted.

0 comments on commit 6f95dd6

Please sign in to comment.