From 994f6b991a56382f530e3d43ad1f3a56c195559d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 19 Feb 2017 20:19:00 -0500 Subject: [PATCH] SFT making utilities --- .../Applications/FileSkimmer.Designer.cs | 46 ++++++++++++++++--- ShiftOS.WinForms/Applications/FileSkimmer.cs | 23 ++++++++++ .../Applications/FileSkimmer.resx | 3 ++ ShiftOS_TheReturn/Scripting.cs | 42 +++++++++++++++++ 4 files changed, 108 insertions(+), 6 deletions(-) diff --git a/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs b/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs index df31977..b75f801 100644 --- a/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs +++ b/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs @@ -55,7 +55,11 @@ namespace ShiftOS.WinForms.Applications this.lvitems = new System.Windows.Forms.ListView(); this.panel1 = new System.Windows.Forms.Panel(); this.lbcurrentfolder = new System.Windows.Forms.Label(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.newFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1.SuspendLayout(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // lvitems @@ -63,7 +67,7 @@ namespace ShiftOS.WinForms.Applications this.lvitems.Dock = System.Windows.Forms.DockStyle.Fill; this.lvitems.Location = new System.Drawing.Point(0, 0); this.lvitems.Name = "lvitems"; - this.lvitems.Size = new System.Drawing.Size(634, 356); + this.lvitems.Size = new System.Drawing.Size(634, 332); this.lvitems.TabIndex = 0; this.lvitems.UseCompatibleStateImageBehavior = false; this.lvitems.DoubleClick += new System.EventHandler(this.lvitems_DoubleClick); @@ -73,31 +77,58 @@ namespace ShiftOS.WinForms.Applications this.panel1.Controls.Add(this.lvitems); this.panel1.Controls.Add(this.lbcurrentfolder); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Location = new System.Drawing.Point(0, 24); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(634, 369); + this.panel1.Size = new System.Drawing.Size(634, 345); this.panel1.TabIndex = 1; // // lbcurrentfolder // this.lbcurrentfolder.Dock = System.Windows.Forms.DockStyle.Bottom; - this.lbcurrentfolder.Location = new System.Drawing.Point(0, 356); + this.lbcurrentfolder.Location = new System.Drawing.Point(0, 332); this.lbcurrentfolder.Name = "lbcurrentfolder"; this.lbcurrentfolder.Size = new System.Drawing.Size(634, 13); this.lbcurrentfolder.TabIndex = 1; this.lbcurrentfolder.Text = "label1"; // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.newFolderToolStripMenuItem, + this.deleteToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(634, 24); + this.menuStrip1.TabIndex = 2; + this.menuStrip1.Text = "menuStrip1"; + // + // newFolderToolStripMenuItem + // + this.newFolderToolStripMenuItem.Name = "newFolderToolStripMenuItem"; + this.newFolderToolStripMenuItem.Size = new System.Drawing.Size(79, 20); + this.newFolderToolStripMenuItem.Text = "New Folder"; + this.newFolderToolStripMenuItem.Click += new System.EventHandler(this.newFolderToolStripMenuItem_Click); + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(52, 20); + this.deleteToolStripMenuItem.Text = "Delete"; + // // FileSkimmer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(634, 369); this.Controls.Add(this.panel1); + this.Controls.Add(this.menuStrip1); this.Name = "FileSkimmer"; - this.Text = "{FILE_SKIMMER_NAME}"; + this.Size = new System.Drawing.Size(634, 369); this.Load += new System.EventHandler(this.FileSkimmer_Load); this.panel1.ResumeLayout(false); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -106,5 +137,8 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.ListView lvitems; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label lbcurrentfolder; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem newFolderToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/FileSkimmer.cs b/ShiftOS.WinForms/Applications/FileSkimmer.cs index ec8fd00..2881dc0 100644 --- a/ShiftOS.WinForms/Applications/FileSkimmer.cs +++ b/ShiftOS.WinForms/Applications/FileSkimmer.cs @@ -258,6 +258,29 @@ namespace ShiftOS.WinForms.Applications public void OnUpgrade() { } + + private void newFolderToolStripMenuItem_Click(object sender, EventArgs e) + { + Infobox.PromptText("New Folder", "Please type a name for your folder.", (path) => + { + if (!string.IsNullOrWhiteSpace(path)) + { + if(!Utils.DirectoryExists(this.currentdir + "/" + path)) + { + Utils.CreateDirectory(currentdir + "/" + path); + this.ResetList(); + } + else + { + Infobox.Show("New folder", "A folder with that name already exists."); + } + } + else + { + Infobox.Show("New folder", "You can't create a folder with no name!"); + } + }); + } } diff --git a/ShiftOS.WinForms/Applications/FileSkimmer.resx b/ShiftOS.WinForms/Applications/FileSkimmer.resx index 1af7de1..d5494e3 100644 --- a/ShiftOS.WinForms/Applications/FileSkimmer.resx +++ b/ShiftOS.WinForms/Applications/FileSkimmer.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index cfa1549..3ecf9d9 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -63,6 +63,12 @@ namespace ShiftOS.Engine.Scripting public dynamic Lua = new DynamicLua.DynamicLua(); public bool Running = true; + public static string CreateSft(string lua) + { + byte[] bytes = Encoding.UTF8.GetBytes(lua); + return Convert.ToBase64String(bytes); + } + public static void RunSft(string sft) { if (Utils.FileExists(sft)) @@ -72,6 +78,7 @@ namespace ShiftOS.Engine.Scripting string b64 = Utils.ReadAllText(sft); byte[] bytes = Convert.FromBase64String(b64); string lua = Encoding.UTF8.GetString(bytes); + CurrentDirectory = sft.Replace(Utils.GetFileInfo(sft).Name, ""); new LuaInterpreter().Execute(lua); } catch @@ -81,6 +88,8 @@ namespace ShiftOS.Engine.Scripting } } + public static string CurrentDirectory { get; private set; } + public LuaInterpreter() { Lua(@"function totable(clrlist) @@ -101,6 +110,7 @@ end"); public void SetupAPIs() { + Lua.currentdir = (string.IsNullOrWhiteSpace(CurrentDirectory)) ? "0:" : CurrentDirectory; Lua.random = new Func((min, max) => { return new Random().Next(min, max); @@ -208,6 +218,7 @@ end"); { if (Utils.FileExists(file)) { + CurrentDirectory = file.Replace(Utils.GetFileInfo(file).Name, ""); Execute(Utils.ReadAllText(file)); } else @@ -248,6 +259,37 @@ end"); } } + [Exposed("sft")] + public class SFTFunctions + { + public string make(string lua) + { + return LuaInterpreter.CreateSft(lua); + } + + public void makefile(string lua, string outpath) + { + Utils.WriteAllText(outpath, make(lua)); + } + + public void run(string inpath) + { + LuaInterpreter.RunSft(inpath); + } + + public string unmake(string sft) + { + if (Utils.FileExists(sft)) + { + string b64 = Utils.ReadAllText(sft); + byte[] bytes = Convert.FromBase64String(b64); + string lua = Encoding.UTF8.GetString(bytes); + return lua; + } + return ""; + } + } + [Exposed("net")] public class NetFunctions {