From ab207070b2755d07f89106611cf34da34970e529 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sun, 19 Nov 2017 06:50:01 +0100 Subject: [PATCH] first try to load style from current dir in *.style --- src/Interface.cs | 19 ++++++++++++++++--- src/StyleReader.cs | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Interface.cs b/src/Interface.cs index 07c7afbf..9add4f4e 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -196,20 +196,33 @@ namespace Crow //fetch styling info in this order, if member styling is alreadey referenced in previous //assembly, it's ignored. - loadStylingFromAssembly (Assembly.GetEntryAssembly ()); - loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); + loadStylingFrom (Directory.GetCurrentDirectory()); + loadStylingFrom (Assembly.GetEntryAssembly ()); + loadStylingFrom (Assembly.GetExecutingAssembly ()); } /// Search for .style resources in assembly - static void loadStylingFromAssembly (Assembly assembly) { + static void loadStylingFrom (Assembly assembly) { if (assembly == null) return; foreach (string s in assembly .GetManifestResourceNames () .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { + Console.WriteLine ("Loading style: {0}", s); new StyleReader (assembly, s) .Dispose (); } } + static void loadStylingFrom (string styleDirectory) { + if (!Directory.Exists(styleDirectory)) + Console.WriteLine ("Error loading styles: {0} directory not found"); + foreach (string s in Directory.GetFiles(styleDirectory, "*.style",SearchOption.AllDirectories)) { + using (Stream stream = new FileStream(s,FileMode.Open)){ + Console.WriteLine ("Loading style: {0}", s); + new StyleReader (stream, s) + .Dispose (); + } + } + } static void loadCursors(){ //Load cursors XCursor.Cross = XCursorFile.Load ("#Crow.Images.Icons.Cursors.cross").Cursors [0]; diff --git a/src/StyleReader.cs b/src/StyleReader.cs index db12053d..ec04f92f 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -40,7 +40,10 @@ namespace Crow int line = 1; public StyleReader (Assembly assembly, string resId) - : base(assembly.GetManifestResourceStream (resId)) + : this(assembly.GetManifestResourceStream (resId), resId) + {} + public StyleReader (Stream stream, string resId) + : base(stream) { resourceId = resId; string styleKey = resId.Substring (0, resId.Length - 6); -- 2.47.3