SFT making utilities

This commit is contained in:
Michael 2017-02-19 20:19:00 -05:00
parent 55c1fbeaa2
commit 994f6b991a
4 changed files with 108 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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!");
}
});
}
}

View file

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -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<int, int, int>((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
{