From dec9a4413664a362efd2e81452bf19ce37b87931 Mon Sep 17 00:00:00 2001 From: MichaelTheShifter Date: Sat, 23 Jul 2016 15:49:49 -0400 Subject: I dun derped. --- source/ShiftUI Designer/Program.cs | 1445 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1445 insertions(+) create mode 100644 source/ShiftUI Designer/Program.cs (limited to 'source/ShiftUI Designer/Program.cs') diff --git a/source/ShiftUI Designer/Program.cs b/source/ShiftUI Designer/Program.cs new file mode 100644 index 0000000..7e4be98 --- /dev/null +++ b/source/ShiftUI Designer/Program.cs @@ -0,0 +1,1445 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftUI; +using System.Drawing; +using System.Diagnostics; +using System.Reflection; + +namespace ShiftUI_Designer +{ + public class MyAwesomeSkin : ShiftUI.ShiftOS.Skin + { + public MyAwesomeSkin() + { + base.ButtonBackColor_Pressed = Color.Red; + } + } + + class Program + { + static void Main(string[] args) + { + Application.LoadSkin(new MyAwesomeSkin()); + Application.EnableVisualStyles(); + Application.Run(new FormSelectionForm()); + Console.WriteLine("This executed after Run."); + } + } + + public static class Helpers + { + public static void Debug(this Form host, string message) + { + Console.WriteLine("<{0}> [ShiftUI/{1}] {2}", DateTime.Now.ToString(), host.Text, message); + } + } + + public class MainEditorForm : Form + { + private Panel resize_se = null; + private Panel resize_e = null; + private Panel resize_s = null; + private Panel resize_sw = null; + private Panel resize_w = null; + + public void LoadFormFromClass(Form form) + { + var t = form.GetType(); + var init_method = t.GetMethod("InitializeComponent"); + if (init_method != null) + { + init_method.Invoke(form, null); + } + TopLevels.Add(form); + current_form = form; + PopulateTree(); + DrawForm(); + this.Show(); + } + + public enum ResizeLocation + { + South = 0, + SouthEast = 1, + East = 2, + NorthEast = 3, + North = 4, + NorthWest = 5, + West = 6, + SouthWest = 7 + } + + public void Select(Widget widget) + { + if (widget != null) + { + if(widget is Form && current_form != widget as Form) + { + current_form = widget as Form; + DrawForm(); + Select(current_form); + } + if (widget != current_form.Body) + { + properties.SelectedObject = widget; + resizing_widget = widget; + resize_w?.Parent?.Widgets.Remove(resize_w); + resize_w = null; + resize_sw?.Parent?.Widgets.Remove(resize_sw); + resize_sw = null; + resize_se?.Parent?.Widgets.Remove(resize_se); + resize_se = null; + resize_s?.Parent?.Widgets.Remove(resize_s); + resize_s = null; + resize_e?.Parent?.Widgets.Remove(resize_e); + resize_e = null; + SetupResizeBorder(widget); + } + else + { + Select(current_form); + } + } + else + { + resize_w?.Hide(); + resize_sw?.Hide(); + resize_s?.Hide(); + resize_se?.Hide(); + resize_e?.Hide(); + + } + } + + public void SetupResizeBorder(Widget widget) + { + if (!(widget is Form)) + { + SetupMoveHandle(ref resize_sw, ResizeLocation.NorthWest); + } + SetupResizeHandle(ref resize_se, ResizeLocation.SouthEast); + SetupResizeHandle(ref resize_e, ResizeLocation.East); + SetupResizeHandle(ref resize_s, ResizeLocation.South); + + } + + + Point last_mouse_location = Point.Empty; + bool dragging = false; + private Widget resizing_widget = null; + + public void SetupMoveHandle(ref Panel handle, ResizeLocation loc) + { + bool updown = false; + bool leftright = false; + properties.SelectedObject = resizing_widget; + if (handle == null) + { + handle = new Panel(); + body.Widgets.Add(handle); + handle.BackColor = Color.Black; + handle.Size = new Size(16, 16); + handle.MouseDown += (o, a) => + { + if (a.Button == MouseButtons.Left) + { + last_mouse_location = a.Location; + dragging = true; + } + }; + handle.MouseUp += (o, a) => + { + dragging = false; + }; + handle.MouseMove += (o, a) => + { + if (dragging == true) + { + var mouse_loc = a.Location; + int y_distance = mouse_loc.Y - last_mouse_location.Y; + int x_distance = mouse_loc.X - last_mouse_location.X; + if (updown == true) + { + resizing_widget.Top += y_distance; + form_preview.Refresh(); + } + if (leftright == true) + { + resizing_widget.Left += x_distance; + form_preview.Refresh(); + } + SetupResizeBorder(resizing_widget); + } + }; + } + bool ex = false; + var wloc = Point.Empty; + try + { + wloc = resizing_widget.Parent.PointToScreen(resizing_widget.Location); + } + catch + { + ex = true; + wloc = body.PointToScreen(resizing_widget.Location); //Must be a top-level widget. + } + wloc = body.PointToClient(wloc); + switch (loc) + { + case ResizeLocation.NorthWest: + handle.Left = wloc.X - handle.Width; + handle.Top = wloc.Y - handle.Height; + updown = true; + leftright = true; + break; + } + + handle.BringToFront(); + handle.Show(); + handle.Refresh(); + body.Refresh(); + } + + + public void SetupResizeHandle(ref Panel handle, ResizeLocation loc) + { + bool updown = false; + bool leftright = false; + properties.SelectedObject = resizing_widget; + if (handle == null) + { + handle = new Panel(); + body.Widgets.Add(handle); + handle.BackColor = Color.Black; + handle.Size = new Size(16, 16); + handle.MouseDown += (o, a) => + { + if (a.Button == MouseButtons.Left) + { + last_mouse_location = a.Location; + dragging = true; + } + }; + handle.MouseUp += (o, a) => + { + dragging = false; + }; + handle.MouseMove += (o, a) => + { + if (dragging == true) + { + var mouse_loc = a.Location; + int y_distance = mouse_loc.Y - last_mouse_location.Y; + int x_distance = mouse_loc.X - last_mouse_location.X; + if (updown == true) + { + resizing_widget.Height += y_distance; + form_preview.Refresh(); + } + if (leftright == true) + { + resizing_widget.Width += x_distance; + form_preview.Refresh(); + } + SetupResizeBorder(resizing_widget); + } + }; + } + bool ex = false; + var wloc = Point.Empty; + try + { + wloc = resizing_widget.Parent.PointToScreen(resizing_widget.Location); + } + catch + { + ex = true; + wloc = body.PointToScreen(resizing_widget.Location); //Must be a top-level widget. + } + wloc = body.PointToClient(wloc); + switch ((int)loc) + { + case 0: + handle.Left = wloc.X + ((resizing_widget.Width - handle.Width) / 2); + handle.Top = wloc.Y + resizing_widget.Height; + updown = true; + break; + case 1: + handle.Left = wloc.X + resizing_widget.Width + 5; + handle.Top = wloc.Y + resizing_widget.Height + 5; + updown = true; + leftright = true; + break; + case 2: + handle.Left = wloc.X + resizing_widget.Width; + handle.Top = wloc.Y + ((resizing_widget.Height - handle.Height) / 2); + leftright = true; + break; + case 3: + handle.Left = wloc.X + resizing_widget.Width; + handle.Top = wloc.Y + (resizing_widget.Top - handle.Top); + leftright = true; + updown = true; + break; + } + + handle.BringToFront(); + handle.Show(); + handle.Refresh(); + body.Refresh(); + } + + private Panel form_preview; + private Form current_form; + + public void DrawForm() + { + if (form_preview == null) + { + form_preview = new Panel(); + body.Widgets.Add(form_preview); + } + + if (current_form != null) + { + current_form.FormClosing += (o, a) => + { + a.Cancel = true; + }; + current_form.SizeChanged += (o, a) => + { + form_preview.Size = current_form.Size; + }; + current_form.Body.WidgetAdded += (o, a) => + { + SetupWidget(a.Widget); + }; + form_preview.Widgets.Clear(); + form_preview.Location = new Point(5, 5); + form_preview.Size = current_form.Size; + Widget[] widgets = new Widget[current_form.Widgets.Count]; + current_form.Widgets.CopyTo(widgets, 0); + Widget[] borderwidgets = new Widget[current_form.BorderWidgets.Length]; + current_form.BorderWidgets.CopyTo(borderwidgets, 0); + foreach (var widget in borderwidgets) + { + form_preview.Widgets.Add(widget); + widget.Show(); + SetupWidget(widget); + + } + + foreach (var widget in widgets) + { + if (!borderwidgets.Contains(widget)) + { + form_preview.Widgets.Add(widget); + widget.Show(); + if (widget == current_form.Body) + widget.BringToFront(); + SetupWidget(widget); + } + } + form_preview.Show(); + } + } + + public void SetupWidget(Widget widget) + { + if (string.IsNullOrEmpty(widget.Name)) + { + widget.MouseDown += (o, a) => + { + Select(current_form); + current_parent = current_form; + }; + } + else + { + widget.MouseDown += (o, a) => + { + Select(widget); + current_parent = widget; + }; + } + //give the widget the Container context menu + widget.ContextMenuStrip = container_menu; + + foreach(Widget w in widget.Widgets) + { + SetupWidget(w); + } + + } + + public List
TopLevels = new List(); + private Widget current_parent = null; + private ContextMenuStrip widget_modification_menu = null; + + public void PopulateTopLevelNode(TreeNode node, Widget widget) + { + document_outline.Nodes.Add(node); + node.ContextMenuStrip = widget_modification_menu; + if (widget.Widgets != null && widget.Widgets.Count > 0) + { + foreach(Widget w in widget.Widgets) + { + PopulateNode(node, w); + } + } + } + + public void PopulateNode(TreeNode parent, Widget widget) + { + var t = new TreeNode(); + if (!string.IsNullOrEmpty(widget.Name)) + { + t.Text = widget.Name + ": " + widget.GetType().Name; + t.Tag = widget; + t.ContextMenuStrip = widget_modification_menu; + parent.Nodes.Add(t); + if (widget.Widgets.Count > 0) + { + foreach (Widget w in widget.Widgets) + { + PopulateNode(t, w); + } + } + t.Expand(); + } + else + { + } + } + + public void PopulateTree() + { + document_outline.Nodes.Clear(); + foreach (var form in TopLevels) + { + var t = new TreeNode(); + t.Text = form.Name + ": " + form.GetType().Name; + t.Tag = form; + PopulateTopLevelNode(t, current_form.Body); + t.Expand(); + } + } + + public MainEditorForm() + { + Text = "ShiftUI"; + this.Debug("Starting designer..."); + this.MaximumSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - 40); + this.SizeChanged += (o, a) => + { + if (this.WindowState == FormWindowState.Maximized) + this.Location = new Point(0, 0); + }; + this.Size = new Size(1280, 720); + this.Load += (o, a) => + { + ResetSkin(); + }; + + //create menu + menu = new MenuStrip(); + this.Widgets.Add(menu); + menu.Show(); + + //top-levels + file = new ToolStripMenuItem(); + edit = new ToolStripMenuItem(); + about = new ToolStripMenuItem(); + file.Text = "File"; + edit.Text = "Edit"; + about.Text = "About"; + menu.Items.Add(file); + menu.Items.Add(edit); + menu.Items.Add(about); + + //about + a_about_shiftui = new ToolStripMenuItem(); + a_about_shiftui_designer = new ToolStripMenuItem(); + a_shiftos = new ToolStripMenuItem(); + a_about_shiftui.Text = "About ShiftUI"; + a_about_shiftui_designer.Text = "About ShiftUI Designer"; + a_shiftos.Text = "ShiftOS"; + about.DropDownItems.Add(a_about_shiftui); + about.DropDownItems.Add(a_about_shiftui_designer); + about.DropDownItems.Add(a_shiftos); + a_about_shiftui.Click += (o, a) => + { + Process.Start("http://playshiftos.ml/wiki/index/shiftui"); + }; + a_about_shiftui_designer.Click += (o, a) => + { + Process.Start("http://playshiftos.ml/wiki/index/shiftui-designer"); + }; + a_shiftos.Click += (o, a) => + { + Process.Start("http://playshiftos.ml"); + }; + + + widget_modification_menu = new ContextMenuStrip(); + var rename_widget = new ToolStripMenuItem(); + rename_widget.Text = "Rename"; + widget_modification_menu.Items.Add(rename_widget); + rename_widget.Click += (o, a) => + { + if (document_outline.SelectedNode != null) + { + var renamer = new WidgetRenameForm(document_outline.SelectedNode.Tag as Widget); + renamer.ShowDialog(); + PopulateTree(); + } + }; + + e_newform = new ToolStripMenuItem(); + e_newform.Text = "Add new form"; + edit.DropDownItems.Add(e_newform); + e_newform.Click += (o, a) => + { + var nf = new Form(); + nf.Name = $"Form{TopLevels.Count + 1}"; + TopLevels.Add(nf); + current_form = nf; + PopulateTree(); + DrawForm(); + }; + + var delete_widget = new ToolStripMenuItem(); + delete_widget.Text = "Delete"; + widget_modification_menu.Items.Add(delete_widget); + delete_widget.Click += (o, a) => + { + if (document_outline.SelectedNode != null) + { + var w = document_outline.SelectedNode.Tag as Widget; + if (properties.SelectedObject == w) + Select(null); //deselect the widget IF it's the selected widget. + if (w.Parent != null) + w.Parent.Widgets.Remove(w); + + if (w is Form) + { + if (TopLevels.Contains(w as Form)) + { + bool should_redraw = current_form == w as Form; + Select(null); //have to deselect whatever is selected in case it's this form or + //it's a part of it's family (child, grandchild, etc) + TopLevels.Remove(w as Form); + if (TopLevels.Count > 0 && should_redraw == true) + { + current_form = TopLevels[0]; + DrawForm(); + } + else + { + current_form = null; + form_preview.Hide(); + } + } + } + + w.Hide(); + w.Dispose(); + + PopulateTree(); + + } + + }; + + + ///Main UI + + //Split panel + var splitter_parent = new Panel(); + this.Widgets.Add(splitter_parent); + splitter_parent.Dock = DockStyle.Fill; + splitter_parent.Show(); + //split panel - left panel + var splitter_left = new Panel(); + splitter_left.Dock = DockStyle.Left; + splitter_left.Width = splitter_parent.Width / 3; + splitter_parent.Widgets.Add(splitter_left); + splitter_left.Show(); + + //left panel - property grid + properties = new PropertyGrid(); + properties.Dock = DockStyle.Bottom; + properties.Height = splitter_left.Height / 2; + splitter_left.Widgets.Add(properties); + properties.Show(); + + //left panel - document tree + document_outline = new TreeView(); + document_outline.Dock = DockStyle.Fill; + splitter_left.Widgets.Add(document_outline); + document_outline.Show(); + + //splitter panel - body + body = new Panel(); + body.Dock = DockStyle.Fill; + splitter_parent.Widgets.Add(body); + body.Show(); + splitter_left.SendToBack(); + + //add a new form to the toplevel + var f = new Form(); + f.Name = "Form1"; + f.Text = "Form1"; + TopLevels.Add(f); + + //populate tree + current_form = TopLevels[0]; + PopulateTree(); + + menu.SendToBack(); + + //Create the container context menu + container_menu = new ContextMenuStrip(); + c_add_widget = new ToolStripMenuItem(); + c_add_widget.Text = "Add widget"; + container_menu.Items.Add(c_add_widget); + c_add_widget.Click += (o, a) => + { + var wselector = new WidgetSelectorForm(current_parent); + wselector.ShowDialog(); + PopulateTree(); + }; + + //draw the first top-level + DrawForm(); + Select(current_form); + document_outline.Click += (o, a) => + { + if(document_outline.SelectedNode != null) + { + Select(document_outline.SelectedNode.Tag as Widget); + } + }; + + f_export = new ToolStripMenuItem(); + f_export.Text = "Export as..."; + file.DropDownItems.Add(f_export); + + f_export_cs = new ToolStripMenuItem(); + f_export_cs.Text = "C# Code File"; + f_export.DropDownItems.Add(f_export_cs); + f_export_cs.Click += (o, a) => + { + MessageBox.Show("This is an experimental feature of the ShiftUI designer. Although we can handle most of the heavy lifting and you won't have to type lots of UI code, we may mess up a bit in some areas, and in that case, you may experience errors in the generated code.", "Warning: Experimental"); + ExportCS(TopLevels); + }; + } + + public string GenerateWidgetCSharp(Widget parent, Widget w) + { + string csharp = ""; + var wtype = w.GetType(); + string wName = w.Name; + if (w is Form && TopLevels.Contains(w as Form)) + wName = "this"; + string parentName = ""; + if (parent != null) + parentName = parent.Name; + if (parent is Form && TopLevels.Contains(parent as Form)) + parentName = "this"; + + + Type[] valid_types = { typeof(string), typeof(int), typeof(Color), typeof(bool), typeof(Size), typeof(Point), typeof(Font) }; + + //Instantiate widget. + if(wName != "this") + csharp += $"\t\t\t{wName} = new {wtype.Name}();\r\n"; + + //get all public properties of widget + var propertyinf = wtype.GetProperties(BindingFlags.Public | BindingFlags.Instance); + foreach (var p in propertyinf) + { + if (!p.CanRead || !p.CanWrite) + continue; + + var get = p.GetGetMethod(); + var set = p.GetSetMethod(); + + if (get == null) + continue; + + if (set == null) + continue; + + if (valid_types.Contains(p.PropertyType) || p.PropertyType.IsEnum) + { + if (p.Name != "TransparencyKey") + { + csharp += $"\t\t\t{wName}.{p.Name} = "; + + if (p.PropertyType == typeof(string)) + csharp += $"\"{p.GetValue(w)}\""; + else if (p.PropertyType == typeof(Cursor)) + csharp += $"{p.GetValue(w).ToString().Replace("[", "").Replace("]", "")}"; + else if (p.PropertyType.IsEnum) + { + try + { + int enum_val = int.Parse(p.GetValue(w).ToString()); + csharp += $"({p.PropertyType.Name}){enum_val}"; + } + catch + { + csharp += $"{p.PropertyType.Name}.{p.GetValue(w).ToString().Replace(", ", $" | {p.PropertyType.Name}.")}"; + } + } + else if (p.PropertyType == typeof(bool)) + csharp += $"{p.GetValue(w).ToString().ToLower()}"; //Booleans are always lowercase in C#. + else if (p.PropertyType == typeof(int)) + csharp += $"{p.GetValue(w)}"; + else if (p.PropertyType == typeof(Point)) + { + var point = (Point)p.GetValue(w); + csharp += $"new Point({point.X}, {point.Y})"; + } + else if (p.PropertyType == typeof(Size)) + { + var size = (Size)p.GetValue(w); + csharp += $"new Size({size.Width}, {size.Height})"; + } + else if (p.PropertyType == typeof(Color)) + { + //Bug: Form.TransparencyKey seems to always be set to black if the user doesn't explicitly + //set it. This causes the close, minimize and maximize buttons, as well as text to appear transparent. + // + //Workaround: Disallow TransparencyKey. + var color = (Color)p.GetValue(w); + csharp += $"Color.FromArgb({color.R}, {color.G}, {color.B})"; + } + else if (p.PropertyType == typeof(Font)) + { + var font = (Font)p.GetValue(w); + csharp += $"new Font(\"{font.FontFamily.Name}\", (float){font.Size}, (FontStyle){(int)font.Style})"; + } + csharp += ";\r\n"; + } + } + } + if (wName == "this") + { + csharp += "\r\n"; + } + else + { + csharp += $"\t\t\t{parentName}.Widgets.Add({wName});\r\n"; + csharp += $"\t\t\t{wName}.Show();\r\n"; + } + + foreach(Widget wid in w.Widgets) + { + csharp += GenerateWidgetCSharp(w, wid); + } + + return csharp; + } + + public string GenerateWidgetMembersCSharp(Widget widget) + { + var t = widget.GetType(); + string csharp = ""; + csharp += "public " + t.Name + " " + widget.Name + " = null;"; + foreach(Widget w in widget.Widgets) + { + csharp += GenerateWidgetMembersCSharp(w); + } + return csharp; + } + + public void ExportCS(List forms) + { + string csharp = ""; + csharp += @"/* + * This piece of code was automatically + * generated by the ShiftUI designer. + * + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Drawing; +using ShiftUI; + +namespace ShiftUI_DesignerGenerated { +"; + foreach (var form in forms) + { + csharp += $@" public class {form.Name} : Form" + @" { + public " + form.Name + @"() { +"; + + csharp += GenerateWidgetCSharp(null, form); + + //Widget property setup. + foreach (Widget widget in form.Body.Widgets) + { + csharp += GenerateWidgetCSharp(form as Widget, widget); + } + + csharp += @" + } +"; + + foreach (Widget widget in form.Body.Widgets) + { + csharp += GenerateWidgetMembersCSharp(widget); + } + + csharp += @" + }"; + } + csharp += @" +}"; + var f = new Form(); + var rtb = new RichTextBox(); + f.Text = "C# Output"; + rtb.Dock = DockStyle.Fill; + f.Show(); + f.Widgets.Add(rtb); + rtb.Show(); + rtb.Text = csharp; + + } + + private Panel body = null; + private PropertyGrid properties = null; + private MenuStrip menu = null; + private TreeView document_outline = null; + private ContextMenuStrip container_menu = null; + + private ToolStripMenuItem c_add_widget = null; + + private ToolStripMenuItem file = null; + private ToolStripMenuItem f_new = null; + private ToolStripMenuItem f_open = null; + private ToolStripMenuItem f_save = null; + private ToolStripMenuItem f_export = null; + + private ToolStripMenuItem f_export_vb = null; + private ToolStripMenuItem f_export_cs = null; + private ToolStripMenuItem f_export_lua = null; + + private ToolStripMenuItem f_exit = null; + + private ToolStripMenuItem edit = null; + private ToolStripMenuItem e_newform = null; + + private ToolStripMenuItem about = null; + private ToolStripMenuItem a_about_shiftui = null; + private ToolStripMenuItem a_about_shiftui_designer = null; + private ToolStripMenuItem a_shiftos = null; + + + } + + public class WidgetSelectorForm : Form + { + public WidgetSelectorForm(Widget parent) + { + this.Text = "Add Widget"; + Size = new Size(400, 400); + var cbox = new ComboBox(); + foreach(var t in Widget.GetAllToolboxWidgets()) + { + cbox.Items.Add(t.Name); + } + this.Widgets.Add(cbox); + cbox.Location = new Point(10, 50); + cbox.Width = this.Width - (cbox.Left * 2); + var cbox_label = new Label(); + cbox_label.Text = "Select widget type"; + cbox_label.Top = cbox.Top - cbox_label.Height; + cbox_label.Left = 10; + this.Widgets.Add(cbox_label); + var widget_name = new TextBox(); + widget_name.Location = new Point(10, 100); + widget_name.Width = this.Width - (widget_name.Left * 2); + this.Widgets.Add(widget_name); + widget_name.Show(); + var widget_name_label = new Label(); + widget_name_label.Text = "Widget name"; + widget_name_label.Left = 10; + widget_name_label.Top = widget_name.Top - widget_name_label.Height; + this.Widgets.Add(widget_name_label); + widget_name_label.Show(); + cbox.Show(); + cbox_label.Show(); + DialogResult = DialogResult.Cancel; + Button confirm = new Button(); + confirm.AutoSize = true; + confirm.AutoSizeMode = AutoSizeMode.GrowAndShrink; + confirm.Text = "Add"; + confirm.Click += (o, a) => + { + if (string.IsNullOrEmpty(cbox.Text)) + { + MessageBox.Show("Error: Widget type not present. You must select a valid widget type.", "Add Widget"); return; + } + + if(string.IsNullOrEmpty(widget_name.Text)) + { + MessageBox.Show("Error: Widget name cannot be empty as it is required for the variable name when generating code.", "Add Widget"); return; + } + + //get the type of the selected widget + Type type = null; + foreach (var t in Widget.GetAllToolboxWidgets()) + { + if (t.Name == cbox.SelectedItem.ToString()) + { + type = t; + } + } + if(type == null) + { + MessageBox.Show("Error: Invalid widget type. The type could not be found.", "Add Widget"); return; + } + try + { + Widget w = Activator.CreateInstance(type) as Widget; + w.Name = widget_name.Text; + parent.Widgets.Add(w); + w.Show(); + } + catch(Exception ex) + { + MessageBox.Show($"Error: Couldn't create widget instance from type! {ex.Message}", "Add Widget"); return; + } + + this.DialogResult = DialogResult.OK; + this.Close(); + }; + var bottom_panel = new FlowLayoutPanel(); + bottom_panel.Dock = DockStyle.Bottom; + bottom_panel.Height = 25; + this.Widgets.Add(bottom_panel); + bottom_panel.Show(); + bottom_panel.BackColor = Application.CurrentSkin.MessageBox_BottomPanel; + bottom_panel.Widgets.Add(confirm); + confirm.Show(); + } + } + + public class WidgetRenameForm : Form + { + public WidgetRenameForm(Widget widget) + { + this.AllowTransparency = false; + this.AutoScale = true; + this.AutoScaleBaseSize = new Size(5, 13); + this.AutoScroll = false; + this.AutoSize = false; + this.AutoSizeMode = AutoSizeMode.GrowOnly; + this.AutoValidate = AutoValidate.Inherit; + this.BackColor = Color.FromArgb(240, 240, 240); + this.ClientSize = new Size(300, 132); + this.WidgetBox = true; + this.DesktopLocation = new Point(0, 0); + this.DialogResult = DialogResult.None; + this.FormBorderStyle = FormBorderStyle.FixedSingle; + this.HelpButton = false; + this.IsMdiContainer = false; + this.KeyPreview = false; + this.MaximizeBox = true; + this.MaximumSize = new Size(0, 0); + this.MinimizeBox = true; + this.MinimumSize = new Size(0, 0); + this.RightToLeftLayout = false; + this.ShowIcon = true; + this.ShowInTaskbar = true; + this.Size = new Size(300, 132); + this.SizeGripStyle = SizeGripStyle.Auto; + this.StartPosition = FormStartPosition.WindowsDefaultLocation; + this.TabIndex = 0; + this.TabStop = true; + this.TopLevel = true; + this.TopMost = false; + this.WindowState = FormWindowState.Normal; + this.Text = "Rename widget"; + this.Location = new Point(0, 0); + this.AutoScaleMode = AutoScaleMode.Inherit; + this.AutoScrollMargin = new Size(0, 0); + this.AutoScrollMinSize = new Size(0, 0); + this.AutoScrollPosition = new Point(0, 0); + this.Alignment = (ContentAlignment)0; + this.AccessibleDefaultActionDescription = ""; + this.AccessibleDescription = ""; + this.AccessibleName = ""; + this.AccessibleRole = AccessibleRole.Default; + this.AllowDrop = false; + this.Anchor = AnchorStyles.Top | AnchorStyles.Left; + this.AutoScrollOffset = new Point(0, 0); + this.BackgroundImageLayout = ImageLayout.Tile; + this.Capture = false; + this.CausesValidation = true; + this.Dock = DockStyle.None; + this.Enabled = true; + this.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + this.ForeColor = Color.FromArgb(0, 0, 0); + this.Height = 132; + this.ImeMode = ImeMode.NoControl; + this.IsAccessible = false; + this.Left = 0; + this.Name = "Form1"; + this.RightToLeft = RightToLeft.No; + this.Top = 0; + this.UseWaitCursor = false; + this.Visible = false; + this.Width = 300; + + btnok = new Button(); + btnok.AutoSizeMode = AutoSizeMode.GrowOnly; + btnok.DialogResult = DialogResult.None; + btnok.AutoEllipsis = false; + btnok.AutoSize = false; + btnok.BackColor = Color.FromArgb(255, 255, 0); + btnok.FlatStyle = FlatStyle.Standard; + btnok.ImageAlign = ContentAlignment.MiddleCenter; + btnok.ImageIndex = -1; + btnok.ImageKey = ""; + btnok.ImeMode = ImeMode.Disable; + btnok.Text = "Rename"; + btnok.TextAlign = ContentAlignment.MiddleCenter; + btnok.TextImageRelation = TextImageRelation.Overlay; + btnok.UseCompatibleTextRendering = true; + btnok.UseMnemonic = true; + btnok.UseVisualStyleBackColor = true; + btnok.Alignment = (ContentAlignment)0; + btnok.AccessibleDefaultActionDescription = ""; + btnok.AccessibleDescription = ""; + btnok.AccessibleName = ""; + btnok.AccessibleRole = AccessibleRole.Default; + btnok.AllowDrop = false; + btnok.Anchor = AnchorStyles.Top | AnchorStyles.Left; + btnok.AutoScrollOffset = new Point(0, 0); + btnok.MaximumSize = new Size(0, 0); + btnok.MinimumSize = new Size(0, 0); + btnok.BackgroundImageLayout = ImageLayout.Tile; + btnok.Capture = false; + btnok.CausesValidation = true; + btnok.ClientSize = new Size(75, 23); + btnok.Dock = DockStyle.None; + btnok.Enabled = true; + btnok.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + btnok.ForeColor = Color.FromArgb(0, 0, 0); + btnok.Height = 23; + btnok.IsAccessible = false; + btnok.Left = 210; + btnok.Location = new Point(210, 66); + btnok.Name = "btnok"; + btnok.RightToLeft = RightToLeft.No; + btnok.Size = new Size(75, 23); + btnok.TabIndex = 0; + btnok.TabStop = true; + btnok.Top = 66; + btnok.UseWaitCursor = false; + btnok.Visible = true; + btnok.Width = 75; + this.Widgets.Add(btnok); + btnok.Show(); + btnok.Click += (o, a) => + { + if(string.IsNullOrEmpty(txtnewname.Text)) + { + MessageBox.Show("Error: The new name must not be empty!", "Rename Widget"); return; + } + + widget.Name = txtnewname.Text.Replace(" ", ""); + this.Close(); + }; + + txtnewname = new TextBox(); + txtnewname.AutoCompleteMode = AutoCompleteMode.None; + txtnewname.AutoCompleteSource = AutoCompleteSource.None; + txtnewname.UseSystemPasswordChar = false; + txtnewname.AcceptsReturn = false; + txtnewname.CharacterCasing = CharacterCasing.Normal; + txtnewname.ScrollBars = ScrollBars.None; + txtnewname.Text = widget.Name; + txtnewname.TextAlign = HorizontalAlignment.Left; + txtnewname.Multiline = false; + txtnewname.AcceptsTab = false; + txtnewname.AutoSize = true; + txtnewname.BackColor = Color.FromArgb(240, 240, 240); + txtnewname.BorderStyle = BorderStyle.Fixed3D; + txtnewname.ForeColor = Color.FromArgb(0, 0, 0); + txtnewname.HideSelection = true; + txtnewname.MaxLength = 32767; + txtnewname.Modified = true; + txtnewname.ReadOnly = false; + txtnewname.SelectedText = ""; + txtnewname.SelectionLength = 0; + txtnewname.SelectionStart = 14; + txtnewname.ShortcutsEnabled = true; + txtnewname.WordWrap = true; + txtnewname.BackgroundImageLayout = ImageLayout.Tile; + txtnewname.Alignment = (ContentAlignment)0; + txtnewname.AccessibleDefaultActionDescription = ""; + txtnewname.AccessibleDescription = ""; + txtnewname.AccessibleName = ""; + txtnewname.AccessibleRole = AccessibleRole.Default; + txtnewname.AllowDrop = false; + txtnewname.Anchor = AnchorStyles.Top | AnchorStyles.Left; + txtnewname.AutoScrollOffset = new Point(0, 0); + txtnewname.MaximumSize = new Size(0, 0); + txtnewname.MinimumSize = new Size(0, 0); + txtnewname.Capture = false; + txtnewname.CausesValidation = true; + txtnewname.ClientSize = new Size(272, 20); + txtnewname.Dock = DockStyle.None; + txtnewname.Enabled = true; + txtnewname.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + txtnewname.Height = 24; + txtnewname.ImeMode = ImeMode.NoControl; + txtnewname.IsAccessible = false; + txtnewname.Left = 11; + txtnewname.Location = new Point(11, 35); + txtnewname.Name = "txtnewname"; + txtnewname.RightToLeft = RightToLeft.No; + txtnewname.Size = new Size(276, 24); + txtnewname.TabIndex = 1; + txtnewname.TabStop = true; + txtnewname.Top = 35; + txtnewname.UseWaitCursor = false; + txtnewname.Visible = true; + txtnewname.Width = 276; + this.Widgets.Add(txtnewname); + txtnewname.Show(); + lblnewnamelabel = new Label(); + lblnewnamelabel.AutoEllipsis = false; + lblnewnamelabel.AutoSize = false; + lblnewnamelabel.BackgroundImageLayout = ImageLayout.Tile; + lblnewnamelabel.BorderStyle = BorderStyle.None; + lblnewnamelabel.FlatStyle = FlatStyle.Standard; + lblnewnamelabel.ImageAlign = ContentAlignment.MiddleCenter; + lblnewnamelabel.ImageIndex = -1; + lblnewnamelabel.ImageKey = ""; + lblnewnamelabel.ImeMode = ImeMode.NoControl; + lblnewnamelabel.TabStop = false; + lblnewnamelabel.TextAlign = ContentAlignment.TopLeft; + lblnewnamelabel.UseMnemonic = true; + lblnewnamelabel.UseCompatibleTextRendering = true; + lblnewnamelabel.Text = "New name:"; + lblnewnamelabel.Alignment = (ContentAlignment)0; + lblnewnamelabel.AccessibleDefaultActionDescription = ""; + lblnewnamelabel.AccessibleDescription = ""; + lblnewnamelabel.AccessibleName = ""; + lblnewnamelabel.AccessibleRole = AccessibleRole.Default; + lblnewnamelabel.AllowDrop = false; + lblnewnamelabel.Anchor = AnchorStyles.Top | AnchorStyles.Left; + lblnewnamelabel.AutoScrollOffset = new Point(0, 0); + lblnewnamelabel.MaximumSize = new Size(0, 0); + lblnewnamelabel.MinimumSize = new Size(0, 0); + lblnewnamelabel.BackColor = Color.FromArgb(255, 255, 0); + lblnewnamelabel.Capture = false; + lblnewnamelabel.CausesValidation = true; + lblnewnamelabel.ClientSize = new Size(100, 23); + lblnewnamelabel.Dock = DockStyle.None; + lblnewnamelabel.Enabled = true; + lblnewnamelabel.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + lblnewnamelabel.ForeColor = Color.FromArgb(0, 0, 0); + lblnewnamelabel.Height = 23; + lblnewnamelabel.IsAccessible = false; + lblnewnamelabel.Left = 12; + lblnewnamelabel.Location = new Point(12, 18); + lblnewnamelabel.Name = "lblnewnamelabel"; + lblnewnamelabel.RightToLeft = RightToLeft.No; + lblnewnamelabel.Size = new Size(100, 23); + lblnewnamelabel.TabIndex = 2; + lblnewnamelabel.Top = 18; + lblnewnamelabel.UseWaitCursor = false; + lblnewnamelabel.Visible = true; + lblnewnamelabel.Width = 100; + this.Widgets.Add(lblnewnamelabel); + lblnewnamelabel.Show(); + + } + public Button btnok = null; public TextBox txtnewname = null; public Label lblnewnamelabel = null; + } + + public class FormSelectionForm : Form + { + public FormSelectionForm() + { + this.AllowTransparency = false; + this.AutoScale = true; + this.AutoScaleBaseSize = new Size(5, 13); + this.AutoScroll = false; + this.AutoSize = false; + this.AutoSizeMode = AutoSizeMode.GrowOnly; + this.AutoValidate = AutoValidate.Inherit; + this.BackColor = Color.FromArgb(240, 240, 240); + this.ClientSize = new Size(456, 395); + this.WidgetBox = true; + this.DesktopLocation = new Point(0, 0); + this.DialogResult = DialogResult.None; + this.FormBorderStyle = FormBorderStyle.Sizable; + this.HelpButton = false; + this.IsMdiContainer = false; + this.KeyPreview = false; + this.MaximizeBox = true; + this.MaximumSize = new Size(0, 0); + this.MinimizeBox = true; + this.MinimumSize = new Size(0, 0); + this.RightToLeftLayout = false; + this.ShowIcon = true; + this.ShowInTaskbar = true; + this.Size = new Size(456, 395); + this.SizeGripStyle = SizeGripStyle.Auto; + this.StartPosition = FormStartPosition.WindowsDefaultLocation; + this.TabIndex = 0; + this.TabStop = true; + this.TopLevel = true; + this.TopMost = false; + this.WindowState = FormWindowState.Normal; + this.Text = "Select form"; + this.Location = new Point(0, 0); + this.AutoScaleMode = AutoScaleMode.Inherit; + this.AutoScrollMargin = new Size(0, 0); + this.AutoScrollMinSize = new Size(0, 0); + this.AutoScrollPosition = new Point(0, 0); + this.Alignment = (ContentAlignment)0; + this.AccessibleDefaultActionDescription = ""; + this.AccessibleDescription = ""; + this.AccessibleName = ""; + this.AccessibleRole = AccessibleRole.Default; + this.AllowDrop = false; + this.Anchor = AnchorStyles.Top | AnchorStyles.Left; + this.AutoScrollOffset = new Point(0, 0); + this.BackgroundImageLayout = ImageLayout.Tile; + this.Capture = false; + this.CausesValidation = true; + this.Dock = DockStyle.None; + this.Enabled = true; + this.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + this.ForeColor = Color.FromArgb(0, 0, 0); + this.Height = 395; + this.ImeMode = ImeMode.NoControl; + this.IsAccessible = false; + this.Left = 0; + this.Name = "Form1"; + this.RightToLeft = RightToLeft.No; + this.Top = 0; + this.UseWaitCursor = false; + this.Visible = false; + this.Width = 456; + + lblabel = new Label(); + lblabel.AutoEllipsis = false; + lblabel.AutoSize = false; + lblabel.BackgroundImageLayout = ImageLayout.Tile; + lblabel.BorderStyle = BorderStyle.None; + lblabel.FlatStyle = FlatStyle.Standard; + lblabel.ImageAlign = ContentAlignment.MiddleCenter; + lblabel.ImageIndex = -1; + lblabel.ImageKey = ""; + lblabel.ImeMode = ImeMode.NoControl; + lblabel.TabStop = false; + lblabel.TextAlign = ContentAlignment.TopLeft; + lblabel.UseMnemonic = true; + lblabel.UseCompatibleTextRendering = true; + lblabel.Text = "Please select a form inside the ShiftOS code to load into the ShiftUI designer."; + lblabel.Alignment = (ContentAlignment)0; + lblabel.AccessibleDefaultActionDescription = ""; + lblabel.AccessibleDescription = ""; + lblabel.AccessibleName = ""; + lblabel.AccessibleRole = AccessibleRole.Default; + lblabel.AllowDrop = false; + lblabel.Anchor = AnchorStyles.Top | AnchorStyles.Left; + lblabel.AutoScrollOffset = new Point(0, 0); + lblabel.MaximumSize = new Size(0, 0); + lblabel.MinimumSize = new Size(0, 0); + lblabel.BackColor = Color.FromArgb(240, 240, 240); + lblabel.Capture = false; + lblabel.CausesValidation = true; + lblabel.ClientSize = new Size(390, 16); + lblabel.Dock = DockStyle.None; + lblabel.Enabled = true; + lblabel.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + lblabel.ForeColor = Color.FromArgb(0, 0, 0); + lblabel.Height = 16; + lblabel.IsAccessible = false; + lblabel.Left = 19; + lblabel.Location = new Point(19, 18); + lblabel.Name = "lblabel"; + lblabel.RightToLeft = RightToLeft.No; + lblabel.Size = new Size(390, 16); + lblabel.TabIndex = 0; + lblabel.Top = 18; + lblabel.UseWaitCursor = false; + lblabel.Visible = true; + lblabel.Width = 390; + this.Widgets.Add(lblabel); + lblabel.Show(); + lvforms = new ListView(); + lvforms.Activation = ItemActivation.Standard; + lvforms.Alignment = ListViewAlignment.Top; + lvforms.AllowColumnReorder = false; + lvforms.AutoArrange = true; + lvforms.BackColor = Color.FromArgb(255, 255, 255); + lvforms.BackgroundImageLayout = ImageLayout.Tile; + lvforms.BackgroundImageTiled = false; + lvforms.BorderStyle = BorderStyle.Fixed3D; + lvforms.CheckBoxes = false; + lvforms.ForeColor = Color.FromArgb(0, 0, 0); + lvforms.FullRowSelect = false; + lvforms.GridLines = false; + lvforms.HeaderStyle = ColumnHeaderStyle.Clickable; + lvforms.HideSelection = true; + lvforms.HotTracking = false; + lvforms.HoverSelection = false; + lvforms.LabelEdit = false; + lvforms.LabelWrap = true; + lvforms.MultiSelect = true; + lvforms.OwnerDraw = false; + lvforms.RightToLeftLayout = false; + lvforms.Scrollable = true; + lvforms.ShowGroups = true; + lvforms.ShowItemToolTips = false; + lvforms.Sorting = SortOrder.None; + lvforms.Text = ""; + lvforms.UseCompatibleStateImageBehavior = false; + lvforms.View = View.List; + lvforms.VirtualMode = false; + lvforms.VirtualListSize = 0; + lvforms.Alignment = (ListViewAlignment)0; + lvforms.AccessibleDefaultActionDescription = ""; + lvforms.AccessibleDescription = ""; + lvforms.AccessibleName = ""; + lvforms.AccessibleRole = AccessibleRole.Default; + lvforms.AllowDrop = false; + lvforms.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + lvforms.AutoScrollOffset = new Point(0, 0); + lvforms.AutoSize = false; + lvforms.MaximumSize = new Size(0, 0); + lvforms.MinimumSize = new Size(0, 0); + lvforms.Capture = false; + lvforms.CausesValidation = true; + lvforms.ClientSize = new Size(407, 280); + lvforms.Dock = DockStyle.None; + lvforms.Enabled = true; + lvforms.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + lvforms.Height = 284; + lvforms.ImeMode = ImeMode.NoControl; + lvforms.IsAccessible = false; + lvforms.Left = 16; + lvforms.Location = new Point(16, 36); + lvforms.Name = "lvforms"; + lvforms.RightToLeft = RightToLeft.No; + lvforms.Size = new Size(411, 284); + lvforms.TabIndex = 1; + lvforms.TabStop = true; + lvforms.Top = 36; + lvforms.UseWaitCursor = false; + lvforms.Visible = true; + lvforms.Width = 411; + this.Widgets.Add(lvforms); + lvforms.Show(); + btnstart = new Button(); + btnstart.AutoSizeMode = AutoSizeMode.GrowOnly; + btnstart.DialogResult = DialogResult.None; + btnstart.AutoEllipsis = false; + btnstart.AutoSize = false; + btnstart.BackColor = Color.FromArgb(240, 240, 240); + btnstart.FlatStyle = FlatStyle.Standard; + btnstart.ImageAlign = ContentAlignment.MiddleCenter; + btnstart.ImageIndex = -1; + btnstart.ImageKey = ""; + btnstart.ImeMode = ImeMode.Disable; + btnstart.Text = "Design"; + btnstart.TextAlign = ContentAlignment.MiddleCenter; + btnstart.TextImageRelation = TextImageRelation.Overlay; + btnstart.UseCompatibleTextRendering = true; + btnstart.UseMnemonic = true; + btnstart.UseVisualStyleBackColor = true; + btnstart.Alignment = (ContentAlignment)0; + btnstart.AccessibleDefaultActionDescription = ""; + btnstart.AccessibleDescription = ""; + btnstart.AccessibleName = ""; + btnstart.AccessibleRole = AccessibleRole.Default; + btnstart.AllowDrop = false; + btnstart.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + btnstart.AutoScrollOffset = new Point(0, 0); + btnstart.MaximumSize = new Size(0, 0); + btnstart.MinimumSize = new Size(0, 0); + btnstart.BackgroundImageLayout = ImageLayout.Tile; + btnstart.Capture = false; + btnstart.CausesValidation = true; + btnstart.ClientSize = new Size(75, 23); + btnstart.Dock = DockStyle.None; + btnstart.Enabled = true; + btnstart.Font = new Font("Microsoft Sans Serif", (float)8.25, (FontStyle)0); + btnstart.ForeColor = Color.FromArgb(0, 0, 0); + btnstart.Height = 23; + btnstart.IsAccessible = false; + btnstart.Left = 17; + btnstart.Location = new Point(17, 329); + btnstart.Name = "btnstart"; + btnstart.RightToLeft = RightToLeft.No; + btnstart.Size = new Size(75, 23); + btnstart.TabIndex = 2; + btnstart.TabStop = true; + btnstart.Top = 329; + btnstart.UseWaitCursor = false; + btnstart.Visible = true; + btnstart.Width = 75; + this.Widgets.Add(btnstart); + btnstart.Show(); + btnstart.Click += (o, a) => + { + if(lvforms.SelectedItems.Count > 0) + { + var form = lvforms.SelectedItems[0].Tag as Form; + var designer = new MainEditorForm(); + designer.LoadFormFromClass(form); + } + }; + ShiftOS.Program.Main(new[] { "nodisplay" }); + ShiftOS.API.ShouldLoadEngine = false; //so that things like bitnote wallet don't try to connect to server and stuff + Assembly asm = Assembly.Load("ShiftOS"); + Type[] types = asm.GetTypes(); + Dictionary forms = new Dictionary(); + foreach(var type in types) + { + try + { + if (type.BaseType == typeof(Form) && type != this.GetType()) + { + this.Debug($"Found form \"{type.Name}\" in assembly \"{asm.FullName}\"..."); + forms.Add(type.Name, Activator.CreateInstance(type) as Form); + } + } + catch + { + + } + } + foreach(var item in forms) + { + var lvitem = new ListViewItem(); + lvitem.Text = item.Key; + lvitem.Tag = item.Value; + lvforms.Items.Add(lvitem); + } + + } + public Label lblabel = null; public ListView lvforms = null; public Button btnstart = null; + } + +} + + -- cgit v1.2.3 From bf7a488011c09be39bdb4980c2bb020cb1fdb71a Mon Sep 17 00:00:00 2001 From: Carver Harrison Date: Sun, 24 Jul 2016 11:17:36 -0700 Subject: Added Hashing API and Fixed Bugs --- source/ShiftUI Designer/Program.cs | 8 +- source/WindowsFormsApplication1/API.cs | 720 +++++++++++---------- .../Desktop/ShiftOSDesktop.cs | 332 +++++----- source/WindowsFormsApplication1/Program.cs | 16 +- 4 files changed, 566 insertions(+), 510 deletions(-) (limited to 'source/ShiftUI Designer/Program.cs') diff --git a/source/ShiftUI Designer/Program.cs b/source/ShiftUI Designer/Program.cs index 7e4be98..4ca9e98 100644 --- a/source/ShiftUI Designer/Program.cs +++ b/source/ShiftUI Designer/Program.cs @@ -1423,10 +1423,10 @@ namespace ShiftUI_DesignerGenerated { forms.Add(type.Name, Activator.CreateInstance(type) as Form); } } - catch - { - - } + catch (Exception catcherror) + { + Console.WriteLine(catcherror); + } } foreach(var item in forms) { diff --git a/source/WindowsFormsApplication1/API.cs b/source/WindowsFormsApplication1/API.cs index e81788d..157f373 100644 --- a/source/WindowsFormsApplication1/API.cs +++ b/source/WindowsFormsApplication1/API.cs @@ -80,341 +80,391 @@ namespace ShiftOS } - public class API - { - public static Dictionary OpenGUIDs = new Dictionary(); - public static Dictionary DEF_PanelGUIDs = new Dictionary(); - - - /// - /// Settings file. - /// - public static Settings LoadedSettings = null; - - /// - /// Whether or not dev commands like '05tray' are available. - /// Typically, this is set to true if the release is classified as - /// an alpha, beta, or release candidate. - /// - /// Turn it off if the release is the final RC, or the stable release! - /// - /// Enabling developer mode will cause the save engine to not encrypt the save file - /// or Shiftorium Registry on save, enabling you to easily modify your save - /// to test new features or to bring in lots of codepoints. This is why - /// Developer mode should ALWAYS be off in non-dev releases, to prevent cheating. - /// - public static bool DeveloperMode = true; - - /// - /// If this is true, only certain applications will open and only - /// certain features will work. - /// - /// This is useful for story plots like the End Game where you don't - /// want the user being distracted by novelty features when they should - /// be focusing on what's happening. - /// - /// Think of it like the opposite of what Developer Mode would do. - /// - public static bool LimitedMode = false; - - public static bool InfoboxesPlaySounds = true; - - public static void SkinWidget(Widget c) - { - if(c is Button) - { - var b = c as Button; - b.FlatStyle = FlatStyle.Standard; - } - if(c is Panel || c is FlowLayoutPanel) - { - foreach(Widget child in c.Widgets) - { - SkinWidget(child); - } - } - } - - public static List RunningModProcesses = new List(); - public static Dictionary CommandAliases = new Dictionary(); - public static Terminal LoggerTerminal = null; - - // Alternate Names for True and False - public static bool yes = true; - public static bool no = false; - - /// - /// Logs an exception to the log. - /// - /// The text to log. - /// Is it a fatal crash? - public static void LogException(string Message, bool fatal) - { - if(!File.Exists(Paths.SystemDir + "_Log.txt")) - { - if (fatal == true) - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); - } - else - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); - } - } - else - { - List Entries = new List(); - foreach(string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) { - Entries.Add(entry); - } - if (fatal == true) - { - Entries.Add(GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); - } - else - { - Entries.Add(GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); - } - File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); - } - } - - /// - /// Logs text to the log file. - /// - /// The text to log. - public static void Log(string Message) - { - if (!File.Exists(Paths.SystemDir + "_Log.txt")) - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message); - } - else - { - List Entries = new List(); - foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) - { - Entries.Add(entry); - } - Entries.Add(GetLogTime() + " " + Message); - File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); - } - } - - /// - /// Gets a proper-formatted date/time string for the log. - /// - /// - public static string GetLogTime() - { - return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]"; - } - - /// - /// Property representing the currently loaded name pack. - /// - public static Skinning.NamePack LoadedNames - { - get - { - if (Skinning.Utilities.LoadedNames != null) - { - return Skinning.Utilities.LoadedNames; - } - else - { - Skinning.Utilities.LoadedNames = new Skinning.NamePack(); - Skinning.Utilities.loadedSkin.EmbeddedNamePackPath = "names.npk"; - Skinning.Utilities.SaveEmbeddedNamePack(); - Log("[Name Changer] Couldn't locate loaded name pack, using default name pack."); - return Skinning.Utilities.LoadedNames; - } - } - } - - /// - /// Adds a command line alias. - /// - /// Alias name - /// Command to run. - /// - public static bool AddAlias(string key, string value) - { - if(!AliasExists(key)) - { - CommandAliases.Add(key, value); - return true; - } - else - { - return false; - } - } - - /// - /// Saves alias list to save game. - /// - public static void SaveAliases() - { - string json = JsonConvert.SerializeObject(CommandAliases); - File.WriteAllText(Paths.SystemDir + "_aliases.json", json); - } - - /// - /// Loads alias list from the save game. - /// - public static void LoadAliases() - { - if (File.Exists(Paths.SystemDir + "_aliases.json")) { - string json = File.ReadAllText(Paths.SystemDir + "_aliases.json"); - CommandAliases = JsonConvert.DeserializeObject>(json); - } - else - { - CommandAliases = new Dictionary(); - } - - } - - /// - /// Removes an alias from the list. - /// - /// Alias to remove. - /// Whether the alias could be removed. - public static bool RemoveAlias(string key) - { - if(AliasExists(key)) - { - CommandAliases.Remove(key); - return true; - } - else - { - return false; - } - } - - /// - /// Checks if the provided alias exists. - /// - /// The alias to check. - /// Whether the alias exists. - public static bool AliasExists(string key) - { - bool no = false; - foreach(KeyValuePair kv in CommandAliases) - { - if(kv.Key == key) - { - no = true; - } - } - return no; - } - - /// - /// I have no idea what this does - Michael - /// - /// - public static void CreateNewLoggerTerminal(string AppName) - { - CreateForm(new Terminal(true), AppName, Properties.Resources.iconTerminal); - } - - public const string HiddenAPMCommand = "0Ifm0DcBBy10VZo/p4r1Jg=="; - public const string HiddenBTNConvertCommand = "js2qrls5kvZnutMbfH46sUKzKVrBtjzPlWn/wIIe/3g="; - public const string HiddenDodgeCommand = "mpL4WPUoDcZrsXnNUJ5RWQ=="; - public const string HiddenLabyrinthCommand = "NbNzpplGKaS5D/RdwrQMXw=="; - public const string HiddenQuickChatCommand = "iQm+/qDqgkHT/zgPiYRlZQ=="; - public const string HiddenShiftnetCommand = "NCM++hbZox7B+m9tXRXGnw=="; - public const string HiddenBWalletCommand = "1nLiZELFcaxkXDufrLuyfw=="; - public const string HiddenBDiggerCommand = "g/efSjsaglt//dr3XHnPOw=="; - public const string HiddenDecryptorCommand = "CYPXaweggfWAuS7ONt/OPQ=="; - - /// - /// Launches an saa file, hooks it up to the Lua API, and runs it. - /// - /// File to run. - public static void LaunchMod(string modSAA) - { - if (!LimitedMode) - { - if (Upgrades["shiftnet"] == true) - { - if (File.Exists(modSAA)) - { - if (File.ReadAllText(modSAA) == HiddenAPMCommand) - { - CreateForm(new Appscape(), "Appscape Package Manager", Properties.Resources.iconAppscape); - } - else if (File.ReadAllText(modSAA) == HiddenDecryptorCommand) - { - CreateForm(new ShiftnetDecryptor(), "Shiftnet Decryptor", Properties.Resources.iconShiftnet); - } - else if (File.ReadAllText(modSAA) == HiddenBDiggerCommand) - { - CreateForm(new BitnoteDigger(), "Bitnote Digger", Properties.Resources.iconBitnoteDigger); - } - else if (File.ReadAllText(modSAA) == HiddenBWalletCommand) - { - CreateForm(new BitnoteWallet(), "Bitnote Wallet", Properties.Resources.iconBitnoteWallet); - } - else if (File.ReadAllText(modSAA) == HiddenShiftnetCommand) - { - CreateForm(new Shiftnet(), "Shiftnet", Properties.Resources.iconShiftnet); - } - else if (File.ReadAllText(modSAA) == HiddenBTNConvertCommand) - { - CreateForm(new BitnoteConverter(), "Bitnote Converter", Properties.Resources.iconBitnoteWallet); - } - else if (File.ReadAllText(modSAA) == HiddenDodgeCommand) - { - CreateForm(new Dodge(), "Dodge", Properties.Resources.iconDodge); - } - else if (File.ReadAllText(modSAA) == HiddenLabyrinthCommand) - { - CreateForm(new Labyrinth(), "Labyrinth", null); - } - else - { - try - { - ExtractFile(modSAA, Paths.Mod_Temp, true); - var l = new LuaInterpreter(Paths.Mod_Temp + "main.lua"); - } - catch (Exception ex) - { - LogException("Error launching mod file (.saa): " + ex.Message, false); - CreateInfoboxSession("Error", "Could not launch the .saa file you specified. It is unsupported by this version of ShiftOS.", infobox.InfoboxMode.Info); - } - } - var story_rnd = new Random(); - int story_chance = story_rnd.Next(0, 3); - switch (story_chance) { - case 2: - if(API.Upgrades["holochat"] == false) - { - var t = new Terminal(); - API.CreateForm(t, API.LoadedNames.TerminalName, API.GetIcon("Terminal")); - t.StartDevXFuriousStory(); - t.BringToFront(); - } - break; - } - - } - else - { - throw new ModNotFoundException(); - } - } - } - else - { - CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot perform this action. Please complete the current Mission first.", infobox.InfoboxMode.Info); - } - } - + public class API + { + public static Dictionary OpenGUIDs = new Dictionary(); + public static Dictionary DEF_PanelGUIDs = new Dictionary(); + + + /// + /// Settings file. + /// + public static Settings LoadedSettings = null; + + /// + /// Whether or not dev commands like '05tray' are available. + /// Typically, this is set to true if the release is classified as + /// an alpha, beta, or release candidate. + /// + /// Turn it off if the release is the final RC, or the stable release! + /// + /// Enabling developer mode will cause the save engine to not encrypt the save file + /// or Shiftorium Registry on save, enabling you to easily modify your save + /// to test new features or to bring in lots of codepoints. This is why + /// Developer mode should ALWAYS be off in non-dev releases, to prevent cheating. + /// + public static bool DeveloperMode = true; + + /// + /// If this is true, only certain applications will open and only + /// certain features will work. + /// + /// This is useful for story plots like the End Game where you don't + /// want the user being distracted by novelty features when they should + /// be focusing on what's happening. + /// + /// Think of it like the opposite of what Developer Mode would do. + /// + public static bool LimitedMode = false; + + public static bool InfoboxesPlaySounds = true; + + public static void SkinWidget(Widget c) + { + if (c is Button) + { + var b = c as Button; + b.FlatStyle = FlatStyle.Standard; + } + if (c is Panel || c is FlowLayoutPanel) + { + foreach (Widget child in c.Widgets) + { + SkinWidget(child); + } + } + } + + public static List RunningModProcesses = new List(); + public static Dictionary CommandAliases = new Dictionary(); + public static Terminal LoggerTerminal = null; + + // Alternate Names for True and False + public static bool yes = true; + public static bool no = false; + + /// + /// Logs an exception to the log. + /// + /// The text to log. + /// Is it a fatal crash? + public static void LogException(string Message, bool fatal) + { + if (!File.Exists(Paths.SystemDir + "_Log.txt")) + { + if (fatal == true) + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); + } + else + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); + } + } + else + { + List Entries = new List(); + foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) + { + Entries.Add(entry); + } + if (fatal == true) + { + Entries.Add(GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); + } + else + { + Entries.Add(GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); + } + File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); + } + } + + /// + /// Logs text to the log file. + /// + /// The text to log. + public static void Log(string Message) + { + if (!File.Exists(Paths.SystemDir + "_Log.txt")) + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message); + } + else + { + List Entries = new List(); + foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) + { + Entries.Add(entry); + } + Entries.Add(GetLogTime() + " " + Message); + File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); + } + } + + /// + /// Gets a proper-formatted date/time string for the log. + /// + /// + public static string GetLogTime() + { + return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]"; + } + + /// + /// Property representing the currently loaded name pack. + /// + public static Skinning.NamePack LoadedNames + { + get + { + if (Skinning.Utilities.LoadedNames != null) + { + return Skinning.Utilities.LoadedNames; + } + else + { + Skinning.Utilities.LoadedNames = new Skinning.NamePack(); + Skinning.Utilities.loadedSkin.EmbeddedNamePackPath = "names.npk"; + Skinning.Utilities.SaveEmbeddedNamePack(); + Log("[Name Changer] Couldn't locate loaded name pack, using default name pack."); + return Skinning.Utilities.LoadedNames; + } + } + } + + /// + /// Adds a command line alias. + /// + /// Alias name + /// Command to run. + /// + public static bool AddAlias(string key, string value) + { + if (!AliasExists(key)) + { + CommandAliases.Add(key, value); + return true; + } + else + { + return false; + } + } + + /// + /// Saves alias list to save game. + /// + public static void SaveAliases() + { + string json = JsonConvert.SerializeObject(CommandAliases); + File.WriteAllText(Paths.SystemDir + "_aliases.json", json); + } + + /// + /// Loads alias list from the save game. + /// + public static void LoadAliases() + { + if (File.Exists(Paths.SystemDir + "_aliases.json")) + { + string json = File.ReadAllText(Paths.SystemDir + "_aliases.json"); + CommandAliases = JsonConvert.DeserializeObject>(json); + } + else + { + CommandAliases = new Dictionary(); + } + + } + + /// + /// Removes an alias from the list. + /// + /// Alias to remove. + /// Whether the alias could be removed. + public static bool RemoveAlias(string key) + { + if (AliasExists(key)) + { + CommandAliases.Remove(key); + return true; + } + else + { + return false; + } + } + + /// + /// Checks if the provided alias exists. + /// + /// The alias to check. + /// Whether the alias exists. + public static bool AliasExists(string key) + { + bool nay = false; + foreach (KeyValuePair kv in CommandAliases) + { + if (kv.Key == key) + { + nay = true; + } + } + return nay; + } + + /// + /// I have no idea what this does - Michael + /// + /// + public static void CreateNewLoggerTerminal(string AppName) + { + CreateForm(new Terminal(true), AppName, Properties.Resources.iconTerminal); + } + + public const string HiddenAPMCommand = "0Ifm0DcBBy10VZo/p4r1Jg=="; + public const string HiddenBTNConvertCommand = "js2qrls5kvZnutMbfH46sUKzKVrBtjzPlWn/wIIe/3g="; + public const string HiddenDodgeCommand = "mpL4WPUoDcZrsXnNUJ5RWQ=="; + public const string HiddenLabyrinthCommand = "NbNzpplGKaS5D/RdwrQMXw=="; + public const string HiddenQuickChatCommand = "iQm+/qDqgkHT/zgPiYRlZQ=="; + public const string HiddenShiftnetCommand = "NCM++hbZox7B+m9tXRXGnw=="; + public const string HiddenBWalletCommand = "1nLiZELFcaxkXDufrLuyfw=="; + public const string HiddenBDiggerCommand = "g/efSjsaglt//dr3XHnPOw=="; + public const string HiddenDecryptorCommand = "CYPXaweggfWAuS7ONt/OPQ=="; + + /// + /// Launches an saa file, hooks it up to the Lua API, and runs it. + /// + /// File to run. + public static void LaunchMod(string modSAA) + { + if (!LimitedMode) + { + if (Upgrades["shiftnet"] == true) + { + if (File.Exists(modSAA)) + { + if (File.ReadAllText(modSAA) == HiddenAPMCommand) + { + CreateForm(new Appscape(), "Appscape Package Manager", Properties.Resources.iconAppscape); + } + else if (File.ReadAllText(modSAA) == HiddenDecryptorCommand) + { + CreateForm(new ShiftnetDecryptor(), "Shiftnet Decryptor", Properties.Resources.iconShiftnet); + } + else if (File.ReadAllText(modSAA) == HiddenBDiggerCommand) + { + CreateForm(new BitnoteDigger(), "Bitnote Digger", Properties.Resources.iconBitnoteDigger); + } + else if (File.ReadAllText(modSAA) == HiddenBWalletCommand) + { + CreateForm(new BitnoteWallet(), "Bitnote Wallet", Properties.Resources.iconBitnoteWallet); + } + else if (File.ReadAllText(modSAA) == HiddenShiftnetCommand) + { + CreateForm(new Shiftnet(), "Shiftnet", Properties.Resources.iconShiftnet); + } + else if (File.ReadAllText(modSAA) == HiddenBTNConvertCommand) + { + CreateForm(new BitnoteConverter(), "Bitnote Converter", Properties.Resources.iconBitnoteWallet); + } + else if (File.ReadAllText(modSAA) == HiddenDodgeCommand) + { + CreateForm(new Dodge(), "Dodge", Properties.Resources.iconDodge); + } + else if (File.ReadAllText(modSAA) == HiddenLabyrinthCommand) + { + CreateForm(new Labyrinth(), "Labyrinth", null); + } + else + { + try + { + ExtractFile(modSAA, Paths.Mod_Temp, true); + var l = new LuaInterpreter(Paths.Mod_Temp + "main.lua"); + } + catch (Exception ex) + { + LogException("Error launching mod file (.saa): " + ex.Message, false); + CreateInfoboxSession("Error", "Could not launch the .saa file you specified. It is unsupported by this version of ShiftOS.", infobox.InfoboxMode.Info); + } + } + var story_rnd = new Random(); + int story_chance = story_rnd.Next(0, 3); + switch (story_chance) + { + case 2: + if (API.Upgrades["holochat"] == false) + { + var t = new Terminal(); + API.CreateForm(t, API.LoadedNames.TerminalName, API.GetIcon("Terminal")); + t.StartDevXFuriousStory(); + t.BringToFront(); + } + break; + } + + } + else + { + throw new ModNotFoundException(); + } + } + } + else + { + CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot perform this action. Please complete the current Mission first.", infobox.InfoboxMode.Info); + } + } + + /// + /// Base64 Function + /// + public static class Base64 + { + public static string Encrypt(string text) + { + return Convert.ToBase64String(Encoding.UTF8.GetBytes(text)); + } + + public static string Decrypt(string text) + { + return Encoding.UTF8.GetString(Convert.FromBase64String(text)); + } + } + + /// + /// Hashing API + /// By Carver Harrison (@carverh) + /// + public static class Hash + { + public static string MD5(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.MD5.Create(text).Hash); + } + public static string SHA1(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA1.Create(text).Hash); + } + public static string SHA256(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA256.Create(text).Hash); + } + public static string SHA384(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA384.Create(text).Hash); + } + public static string SHA512(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA512.Create(text).Hash); + } + public static string DSA(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.DSA.Create().CreateSignature(Encoding.UTF8.GetBytes(text))); + } + } /// /// Source: http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp diff --git a/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs b/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs index 6d8af77..85659c2 100644 --- a/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs +++ b/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs @@ -327,45 +327,53 @@ namespace ShiftOS public void SetupDesktop() { - SetupRenderers(); - SetupDesktopPanel(); - SetupAppLauncher(); - SetupDesktopIcons(); - SetupGNOME2Elements(); - SetupPanelClock(); - SetupPanelButtons(); - CheckUnity(); - SetupWidgets(); - CheckForChristmas(); - //Set up the context menus. - addDesktopPanelToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"]; - widgetManagerToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"]; - if (API.Upgrades["advanceddesktop"]) - { - AppLauncherPanel.ContextMenuStrip = cbwidget; - Clock.ContextMenuStrip = cbwidget; - PanelButtonHolder.ContextMenuStrip = cbwidget; - } - else - { - AppLauncherPanel.ContextMenuStrip = null; - Clock.ContextMenuStrip = null; - PanelButtonHolder.ContextMenuStrip = null; - } - if (DesktopPanels != null) { - foreach (var dp in DesktopPanels) - { - if (API.Upgrades["advanceddesktop"]) - { - dp.ContextMenuStrip = cbdpanel; - } - else - { - dp.ContextMenuStrip = cbdpanel; - } - } - } - OnDesktopReload?.Invoke(); + try + { + SetupRenderers(); + SetupDesktopPanel(); + SetupAppLauncher(); + SetupDesktopIcons(); + SetupGNOME2Elements(); + SetupPanelClock(); + SetupPanelButtons(); + CheckUnity(); + SetupWidgets(); + CheckForChristmas(); + //Set up the context menus. + addDesktopPanelToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"]; + widgetManagerToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"]; + if (API.Upgrades["advanceddesktop"]) + { + AppLauncherPanel.ContextMenuStrip = cbwidget; + Clock.ContextMenuStrip = cbwidget; + PanelButtonHolder.ContextMenuStrip = cbwidget; + } + else + { + AppLauncherPanel.ContextMenuStrip = null; + Clock.ContextMenuStrip = null; + PanelButtonHolder.ContextMenuStrip = null; + } + if (DesktopPanels != null) + { + foreach (var dp in DesktopPanels) + { + if (API.Upgrades["advanceddesktop"]) + { + dp.ContextMenuStrip = cbdpanel; + } + else + { + dp.ContextMenuStrip = cbdpanel; + } + } + } + OnDesktopReload?.Invoke(); + } + catch (Exception catcherror) + { + Console.WriteLine(catcherror); + } } public void SetupWidgets() @@ -1072,23 +1080,23 @@ namespace ShiftOS if (API.Upgrades["usefulpanelbuttons"]) { Widget ctrl = (Widget)sender; - try - { - PanelButton pbtn = (PanelButton)ctrl.Tag; - var frm = pbtn.FormToManage; - if(frm.Left < Screen.PrimaryScreen.Bounds.Width) - { - API.MinimizeForm(frm); - } - else - { - API.ToggleMinimized(frm); - } - } - catch - { - - } + try + { + PanelButton pbtn = (PanelButton)ctrl.Tag; + var frm = pbtn.FormToManage; + if (frm.Left < Screen.PrimaryScreen.Bounds.Width) + { + API.MinimizeForm(frm); + } + else + { + API.ToggleMinimized(frm); + } + } + catch (Exception catcherror) + { + Console.WriteLine(catcherror); + } } } @@ -1315,113 +1323,111 @@ namespace ShiftOS public static List Icons = null; public static List Models = null; - public static void GetIcons() - { - Icons = new List(); - Models = new List(); - API.GetAppLauncherItems(); - if (!Directory.Exists(Paths.Desktop)) - { - Directory.CreateDirectory(Paths.Desktop); - } - else - { - foreach (string dir in Directory.GetDirectories(Paths.Desktop)) - { - //Get dir info - var dinf = new DirectoryInfo(dir); - //Create new IconModel - var m = new IconModel(); - //Set name to dir name - m.Name = dinf.Name; - //Set type to Directory - m.Type = IconType.Directory; - //Set lua to open directory in File Skimmer - m.Lua = $"fileskimmer('/Home/Desktop/{dinf.Name}')"; - Models.Add(m); - } - foreach (string file in Directory.GetFiles(Paths.Desktop)) - { - //Get file info - var finf = new FileInfo(file); - //Create new IconModel - var icm = new IconModel(); - //Set IconModel name to filename - icm.Name = finf.Name; - //Set IconModel's type based on file extension - switch (finf.Extension.ToLower()) //Make the string lower-case for ease of use. - { - case ".desktop": - //Desktop script. - icm.Type = IconType.Script; - icm.Lua = File.ReadAllText(finf.FullName); //The Lua that is to be ran by this script is in the file. - break; - case ".sct": - //Desktop Shortcut - NYI - break; - default: - //File. - icm.Type = IconType.File; - icm.Lua = $"fopen('/Home/Desktop/{finf.Name}')"; - break; - } - Models.Add(icm); - } - } - - foreach(IconModel m in Models) - { - var d = new DesktopIcon(); - d.IconName = m.Name; - d.LuaAction = m.Lua; - switch(m.Type) - { - case IconType.Directory: - d.Icon = API.GetIcon("Folder"); - break; - default: - var finf = new FileInfo(Paths.Desktop + d.IconName); - switch(finf.Extension) - { - case ".txt": - case ".doc": - case ".owd": - case ".docx": - d.Icon = API.GetIcon("TextFile"); - break; - case ".skn": - case ".spk": - d.Icon = API.GetIcon("SkinFile"); - break; - case ".saa": - d.Icon = API.GetIcon("SAAFile"); - break; - case ".pkg": - case ".stp": - d.Icon = API.GetIcon("SetupPackage"); - break; - default: - d.Icon = API.GetIcon("UnrecognizedFile"); - break; - } - break; - } - Icons.Add(d); - } - foreach (ApplauncherItem al in API.AppLauncherItems) - { - if (al.Display == true) - { - var dl = new DesktopIcon(); - dl.Icon = al.Icon; - dl.IconName = al.Name; - dl.LuaAction = al.Lua; - Icons.Add(dl); - } - } - - } - + public static void GetIcons() + { + Icons = new List(); + Models = new List(); + API.GetAppLauncherItems(); + if (!Directory.Exists(Paths.Desktop)) + { + Directory.CreateDirectory(Paths.Desktop); + } + else + { + foreach (string dir in Directory.GetDirectories(Paths.Desktop)) + { + //Get dir info + var dinf = new DirectoryInfo(dir); + //Create new IconModel + var m = new IconModel(); + //Set name to dir name + m.Name = dinf.Name; + //Set type to Directory + m.Type = IconType.Directory; + //Set lua to open directory in File Skimmer + m.Lua = $"fileskimmer('/Home/Desktop/{dinf.Name}')"; + Models.Add(m); + } + foreach (string file in Directory.GetFiles(Paths.Desktop)) + { + //Get file info + var finf = new FileInfo(file); + //Create new IconModel + var icm = new IconModel(); + //Set IconModel name to filename + icm.Name = finf.Name; + //Set IconModel's type based on file extension + switch (finf.Extension.ToLower()) //Make the string lower-case for ease of use. + { + case ".desktop": + //Desktop script. + icm.Type = IconType.Script; + icm.Lua = File.ReadAllText(finf.FullName); //The Lua that is to be ran by this script is in the file. + break; + case ".sct": + //Desktop Shortcut - NYI + break; + default: + //File. + icm.Type = IconType.File; + icm.Lua = $"fopen('/Home/Desktop/{finf.Name}')"; + break; + } + Models.Add(icm); + } + } + + foreach (IconModel m in Models) + { + var d = new DesktopIcon(); + d.IconName = m.Name; + d.LuaAction = m.Lua; + switch (m.Type) + { + case IconType.Directory: + d.Icon = API.GetIcon("Folder"); + break; + default: + var finf = new FileInfo(Paths.Desktop + d.IconName); + switch (finf.Extension) + { + case ".txt": + case ".doc": + case ".owd": + case ".docx": + d.Icon = API.GetIcon("TextFile"); + break; + case ".skn": + case ".spk": + d.Icon = API.GetIcon("SkinFile"); + break; + case ".saa": + d.Icon = API.GetIcon("SAAFile"); + break; + case ".pkg": + case ".stp": + d.Icon = API.GetIcon("SetupPackage"); + break; + default: + d.Icon = API.GetIcon("UnrecognizedFile"); + break; + } + break; + } + Icons.Add(d); + } + foreach (ApplauncherItem al in API.AppLauncherItems) + { + if (al.Display == true) + { + var dl = new DesktopIcon(); + dl.Icon = al.Icon; + dl.IconName = al.Name; + dl.LuaAction = al.Lua; + Icons.Add(dl); + } + } + } public class IconModel { public string Name { get; set; } diff --git a/source/WindowsFormsApplication1/Program.cs b/source/WindowsFormsApplication1/Program.cs index af294db..e6c4c23 100644 --- a/source/WindowsFormsApplication1/Program.cs +++ b/source/WindowsFormsApplication1/Program.cs @@ -40,10 +40,10 @@ namespace ShiftOS int port = Convert.ToInt32(addSplitter[1]); Package_Grabber.ConnectToServer(host, port); } - catch - { - - } + catch (Exception catcherror) + { + Console.WriteLine(catcherror); + } } } catch @@ -129,10 +129,10 @@ namespace ShiftOS } } } - catch - { - - } + catch (Exception e) + { + Console.WriteLine(e); + } } -- cgit v1.2.3