diff --git a/SharpGMad/Main.cs b/SharpGMad/Main.cs index 4720aa7..9a6f8d3 100644 --- a/SharpGMad/Main.cs +++ b/SharpGMad/Main.cs @@ -72,9 +72,10 @@ private void LoadAddon(string path) if (!AddonHandle.CanWrite) { - DialogResult openReadOnly = MessageBox.Show("This addon is locked by another process.\n\n" + - "Would you like to open it in read-only mode?", "Addon locked", - MessageBoxButtons.YesNo, MessageBoxIcon.Question); + DialogResult openReadOnly = MessageBox.Show("This addon is locked by another process, " + + "and cannot be written.\n\n" + + "Would you like to open it in read-only mode?\nAll modification options will be disabled.", + "Addon locked", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (openReadOnly != DialogResult.Yes) { @@ -120,7 +121,7 @@ private void LoadAddon(string path) UpdateMetadataPanel(); UpdateFileList(); UpdateModified(); - UpdateStatus("Loaded the addon"); + UpdateStatus("Loaded the addon" + (AddonHandle.CanWrite ? null : " (read-only mode)")); tsbAddFile.Enabled = AddonHandle.CanWrite; tsbUpdateMetadata.Enabled = AddonHandle.CanWrite; @@ -143,7 +144,7 @@ private void UpdateModified() } else { - this.Text = Path.GetFileName(AddonHandle.AddonPath) + (AddonHandle.CanWrite ? null : " (readonly)") + + this.Text = Path.GetFileName(AddonHandle.AddonPath) + (AddonHandle.CanWrite ? null : " (read-only)") + (AddonHandle.Modified ? "*" : null) + " - SharpGMad"; tsbSaveAddon.Enabled = AddonHandle.CanWrite && AddonHandle.Modified; diff --git a/SharpGMad/Properties/AssemblyInfo.cs b/SharpGMad/Properties/AssemblyInfo.cs index 4e976e6..9de4e1a 100644 --- a/SharpGMad/Properties/AssemblyInfo.cs +++ b/SharpGMad/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1")] -[assembly: AssemblyFileVersion("1.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.1.1")] +[assembly: AssemblyFileVersion("1.1.1")] \ No newline at end of file diff --git a/SharpGMad/RealtimeCommandline.cs b/SharpGMad/RealtimeCommandline.cs index 4fac8f9..28aaa23 100644 --- a/SharpGMad/RealtimeCommandline.cs +++ b/SharpGMad/RealtimeCommandline.cs @@ -48,7 +48,7 @@ public static int Main(string[] args) } else if (AddonHandle is RealtimeAddon) { - Console.Write(Path.GetFileName(AddonHandle.AddonPath) + + Console.Write(Path.GetFileName(AddonHandle.AddonPath) + (AddonHandle.CanWrite ? null : " (read-only)") + (AddonHandle.Modified ? "*" : null) + (AddonHandle.Pullable ? "#" : null) + "> "); } @@ -217,6 +217,14 @@ public static int Main(string[] args) break; case "export": + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Addon read-only. Use `extract` to unpack files from it."); + Console.ResetColor(); + break; + } + string exportPath = String.Empty; try { @@ -253,6 +261,14 @@ public static int Main(string[] args) break; case "pull": + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + break; + } + try { PullFile(command[1]); @@ -330,6 +346,14 @@ public static int Main(string[] args) break; case "set": + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + break; + } + string Sparameter; try { @@ -560,20 +584,32 @@ public static int Main(string[] args) if (AddonHandle is RealtimeAddon) { - Console.WriteLine("add Adds to the archive"); - Console.WriteLine("addfolder Adds all files from to the archive"); + if (AddonHandle.CanWrite) + { + Console.WriteLine("add Adds to the archive"); + Console.WriteLine("addfolder Adds all files from to the archive"); + } Console.WriteLine("list Lists the files in the memory"); - Console.WriteLine("remove Removes from the archive"); + if (AddonHandle.CanWrite) + { + Console.WriteLine("remove Removes from the archive"); + } Console.WriteLine("extract [path] Extract (to [path] if specified)"); Console.WriteLine("mget [f2...] Extract all specified files to "); - Console.WriteLine("export View the list of exported files"); - Console.WriteLine("export [path] Export for editing (to [path] if specified)"); - Console.WriteLine("pull Pull changes from all exported files"); - Console.WriteLine("pull Pull the changes of exported "); - Console.WriteLine("drop Drops the export for "); + if (AddonHandle.CanWrite) + { + Console.WriteLine("export View the list of exported files"); + Console.WriteLine("export [path] Export for editing (to [path] if specified)"); + Console.WriteLine("pull Pull changes from all exported files"); + Console.WriteLine("pull Pull the changes of exported "); + Console.WriteLine("drop Drops the export for "); + } Console.WriteLine("get Prints the value of metadata "); - Console.WriteLine("set [value] Sets metadata to the specified [value]"); - Console.WriteLine("push Writes the changes to the disk"); + if (AddonHandle.CanWrite) + { + Console.WriteLine("set [value] Sets metadata to the specified [value]"); + Console.WriteLine("push Writes the changes to the disk"); + } Console.WriteLine("shellexec Execute the specified file"); Console.WriteLine("close Closes the addon (dropping all changes)"); Console.WriteLine("path Prints the full path of the current addon."); @@ -629,9 +665,13 @@ public static int Main(string[] args) return 0; //break; default: - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Unknown operation."); - Console.ResetColor(); + if (!String.IsNullOrWhiteSpace(command[0])) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Unknown operation."); + Console.ResetColor(); + } + break; } } @@ -694,6 +734,14 @@ static void NewAddon(string filename) /// Optional. The new title the addon should have. private static void SetTitle(string title = null) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + if (title == String.Empty || title == null) { Console.ForegroundColor = ConsoleColor.Yellow; @@ -712,6 +760,14 @@ private static void SetTitle(string title = null) /// Optional. The new description the addon should have. private static void SetDescription(string description = null) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + if (description == String.Empty || description == null) { Console.ForegroundColor = ConsoleColor.Yellow; @@ -730,6 +786,14 @@ private static void SetDescription(string description = null) /// Optional. The new author the addon should have. private static void SetAuthor(string author = null) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + if (author == String.Empty || author == null) { Console.ForegroundColor = ConsoleColor.Yellow; @@ -750,6 +814,14 @@ private static void SetAuthor(string author = null) /// Optional. The new type the addon should have. private static void SetType(string type = null) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + if (type == String.Empty || type == null) { while (!Tags.TypeExists(type)) @@ -790,6 +862,14 @@ private static void SetType(string type = null) /// Optional. The new tags the addon should have. private static void SetTags(string[] tagsInput = null) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + List tags = new List(2); if (tagsInput == null || tagsInput.Length == 0 || tagsInput[0] == String.Empty) { @@ -926,6 +1006,13 @@ private static void LoadAddon(string filename) { Console.WriteLine("\t" + f.Path + " [" + ((int)f.Size).HumanReadableSize() + "]"); } + + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("File can not be written. Addon opened read-only."); + Console.ResetColor(); + } } /// @@ -942,6 +1029,14 @@ private static void AddFile(string filename) return; } + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + Console.WriteLine(filename + " as "); Console.WriteLine("\t" + Whitelist.GetMatchingString(filename)); @@ -993,6 +1088,14 @@ private static void AddFile(string filename) /// The folder containing the files to be added. private static void AddFolder(string folder) { + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + if (folder == String.Empty) { folder = Directory.GetCurrentDirectory(); @@ -1041,6 +1144,14 @@ private static void RemoveFile(string filename) return; } + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + try { AddonHandle.RemoveFile(filename); @@ -1119,6 +1230,14 @@ private static void ExportFile(string filename, string exportPath = null) return; } + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + try { AddonHandle.ExportFile(filename, exportPath); @@ -1228,6 +1347,14 @@ private static void PullFile(string filename) return; } + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + try { AddonHandle.Pull(filename); @@ -1264,6 +1391,14 @@ private static void Push() return; } + if (!AddonHandle.CanWrite) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Cannot modify a read-only addon."); + Console.ResetColor(); + return; + } + foreach (ContentFile f in AddonHandle.OpenAddon.Files) { Console.WriteLine("File index: " + f.Path.TrimStart('/') + " [CRC: " + f.CRC + "] [Size:" + ((int)f.Size).HumanReadableSize() + "]");