diff --git a/Installer/Resources/Runtime.zip b/Installer/Resources/Runtime.zip index ff8e7f2..770444d 100644 Binary files a/Installer/Resources/Runtime.zip and b/Installer/Resources/Runtime.zip differ diff --git a/Osmo/ConsoleWindow.xaml b/Osmo/ConsoleWindow.xaml new file mode 100644 index 0000000..dade044 --- /dev/null +++ b/Osmo/ConsoleWindow.xaml @@ -0,0 +1,11 @@ + + + diff --git a/Osmo/ConsoleWindow.xaml.cs b/Osmo/ConsoleWindow.xaml.cs new file mode 100644 index 0000000..a644a89 --- /dev/null +++ b/Osmo/ConsoleWindow.xaml.cs @@ -0,0 +1,38 @@ +using Osmo.UI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Osmo +{ + /// + /// Interaction logic for ConsoleWindow.xaml + /// + public partial class ConsoleWindow : Window + { + public ConsoleWindow() + { + InitializeComponent(); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + DebugConsole.Instance.Visibility = Visibility.Collapsed; + } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + DebugConsole.Instance.Visibility = Visibility.Visible; + } + } +} diff --git a/Osmo/Core/Configuration/ProfileManager.cs b/Osmo/Core/Configuration/ProfileManager.cs index 40fd3b1..2007c70 100644 --- a/Osmo/Core/Configuration/ProfileManager.cs +++ b/Osmo/Core/Configuration/ProfileManager.cs @@ -221,7 +221,7 @@ public AppConfiguration GetProfileByName(string profileName) { if (!string.IsNullOrWhiteSpace(profileName)) { - return Profiles.FirstOrDefault(x => x.ProfileName?.Equals(profileName) ?? false); + return Profiles.FirstOrDefault(x => x.ProfileName?.Equals(profileName, StringComparison.CurrentCultureIgnoreCase) ?? false); } else { diff --git a/Osmo/Core/ConsoleHistory.cs b/Osmo/Core/ConsoleHistory.cs new file mode 100644 index 0000000..6e1fed4 --- /dev/null +++ b/Osmo/Core/ConsoleHistory.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; + +namespace Osmo.Core +{ + class ConsoleHistory + { + private List history; + private int capacity; + private int index = -1; + + public ConsoleHistory(int capacity) + { + this.capacity = capacity; + history = new List(capacity); + } + + public void Push(string command) + { + history.Insert(0, command); + index = -1; + + if (history.Count > capacity) + history.RemoveAt(capacity - 1); + } + + public string Peek(bool isUp) + { + if (isUp) + { + if (index < history.Count - 1) + index++; + + + if (index > -1) + return history[index]; + else + return ""; + } + else + { + if (index > 0) + { + index--; + return history[index]; + } + else + { + index = -1; + return ""; + } + } + } + } +} diff --git a/Osmo/Core/FixedValues.cs b/Osmo/Core/FixedValues.cs index 4bab115..a63f7dc 100644 --- a/Osmo/Core/FixedValues.cs +++ b/Osmo/Core/FixedValues.cs @@ -173,13 +173,14 @@ internal static void InitializeReader() Logger.Instance.WriteLog("Skin element details loaded!"); } + //The index refers to the position inside the sidebar internal const int WIZARD_INDEX = 1; internal const int EDITOR_INDEX = 2; internal const int MIXER_INDEX = 3; - internal const int CONFIG_INDEX = 6; - internal const int ABOUT_INDEX = 7; - internal const int TEMPLATE_EDITOR_INDEX = 8; - internal const int RESIZE_TOOL_INDEX = 20; + internal const int RESIZE_TOOL_INDEX = 5; + internal const int TEMPLATE_EDITOR_INDEX = 7; + internal const int CONFIG_INDEX = 8; + internal const int ABOUT_INDEX = 9; internal const string LOCAL_FILENAME = "Runtime.zip"; diff --git a/Osmo/MainWindow.xaml.cs b/Osmo/MainWindow.xaml.cs index 61ba135..2e42bfa 100644 --- a/Osmo/MainWindow.xaml.cs +++ b/Osmo/MainWindow.xaml.cs @@ -495,6 +495,7 @@ private void console_IsVisibleChanged(object sender, DependencyPropertyChangedEv if ((bool)e.NewValue == true) { MinHeight += 200; + console.Height = 200; } else { diff --git a/Osmo/Osmo.csproj b/Osmo/Osmo.csproj index 7098f10..07fc41b 100644 --- a/Osmo/Osmo.csproj +++ b/Osmo/Osmo.csproj @@ -89,6 +89,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -168,6 +172,9 @@ MSBuild:Compile Designer + + ConsoleWindow.xaml + ModeProgressImage.xaml @@ -196,6 +203,7 @@ + @@ -468,6 +476,7 @@ PreserveNewest + diff --git a/Osmo/Properties/AssemblyInfo.cs b/Osmo/Properties/AssemblyInfo.cs index d69dc8d..b854069 100644 --- a/Osmo/Properties/AssemblyInfo.cs +++ b/Osmo/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.0.4.140")] -[assembly: AssemblyFileVersion("0.0.4.140")] +[assembly: AssemblyVersion("0.0.4.147")] +[assembly: AssemblyFileVersion("0.0.4.147")] diff --git a/Osmo/Properties/Resources.Designer.cs b/Osmo/Properties/Resources.Designer.cs index d85a60f..b64fd73 100644 --- a/Osmo/Properties/Resources.Designer.cs +++ b/Osmo/Properties/Resources.Designer.cs @@ -60,6 +60,27 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to === Console stuff + /// clear Clears the console + /// testMessages Writes all types of messages into the console + /// + ///=== Log management === + /// wipeLog Delete the log.txt and generate a new one + /// wipeCrashLogs Delete all crash logs + /// wipeLogFolder Delete all logs inside the "Logs" folder + /// openLog Open the log.txt in your default editor + /// + ///=== Configuration files + /// printConfig Print the configuration for the current profile into the console + /// printConfig [ProfileName] Print the configurati [rest of string was truncated]";. + /// + internal static string ConsoleCommands { + get { + return ResourceManager.GetString("ConsoleCommands", resourceCulture); + } + } + /// /// Looks up a localized string similar to [General] ///Name: [NAME] diff --git a/Osmo/Properties/Resources.resx b/Osmo/Properties/Resources.resx index 9fb595f..a31b724 100644 --- a/Osmo/Properties/Resources.resx +++ b/Osmo/Properties/Resources.resx @@ -172,4 +172,7 @@ ..\Resources\mode_taiko.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\ConsoleCommands.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + \ No newline at end of file diff --git a/Osmo/Resources/ConsoleCommands.txt b/Osmo/Resources/ConsoleCommands.txt new file mode 100644 index 0000000..6e29f8a --- /dev/null +++ b/Osmo/Resources/ConsoleCommands.txt @@ -0,0 +1,16 @@ +=== Console stuff + clear Clears the console + testMessages Writes all types of messages into the console + +=== Log management === + wipeLog Delete the log.txt and generate a new one + wipeCrashLogs Delete all crash logs + wipeLogFolder Delete all logs inside the "Logs" folder + openLog Open the log.txt in your default editor + +=== Configuration files + listProfiles Return a list of all profile names + printConfig Print the configuration for the current profile into the console + printConfig [ProfileName] Print the configuration for a specific profile into the console + openConfig Open the configuration for the current profile in your default editor + openConfig [ProfileName] Open the configuration for a specific profile in your default editor \ No newline at end of file diff --git a/Osmo/UI/DebugConsole.xaml b/Osmo/UI/DebugConsole.xaml index 716052d..6a8d383 100644 --- a/Osmo/UI/DebugConsole.xaml +++ b/Osmo/UI/DebugConsole.xaml @@ -11,19 +11,28 @@ + - + @@ -33,5 +42,12 @@ + + + + diff --git a/Osmo/UI/DebugConsole.xaml.cs b/Osmo/UI/DebugConsole.xaml.cs index af16017..53cb819 100644 --- a/Osmo/UI/DebugConsole.xaml.cs +++ b/Osmo/UI/DebugConsole.xaml.cs @@ -1,8 +1,12 @@ using Osmo.Core; using Osmo.Core.Logging; +using System; +using System.Diagnostics; +using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; +using System.Windows.Input; using System.Windows.Media; namespace Osmo.UI @@ -13,7 +17,9 @@ namespace Osmo.UI public partial class DebugConsole : Border, IConsole { private static DebugConsole _instance; - private bool verboseLogging; + private ConsoleHistory history = new ConsoleHistory(20); + + private string commandList; public static DebugConsole Instance { @@ -25,13 +31,27 @@ public static DebugConsole Instance public bool VerboseLogging { - get => verboseLogging; + get => false; + } + + public bool IsWindowMode + { + get { return (bool)GetValue(IsWindowModeProperty); } + set { SetValue(IsWindowModeProperty, value); } } + // Using a DependencyProperty as the backing store for IsWindowMode. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IsWindowModeProperty = + DependencyProperty.Register("IsWindowMode", typeof(bool), typeof(DebugConsole), new PropertyMetadata(false)); + public DebugConsole() { InitializeComponent(); - _instance = this; + if (_instance == null) + { + _instance = this; + } + commandList = Properties.Resources.ConsoleCommands; } public void ShowConsole() @@ -74,10 +94,10 @@ public void Log(string msg, LogType logType) break; } - SetText(msg, brush); + SetText(msg, logType, brush); } - void SetText(string msg, SolidColorBrush brush) + void SetText(string msg, LogType logType, SolidColorBrush brush) { Dispatcher.Invoke(() => { @@ -85,6 +105,8 @@ void SetText(string msg, SolidColorBrush brush) { Text = msg }; + + tr.ApplyPropertyValue(TextElement.TagProperty, logType.ToString()); tr.ApplyPropertyValue(TextElement.ForegroundProperty, brush); }); } @@ -96,7 +118,196 @@ private void rtb_sessionLog_TextChanged(object sender, TextChangedEventArgs e) private void CloseConsole_Click(object sender, RoutedEventArgs e) { - Visibility = Visibility.Collapsed; + if (!IsWindowMode) + { + Visibility = Visibility.Collapsed; + } + else if (Parent is Window window) + { + Instance.Visibility = Visibility.Collapsed; + window.Close(); + } + } + + private void TextBox_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Enter) + { + GetCommand(txt_cmd.Text); + txt_cmd.Text = ""; + } + else if (e.Key == Key.Up) + { + txt_cmd.Text = history.Peek(true); + } + else if (e.Key == Key.Down) + { + txt_cmd.Text = history.Peek(false); + } + } + + private void GetCommand(string cmd) + { + Log("> " + cmd + "\n", LogType.NULL); + + SolidColorBrush brush = FixedValues.DEFAULT_BRUSH; + string output = null; + string[] args = cmd.ToLower().Split(' '); + switch (args[0]) + { + case "help": + case "?": + output = commandList; + break; + + case "clear": + rtb_sessionLog.Document.Blocks.Clear(); + break; + + case "wipelog": + File.Delete("Logs\\log.txt"); + Logger.Instance.WriteLog("Log wiped!", LogType.CONSOLE); + break; + + case "wipecrashlog": + foreach (FileInfo fi in new DirectoryInfo("Logs").EnumerateFiles("*osmo_crashlog.txt")) + { + fi.Delete(); + } + Logger.Instance.WriteLog("Crash logs deleted!", LogType.CONSOLE); + break; + + case "wipelogfolder": + Directory.Delete("Logs", true); + Directory.CreateDirectory("Logs"); + Logger.Instance.WriteLog("Log folder wiped!", LogType.CONSOLE); + break; + + case "openlog": + Process.Start("Logs\\log.txt"); + break; + + case "listprofiles": + Log("Profiles:\n", LogType.CONSOLE); + foreach (var profile in App.ProfileManager.Profiles) + { + if (profile.ProfileName == null) + { + Log("\tDefault", LogType.CONSOLE); + } + else + { + Log("\t" + profile.ProfileName, LogType.CONSOLE); + } + + if (profile == App.ProfileManager.Profile) + { + Log(" (active)\n", LogType.CONSOLE); + } + else + { + Log("\n", LogType.CONSOLE); + } + } + break; + + case "printconfig": + string configPath = GetConfigPath(args); + + if (configPath != null) + { + PrintFile(configPath); + } + else + { + MakeError(out brush, out output); + output = "Invalid configuration name!\n"; + } + break; + + case "openconfig": + string configPathOpen = GetConfigPath(args); + + if (configPathOpen != null) + { + Process.Start(configPathOpen); + } + else + { + MakeError(out brush, out output); + output = "Invalid configuration name!\n"; + } + break; + + default: + MakeError(out brush, out output); + break; + } + + history.Push(cmd); + + if (output != null && brush != null) + SetText(output, LogType.NULL, brush); + } + + private void MakeError(out SolidColorBrush brush, out string output) + { + brush = FixedValues.DEFAULT_BRUSH; + output = "Unknown command!\n"; + } + + private string GetConfigPath(string[] args) + { + if (args.Length > 1) + { + var targetConfig = App.ProfileManager.GetProfileByName(args[1]); + if (targetConfig != null) + { + return targetConfig.FilePath; + } + else + { + return null; + } + } + else + { + return App.ProfileManager.Profile.FilePath; + } + } + + private void PrintFile(string path) + { + if (File.Exists(path)) + { + Log("---------------------------------------\n", LogType.CONSOLE); + string[] content = File.ReadAllLines(path); + + string msg = string.Format("{0} content:", new FileInfo(path).Name); + for (int i = 0; i < content.Length; i++) + { + if (!string.IsNullOrWhiteSpace(content[i])) + msg += "\n " + content[i]; + } + + Log(msg + "\n---------------------------------------\n\n", LogType.CONSOLE); + } + else + { + Log("File does not exist!\n", LogType.CONSOLE); + } + } + + private void Popout_Click(object sender, RoutedEventArgs e) + { + if (!IsWindowMode) + { + new ConsoleWindow().Show(); + } + else if (Parent is Window window) + { + window.Close(); + } } } }