private bool RenameProgram(Program program, int index, string name) { // Check that we don't override an existing file foreach (Program p in programs) { if ((p != program && p.name == name) || name == "") { PromptSystem.Instance.PromptInvalidProgramName(name); return(false); } } // Remove old file File.Delete(ProgramDirectory.ProgramPath(program.name)); // Update back end programs.RemoveAt(index); program.name = name; int newIndex = programs.InsertAlphabetically(program); // Update front end transform.GetChild(index).SetSiblingIndex(newIndex); // Create new file SaveProgram(program); return(true); }
private void SaveProgram(Program program) { string programText = Disassembler.Disassemble(program); StreamWriter programFile = File.CreateText(ProgramDirectory.ProgramPath(program.name)); programFile.Write(programText); programFile.Close(); }
public static string GetPath(ProgramDirectory dir) { string ret = string.Empty, main = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "/GingerBread"; switch (dir) { case ProgramDirectory.Main: ret = main; break; case ProgramDirectory.Sounds: ret = main + "/Sound Files"; break; } return(ret); }
protected override void RenameItem(Program program, string name) { string fromPath = ProgramDirectory.ProgramPath(program.name); string toPath = ProgramDirectory.ProgramPath(name); #if UNITY_EDITOR && !BUILD_MODE AssetDatabase.RenameAsset(fromPath, name); #else File.Move(fromPath, toPath); #endif program.name = name; }
public Program AssembleProgram() { string programText = null; if (builtInProgram != null) { programText = builtInProgram.text; } else if (customProgramName != null) { try { programText = File.ReadAllText(ProgramDirectory.ProgramPath(customProgramName)); } catch { Debug.LogWarning("Error opening program " + customProgramName + ". Using fallback program."); } } if (programText == null) { Debug.LogWarning("No program provided. Using fallback program."); PromptSystem.Instance.PromptOtherAction("No program provided. Using fallback program."); return(FALLBACK_PROGRAM); } else { Program program = Assembler.Assemble(customProgramName, programText); if (program == null) { Debug.LogWarning("Assembly failed. Using fallback program."); return(FALLBACK_PROGRAM); } else { return(program); } } }
protected override void DeleteItem(Program program) { File.Delete(ProgramDirectory.ProgramPath(program.name)); codeList.Program = null; }