From b900065d1846ef731d1618579fbfa9fa484f7af1 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Fri, 6 Jun 2014 10:34:25 -0400 Subject: [PATCH] Reorganized branding functionality --- .../WindowsFormsEngine.cs | 190 +++++++++--------- .../UniversalEditor.UserInterface/Engine.cs | 17 ++ 2 files changed, 113 insertions(+), 94 deletions(-) diff --git a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs index f5965813..630392a0 100644 --- a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs +++ b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs @@ -48,6 +48,102 @@ namespace UniversalEditor.UserInterface.WindowsForms } } + protected override void InitializeBranding() + { + base.InitializeBranding(); + + // First, attempt to load the branding from Branding.uxt + string BrandingFileName = BasePath + System.IO.Path.DirectorySeparatorChar.ToString() + "Branding.uxt"; + if (System.IO.File.Exists(BrandingFileName)) + { + FileSystemObjectModel fsom = new FileSystemObjectModel(); + FileAccessor fa = new FileAccessor(BrandingFileName); + Document.Load(fsom, new UXTDataFormat(), fa, false); + + UniversalEditor.ObjectModels.FileSystem.File fileSplashScreenImage = fsom.Files["SplashScreen.png"]; + if (fileSplashScreenImage != null) + { + System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenImage.GetDataAsByteArray()); + Configuration.SplashScreen.Image = System.Drawing.Image.FromStream(ms); + } + + UniversalEditor.ObjectModels.FileSystem.File fileSplashScreenSound = fsom.Files["SplashScreen.wav"]; + if (fileSplashScreenSound != null) + { + System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenSound.GetDataAsByteArray()); + Configuration.SplashScreen.Sound = ms; + } + + UniversalEditor.ObjectModels.FileSystem.File fileMainIcon = fsom.Files["MainIcon.ico"]; + if (fileMainIcon != null) + { + System.IO.MemoryStream ms = new System.IO.MemoryStream(fileMainIcon.GetDataAsByteArray()); + Configuration.MainIcon = new System.Drawing.Icon(ms); + } + + UniversalEditor.ObjectModels.FileSystem.File fileConfiguration = fsom.Files["Configuration.upl"]; + if (fileConfiguration != null) + { + System.IO.MemoryStream ms = new System.IO.MemoryStream(fileConfiguration.GetDataAsByteArray()); + + UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel(); + Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new StreamAccessor(ms), true); + + Configuration.ApplicationName = plomBranding.GetValue(new string[] { "Application", "Title" }, String.Empty); + + Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "DarkColor" }, "#2A0068")); + Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF")); + } + + fa.Close(); + } + + // Now, determine if we should override any branding details with local copies + if (System.IO.Directory.Exists(BasePath + System.IO.Path.DirectorySeparatorChar.ToString() + "Branding")) + { + string SplashScreenImageFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] + { + BasePath, + "Branding", + "SplashScreen.png" + }); + if (System.IO.File.Exists(SplashScreenImageFileName)) Configuration.SplashScreen.ImageFileName = SplashScreenImageFileName; + + string SplashScreenSoundFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] + { + BasePath, + "Branding", + "SplashScreen.wav" + }); + if (System.IO.File.Exists(SplashScreenSoundFileName)) Configuration.SplashScreen.SoundFileName = SplashScreenSoundFileName; + + string MainIconFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] + { + BasePath, + "Branding", + "MainIcon.ico" + }); + if (System.IO.File.Exists(MainIconFileName)) Configuration.MainIcon = System.Drawing.Icon.ExtractAssociatedIcon(MainIconFileName); + + string ConfigurationFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] + { + BasePath, + "Branding", + "Configuration.upl" + }); + if (System.IO.File.Exists(ConfigurationFileName)) + { + UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel(); + Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new FileAccessor(ConfigurationFileName), true); + + Configuration.ApplicationName = plomBranding.GetValue(new string[] { "Application", "Title" }, String.Empty); + + Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "DarkColor" }, "#2A0068")); + Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF")); + } + } + } + [STAThreadAttribute()] protected override void MainLoop() { @@ -61,8 +157,6 @@ namespace UniversalEditor.UserInterface.WindowsForms // AwesomeControls.Theming.BuiltinThemes.SlickTheme theme = new AwesomeControls.Theming.BuiltinThemes.SlickTheme(); AwesomeControls.Theming.Theme.CurrentTheme = theme; - Branding_Initialize(); - if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler(WindowsFormsEngine.SingleInstanceManager_Callback))) return; Glue.ApplicationInformation.ApplicationID = new Guid("{b359fe9a-080a-43fc-ae38-00ba7ac1703e}"); @@ -125,98 +219,6 @@ namespace UniversalEditor.UserInterface.WindowsForms Glue.Common.Methods.SendApplicationEvent(new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.ApplicationStop)); } - private static void Branding_Initialize() - { - string BasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); - if (System.IO.Directory.Exists(BasePath + System.IO.Path.DirectorySeparatorChar.ToString() + "Branding")) - { - string SplashScreenImageFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] - { - BasePath, - "Branding", - "SplashScreen.png" - }); - if (System.IO.File.Exists(SplashScreenImageFileName)) Configuration.SplashScreen.ImageFileName = SplashScreenImageFileName; - - string SplashScreenSoundFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] - { - BasePath, - "Branding", - "SplashScreen.wav" - }); - if (System.IO.File.Exists(SplashScreenSoundFileName)) Configuration.SplashScreen.SoundFileName = SplashScreenSoundFileName; - - string MainIconFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] - { - BasePath, - "Branding", - "MainIcon.ico" - }); - if (System.IO.File.Exists(MainIconFileName)) Configuration.MainIcon = System.Drawing.Icon.ExtractAssociatedIcon(MainIconFileName); - - string ConfigurationFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] - { - BasePath, - "Branding", - "Configuration.upl" - }); - if (System.IO.File.Exists(ConfigurationFileName)) - { - UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel(); - Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new FileAccessor(ConfigurationFileName), true); - - Configuration.ApplicationName = plomBranding.GetValue(new string[] { "Application", "Title" }, String.Empty); - - Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "DarkColor" }, "#2A0068")); - Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF")); - } - } - else if (System.IO.File.Exists(BasePath + System.IO.Path.DirectorySeparatorChar.ToString() + "Branding.uxt")) - { - string BrandingFileName = BasePath + System.IO.Path.DirectorySeparatorChar.ToString() + "Branding.uxt"; - FileSystemObjectModel fsom = new FileSystemObjectModel(); - FileAccessor fa = new FileAccessor(BrandingFileName); - Document.Load(fsom, new UXTDataFormat(), fa, false); - - UniversalEditor.ObjectModels.FileSystem.File fileSplashScreenImage = fsom.Files["SplashScreen.png"]; - if (fileSplashScreenImage != null) - { - System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenImage.GetDataAsByteArray()); - Configuration.SplashScreen.Image = System.Drawing.Image.FromStream(ms); - } - - UniversalEditor.ObjectModels.FileSystem.File fileSplashScreenSound = fsom.Files["SplashScreen.wav"]; - if (fileSplashScreenSound != null) - { - System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenSound.GetDataAsByteArray()); - Configuration.SplashScreen.Sound = ms; - } - - UniversalEditor.ObjectModels.FileSystem.File fileMainIcon = fsom.Files["MainIcon.ico"]; - if (fileMainIcon != null) - { - System.IO.MemoryStream ms = new System.IO.MemoryStream(fileMainIcon.GetDataAsByteArray()); - Configuration.MainIcon = new System.Drawing.Icon(ms); - } - - UniversalEditor.ObjectModels.FileSystem.File fileConfiguration = fsom.Files["Configuration.upl"]; - if (fileConfiguration != null) - { - System.IO.MemoryStream ms = new System.IO.MemoryStream(fileConfiguration.GetDataAsByteArray()); - - UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel(); - Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new StreamAccessor(ms), true); - - Configuration.ApplicationName = plomBranding.GetValue(new string[] { "Application", "Title" }, String.Empty); - - Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "DarkColor" }, "#2A0068")); - Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF")); - } - - fa.Close(); - } - } - private static System.Drawing.Color ParseColor(string htmlCode) { int iR = 0, iG = 0, iB = 0; diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs index 27410308..34faed53 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using UniversalEditor.Accessors; +using UniversalEditor.ObjectModels.FileSystem; namespace UniversalEditor.UserInterface { @@ -12,6 +14,14 @@ namespace UniversalEditor.UserInterface private System.Collections.ObjectModel.ReadOnlyCollection mvarSelectedFileNames = null; public System.Collections.ObjectModel.ReadOnlyCollection SelectedFileNames { get { return mvarSelectedFileNames; } } + private string mvarBasePath = String.Empty; + public string BasePath { get { return mvarBasePath; } } + + protected virtual void InitializeBranding() + { + + } + public void StartApplication() { string[] args1 = Environment.GetCommandLineArgs(); @@ -25,6 +35,13 @@ namespace UniversalEditor.UserInterface } mvarSelectedFileNames = new System.Collections.ObjectModel.ReadOnlyCollection(selectedFileNames); + // Set up the base path for the current application. Should this be able to be + // overridden with a switch (/basepath:...) ? + mvarBasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + + // Initialize the branding for the selected application + InitializeBranding(); + MainLoop(); } }