SpringModEdit.Mod.Save C# (CSharp) Method

Save() public method

public Save ( string path ) : void
path string
return void
        public void Save(string path)
        {
            try {
                Directory.CreateDirectory(path);
            } catch {}
            ;
            try {
                Directory.CreateDirectory(path + "/units");
            } catch {}
            ;
            foreach (var s in Directory.GetFiles(path + "/units", "*.lua")) {
                try {
                    File.Delete(s);
                } catch {}
                ;
            }

            foreach (DictionaryEntry de in Units) {
                string key = de.Key.ToString().ToLower();
                string s = String.Format("unitDef = {0}\r\n\r\nreturn lowerkeys({{ {1} = unitDef }})\r\n", TableProxy.Export((LuaTable)de.Value,0), key);
                File.WriteAllText(path + "/units/" + key + ".lua", s);
            }
        }

Usage Example

Example #1
0
 private void miSave_Click(object sender, EventArgs e)
 {
     try {
         mod.Save(mod.Folder);
         MessageBox.Show("Mod saved", "Mod saving", MessageBoxButtons.OK, MessageBoxIcon.Information);
     } catch (Exception ex) {
         MessageBox.Show(ex.ToString(), "Error occurred while saving", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }