public int ReadFile(string filename, byte[] buffer, ref uint readBytes, long offset, DokanFileInfo info) { Console.WriteLine("RF: " + filename + ", off" + offset + ", len" + buffer.Length); RAFInMemoryFileSystemObject fso = rafManager.ResolveRAFPathTOFSO(filename); Console.WriteLine("->FSO NULL: " + (fso == null)); if (fso == null) { return(-DokanNet.ERROR_FILE_NOT_FOUND); } else { RAFFileListEntry entry = rafManager.ResolveRAFPathToEntry(fso.GetRAFPath(true)); byte[] content = entry.GetContent(); readBytes = Math.Min((uint)(content.Length - offset), (uint)buffer.Length); Array.Copy(content, offset, buffer, 0, readBytes); Console.WriteLine("-> " + readBytes + " bytes read"); return(0); } //throw new NotImplementedException(); }
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 = rafManager.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); Util.PrepareDirectory(Environment.CurrentDirectory + "/backup/"); File.WriteAllText(fileBackupLoc, "this file should be deleted"); DLog(" Adding " + nodeTags[j].rafPath); string archiveName = nodeTags[j].rafPath.Split("/").First(); rafManager.Archives.Where( (Func <RAFArchive, bool>) delegate(RAFArchive arc) { return(arc.GetID().ToLower() == archiveName); } ).First().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); Util.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 < rafManager.Archives.Count; i++) { rafManager.Archives[i].SaveDirectoryFile(); } Log("Done Packing"); }