/// <summary> /// Creates a new mod entry for the right panel. /// </summary> private ModEntry CreateAndAppendModEntry(string modName, string modCreator, string modURL, TreeNode[] content) { ModEntry result = new ModEntry(modName, modCreator, modURL, content); modEntriesPanel.Controls.Add(result); modEntries.Add(result); result.Resize += delegate(object sender, EventArgs e) { if (result.Height == 1) { //Delete it modEntries.Remove(result); modEntriesPanel.Controls.Remove(result); } ManageModEntriesLayout(); }; ManageModEntriesLayout(); return result; }
private void OpenProject(string filePath) { ResetProject(); string[] lines = File.ReadAllLines(filePath); if (lines[0] != "RMPROJ1.4") { Log("Invalid File Format. Expected RMPROJ1.4... Perhaps you're trying to use a project file from an older version?"); return; } projectNameLabel.Text = lines[1]; ModEntry current = null; for (int i = 2; i < lines.Length; i++) { try { string line = lines[i]; string[] lineParts = line.QASS(' '); switch (lineParts[0].Trim().ToUpper()) { case ">": { current = CreateAndAppendModEntry(lineParts[1], lineParts[2], lineParts[3], new TreeNode[] { }); break; } case "IMAGEFILE": { if (lineParts.Length == 1 || lineParts[1].Trim() == "") { current.IconImage = Properties.Resources.NoIcon; current.IconImage.Tag = " "; } else { current.IconImage = Bitmap.FromFile(lineParts[1]); current.IconImage.Tag = lineParts[1]; } break; } case "SCRIPTFILE": { current.Script = new RMPropInterpreter(lineParts[1], this); break; } case "OPTION": { current.Script.SetOption(lineParts[1], lineParts[2]); break; } case "CHECKED": { current.IsChecked = lineParts[1] == "1"; break; } case "<": break; //Really don't do anything. default: { if (line != "") { current.AddFile(lineParts[0], lineParts[1]); } break; } } } catch { if (current != null) { Log("Error loading Entry named '" + current.ModName + "'... It will not be loaded."); try { current.Delete(); }catch {} } } } }
/// <summary> /// Dragdrop - process file drops /// Add them if appropriate /// </summary> void modEntriesPanel_DragDrop(object sender, DragEventArgs e) { if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList()) { StringCollection filePaths = ((DataObject)e.Data).GetFileDropList(); //Get all files that were dropped in, by searching subdirectories too List <String> resultFiles = new List <string>(); foreach (string path in filePaths) { if ((new FileInfo(path).Attributes & FileAttributes.Directory) != 0) { resultFiles.AddRange(Util.GetAllChildFiles(path)); } else { resultFiles.Add(path); } } List <TreeNode> resultantNodes = new List <TreeNode>(); string iconPath = null; //If there is a script it overrides default action RMPropInterpreter script = null; foreach (string path in resultFiles) { string rafPath = GuessRafPathFromPath(path); if (rafPath != "undefined") { TreeNode node = new TreeNode(path.Replace("\\", "/").Split("/").Last()); node.Nodes.Add("Local Path: " + path); node.Nodes.Add("RAF Path: " + rafPath); node.Tag = new ModEntryNodeTag() { localPath = path, rafPath = rafPath }; resultantNodes.Add(node); } else { //We usually skip it if it is undefined. We have some special cases if (path.EndsWith("rafmanagericon.jpg")) { iconPath = path; } else if (path.EndsWith("rafmanagerscript")) { try { script = new RMPropInterpreter( path, this ); }catch (Exception ex) { Console.WriteLine(ex); } } else { Log("Unable to resolve local path to RAF path: " + path); } } } ModEntry modEntry = null; if (script == null) { //resultFiles has all our files. StringQueryDialog sqd = new StringQueryDialog("What is the name of the mod that you are dropping into RAF Manager?"); sqd.ShowDialog(); if (sqd.Value == "") { return; } modEntry = CreateAndAppendModEntry(sqd.Value, "-", "-", resultantNodes.ToArray()); } else { modEntry = CreateAndAppendModEntry(script.Name, script.Creator, script.WebsiteURL, resultantNodes.ToArray()); modEntry.Script = script; } try { if (iconPath != null) { modEntry.IconImage = Bitmap.FromFile(iconPath); modEntry.IconImage.Tag = iconPath; } } catch { } } }
private void packToolStripMenuItem_Click(object sender, EventArgs e) { Console.Clear(); Log(""); Log("Begin Packing"); for (int i = 0; i < modEntries.Count; i++) { ModEntry entry = modEntries[i]; if (entry.Script == null || (entry.IsChecked?!entry.Script.HasPackTimeOverride:!entry.Script.HasRestoreTimeOverride)) { DLog("->Pack/Restore Nonscripted Entry: " + entry.ModName); ModEntryNodeTag[] nodeTags = entry.GetModEntryTags(); for (int j = 0; j < nodeTags.Length; j++) { RAFFileListEntry rafEntry = ResolveRAFPathToEntry(nodeTags[j].rafPath); string fileBackupLoc = Environment.CurrentDirectory + "/backup/" + nodeTags[j].rafPath.Replace("/", "_"); if (entry.IsChecked) { if (rafEntry == null && permitExperimentalFileAddingCB.Checked) { //File doesn't exist in archive //Our backup = "this file should be deleted" DLog(" Marking for restore op deletion: " + nodeTags[j].rafPath); PrepareDirectory(Environment.CurrentDirectory + "/backup/"); File.WriteAllText(fileBackupLoc, "this file should be deleted"); DLog(" Adding " + nodeTags[j].rafPath); string archiveName = nodeTags[j].rafPath.Split("/").First(); rafArchives[archiveName].InsertFile( nodeTags[j].rafPath.Replace(archiveName + "/", ""), File.ReadAllBytes(nodeTags[j].localPath), new LogTextWriter( (Func <string, object>) delegate(string s) { if (updateDuringLongOperationsCB.Checked) { DLog(s); } return(null); } ) ); } else { //File does exist in archive, do backup if not done already if (!File.Exists(fileBackupLoc)) { DLog(" Backing up " + nodeTags[j].rafPath); PrepareDirectory(Environment.CurrentDirectory + "/backup/"); File.WriteAllBytes(fileBackupLoc, rafEntry.GetContent()); } DLog(" Inserting " + nodeTags[j].rafPath); rafEntry.RAFArchive.InsertFile( rafEntry.FileName, File.ReadAllBytes(nodeTags[j].localPath), new LogTextWriter( (Func <string, object>) delegate(string s) { if (updateDuringLongOperationsCB.Checked) { DLog(s); } return(null); } ) ); } } else if (File.Exists(fileBackupLoc)) { if (permitExperimentalFileAddingCB.Checked && File.ReadAllText(fileBackupLoc) == "this file should be deleted") { DLog(" Deleting " + nodeTags[j].rafPath); rafEntry.RAFArchive.GetDirectoryFile().DeleteFileEntry(rafEntry); } else { DLog(" Restoring " + nodeTags[j].rafPath); rafEntry.RAFArchive.InsertFile( rafEntry.FileName, File.ReadAllBytes(fileBackupLoc), null ); } } } DLog(" Done"); } else { if (entry.IsChecked) { DLog("->Running RAF Manager Script : Packtime Command"); entry.Script.RunPacktimeCommand(); DLog(" Done"); } else { DLog("->Running RAF Manager Script : Restoretime Command"); entry.Script.RunRestoreTimeCommand(); DLog(" Done"); } } } DLog("Saving Archive Directory Files (*.raf)"); for (int i = 0; i < rafArchives.Count; i++) { new List <RAFArchive>(rafArchives.Values)[i].SaveDirectoryFile(); } Log("Done Packing"); }