Ejemplo n.º 1
0
        public RAFFileListEntry CreateFileEntry(string rafPath, UInt32 offset, UInt32 fileSize, UInt32 nameStringTableIndex)
        {
            RAFFileListEntry result = new RAFFileListEntry(this.raf, rafPath, offset, fileSize, nameStringTableIndex);

            this.GetFileList().AddFileEntry(result);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiates a TextViewer form which displays a string
        /// </summary>
        /// <param name="title">Title of the window</param>
        /// <param name="content">Content displayed</param>
        public TextViewer(RAFFileListEntry fileEntry)
        {
            InitializeComponent();
            this.fileEntry = fileEntry;
            string content = Encoding.ASCII.GetString(fileEntry.GetContent());

            this.Text = defaultTitle = "Text Viewer - " + fileEntry.FileName;
            this.contentTB.Text = content;

            this.Load += delegate(object sender, EventArgs e)
            {
                if (lastSize != Size.Empty) Size = lastSize;
                if (lastLocation != Point.Empty) Location = lastLocation;
            };

            this.FormClosing += new FormClosingEventHandler(TextViewer_FormClosing);
        }
        ///<summary>
        ///Returns a guess of the RAF Path, including the archive id or "undefined"
        ///</summary>
        public string GuessRafPathFromPath(string basePath)
        {
            string[] pathParts = basePath.Replace("\\","/").Split("/");
            RAFFileListEntry matchedEntry = null;
            List<RAFFileListEntry> lastMatches = null;
            bool done = false;

            //Smart search insertion
            for (int i = 1; i < pathParts.Length + 1 && !done; i++)
            {
                string[] searchPathParts = pathParts.SubArray(pathParts.Length - i, i);
                string searchPath = String.Join("/", searchPathParts);
                //Console.WriteLine(searchPath);
                List<RAFFileListEntry> matches = new List<RAFFileListEntry>();
                RAFArchive[] archives = rafManager.Archives.ToArray();
                for (int j = 0; j < archives.Length; j++)
                {
                    List<RAFFileListEntry> newmatches = archives[j].GetDirectoryFile().GetFileList().SearchFileEntries(searchPath);
                    matches.AddRange(newmatches);
                }
                if (matches.Count == 1)
                {
                    matchedEntry = matches[0];
                    done = true;
                }
                else if (matches.Count == 0)
                {
                    done = true;
                }
                else
                {
                    lastMatches = matches;
                }
            }
            if (matchedEntry == null)
            {
                if (lastMatches != null && lastMatches.Count > 0)
                {
                    //Resolve ambiguity
                    FileEntryAmbiguityResolver ambiguityResolver = new FileEntryAmbiguityResolver(lastMatches.ToArray(), "Notes: "+basePath);
                    ambiguityResolver.ShowDialog();
                    RAFFileListEntry resolvedItem = (RAFFileListEntry)ambiguityResolver.SelectedItem;
                    if (resolvedItem != null)
                    {
                        matchedEntry = resolvedItem;
                    }
                }
                else if (permitExperimentalFileAddingCB.Checked)//advanced user
                {
                    //We'll use the file browser to select where we want to save...
                    string rafPath = PickRafPath(false) + "/";
                    RAFArchive archive = rafManager.Archives.Where(
                        (Func<RAFArchive, bool>)delegate(RAFArchive arc)
                        {
                            return arc.GetID().ToLower() == rafPath.Replace("\\", "/").Split("/").First().ToLower();
                        }
                    ).First();
                    rafPath = rafPath.Substring(rafPath.IndexOf("/") + 1); //remove the archive name now...
                    if (rafPath.Length != 0)
                    {
                        Console.WriteLine("FRP: " + "len!= 0");
                        if (rafPath[rafPath.Length - 1] == '/')
                        {
                            Console.WriteLine("FRP: " + rafPath);
                            rafPath = rafPath.Substring(0, rafPath.Length - 1);//remove the trailing /, since we add it later
                        }
                    }
                    Console.WriteLine("FRP: " + rafPath);
                    if (rafPath == "")
                        matchedEntry = new RAFFileListEntry(archive, pathParts.Last(), UInt32.MaxValue, (UInt32)new FileInfo(basePath).Length, UInt32.MaxValue);
                    else
                        matchedEntry = new RAFFileListEntry(archive, rafPath + "/" + pathParts.Last(), UInt32.MaxValue, (UInt32)new FileInfo(basePath).Length, UInt32.MaxValue);

                    //Add the tree node to the raf viewer
                }
            }
            if (matchedEntry != null) //If it is resolved
            {
                /*
                node.Tag = new ChangesViewEntry(filePath, matchedEntry, node);
                node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath));
                node.Nodes.Add(new TristateTreeNode("RAF Path: " + matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName));
                node.Nodes[0].HasCheckBox = false;
                node.Nodes[1].HasCheckBox = false;
                 */
                //Don't add it
                return matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName;
                //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Value = matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName;
                //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Tag = matchedEntry;
            }
            else
            {
                /*
                node.Tag = new ChangesViewEntry(filePath, null, node);
                node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath));
                node.Nodes.Add(new TristateTreeNode("RAF Path: " + "undefined"));
                node.Nodes[0].HasCheckBox = false;
                node.Nodes[1].HasCheckBox = false;
                Log("Unable to link file '" + filePath + "' to RAF Archive.  Please manually select RAF path");
                 */
                //Log("Unable to resolve local path to RAF path: " + basePath);
                return "undefined";
            }
        }
Ejemplo n.º 4
0
 public ChangesViewEntry(string localPath, RAFFileListEntry entry, TristateTreeNode node)
 {
     this.localPath = localPath;
     this.entry = entry;
     this.node = node;
 }
Ejemplo n.º 5
0
 public ChangesViewEntry(string localPath, RAFFileListEntry entry, TristateTreeNode node)
 {
     this.localPath = localPath;
     this.entry     = entry;
     this.node      = node;
 }
 /// <summary>
 /// Presents an editable text file viewer to the user
 /// </summary>
 void ShowEditableTextFile(RAFFileListEntry entry)
 {
     new TextViewer(entry).Show();
 }
Ejemplo n.º 7
0
 public void DeleteFileEntry(RAFFileListEntry entry)
 {
     this.GetFileList().DeleteFileEntry(entry);
 }
Ejemplo n.º 8
0
 public RAFFileListEntry CreateFileEntry(string rafPath, UInt32 offset, UInt32 fileSize, UInt32 nameStringTableIndex)
 {
     RAFFileListEntry result = new RAFFileListEntry(this.raf, rafPath, offset, fileSize, nameStringTableIndex);
     this.GetFileList().AddFileEntry(result);
     return result;
 }
Ejemplo n.º 9
0
 public void DeleteFileEntry(RAFFileListEntry entry)
 {
     this.fileEntries.Remove(entry);
 }
Ejemplo n.º 10
0
 public void AddFileEntry(RAFFileListEntry entry)
 {
     this.fileEntries.Add(entry);
 }
Ejemplo n.º 11
0
 public void DeleteFileEntry(RAFFileListEntry entry)
 {
     this.GetFileList().DeleteFileEntry(entry);
 }
Ejemplo n.º 12
0
        //Inserts a file into the raf archive...
        public bool InsertFile(string fileName, byte[] content, TextWriter ostream)
        {
            if (ostream == null)
            {
                ostream = new StreamWriter(Stream.Null);
            }

            ostream.WriteLine("    Insert: " + fileName);
            ostream.WriteLine("        To: " + GetID());

            RAFFileListEntry fileentry = this.GetDirectoryFile().GetFileList().GetFileEntry(fileName);

            if (fileentry == null)
            {
                //Define a new entry
                ostream.WriteLine("# Create new entry in RAF Archive, using experimental hash calculations");
                ostream.WriteLine("    Get DAT File Stream");
                FileStream datFileStream = GetDataFileContentStream();
                //navigate to the end of it, add the file.
                datFileStream.Seek(0, SeekOrigin.End);
                UInt32 offset = (UInt32)datFileStream.Length;

                byte[] finalContent;
                if (nocompress.Contains(fileName))
                {
                    finalContent = content;
                }
                else
                {
                    ostream.WriteLine("    Begin compression of content");
                    MemoryStream       mStream = new MemoryStream();
                    zlib.ZOutputStream oStream = new zlib.ZOutputStream(mStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION); //using default compression level
                    oStream.Write(content, 0, content.Length);
                    oStream.finish();
                    finalContent = mStream.ToArray();
                }

                ostream.WriteLine("    Begin DAT Write");
                datFileStream.Write(finalContent, 0, finalContent.Length);

                ostream.WriteLine("    Add file entry to in memory directory...");
                UInt32 strTableIndex = directoryFile.GetStringTable().Add(fileName);
                directoryFile.CreateFileEntry(fileName, offset, (UInt32)finalContent.Length, strTableIndex);
                //directoryFile.Save();
                //datFileStream.Close();
                ostream.WriteLine("    Done.");
                return(true);
            }
            else
            {
                //store the old offsets just in case we need to perform a restore.
                //This actually isn't necessary currently, since the raf directory file is saved
                //After packing.
                UInt32 oldOffset = (UInt32)fileentry.FileOffset;
                UInt32 oldSize   = (UInt32)fileentry.FileSize;
                ostream.WriteLine("Old Offset: " + oldOffset + "; Old Size: " + oldSize);

                ostream.WriteLine("Begin modify game files...  This may take a while");
                try
                {
                    ostream.WriteLine("    Get File Stream");
                    FileStream datFileStream = GetDataFileContentStream();
                    //navigate to the end of it, add the file.
                    datFileStream.Seek(0, SeekOrigin.End);
                    UInt32 offset = (UInt32)datFileStream.Length;

                    byte[] finalContent;
                    if (nocompress.Contains(fileName))
                    {
                        finalContent = content;
                    }
                    else
                    {
                        ostream.WriteLine("    Begin compression of content");
                        MemoryStream       mStream = new MemoryStream();
                        zlib.ZOutputStream oStream = new zlib.ZOutputStream(mStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION); //using default compression level
                        oStream.Write(content, 0, content.Length);
                        oStream.finish();
                        finalContent = mStream.ToArray();
                    }

                    ostream.WriteLine("    Begin DAT Write");
                    datFileStream.Write(finalContent, 0, finalContent.Length);

                    ostream.WriteLine("    Begin FileEntry Write");
                    fileentry.FileOffset = offset;
                    fileentry.FileSize   = (UInt32)finalContent.Length;
                    //directoryFile.Save();

                    //datFileStream.Close();
                    ostream.WriteLine("    Done.");
                    return(true);
                }
                catch (Exception e)
                {
                    ostream.WriteLine("!! An error occurred in inserting a file.");
                    ostream.WriteLine("!! Note that the content of the raf archive has been added to");
                    ostream.WriteLine("!! But the directory file that points the game to the data in the content file");
                    ostream.WriteLine("!! Has not been modified.  In other words, if the game read the RAF archive now");
                    ostream.WriteLine("!! It wouldn't see a difference.");
                    ostream.WriteLine("!! However, the RAF archive is a bit bigger than before.");
                    ostream.WriteLine(e.ToString());

                    fileentry.FileOffset = oldOffset;
                    fileentry.FileSize   = oldSize;
                    //directoryFile.GetContent();
                    return(false);
                }
            }
        }
Ejemplo n.º 13
0
 public void DeleteFileEntry(RAFFileListEntry entry)
 {
     this.fileEntries.Remove(entry);
 }
Ejemplo n.º 14
0
 public void AddFileEntry(RAFFileListEntry entry)
 {
     this.fileEntries.Add(entry);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Event handler for when a DragDrop operation completed on top of the changesview
        /// </summary>
        void changesView_DragDrop(object sender, DragEventArgs e)
        {
            //Check if we have a file/list of filfes
            if (e.Data is DataObject && ((DataObject)e.Data).ContainsFileDropList())
            {

                DataObject dataObject = (DataObject)e.Data;
                StringCollection dropList = dataObject.GetFileDropList();

                List<string> filePaths = new List<string>();
                foreach (string path in dropList)
                {
                    if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
                        filePaths.AddRange(Util.GetAllChildFiles(path));//Directory.GetFiles(rootPath, "**", SearchOption.AllDirectories);
                    else
                        filePaths.Add(path);
                }
                if (filePaths.Count == 1) //test if its a project
                {
                    if (filePaths[0].ToLower().EndsWith(".rmproj"))
                    {
                        if (HasProjectChanged)
                            PromptSaveToClose();

                        //Load the project
                        LoadProject(filePaths[0]);
                        return;
                    }
                }

                //Iterate through all files
                StringQueryDialog nameQueryDialog = new StringQueryDialog("Type File Group Name:");
                nameQueryDialog.ShowDialog();
                if (nameQueryDialog.Value.Trim() == "")
                {
                    Log("Invalid name '{0}' given.  ".F(nameQueryDialog.Value.Trim()));
                    return;
                }
                TristateTreeNode topNode = new TristateTreeNode(nameQueryDialog.Value);
                topNode.HasCheckBox = true;
                for (int z = 0; z < filePaths.Count; z++)
                {
                    SetTaskbarProgress(z * 100 / filePaths.Count);
                    string filePath = filePaths[z].Replace("\\", "/");
                    //Console.WriteLine(filePath);

                    //ADD TO VIEW HERE
                    TristateTreeNode node;
                    topNode.Nodes.Add(
                        node = new TristateTreeNode(filePath)
                    );
                    node.HasCheckBox = true;

                    //changesView.Rows[rowIndex].Cells[CN_LOCALPATH].Style.Alignment = DataGridViewContentAlignment.MiddleRight;

                    //Split the path into pieces split by FSOs...  Search the RAF archives and see if we can link it to the raf path

                    string[] pathParts = filePath.Split("/");
                    RAFFileListEntry matchedEntry = null;
                    List<RAFFileListEntry> lastMatches = null;
                    bool done = false;

                    //Smart search insertion
                    for (int i = 1; i < pathParts.Length + 1 && !done; i++)
                    {
                        string[] searchPathParts = pathParts.SubArray(pathParts.Length - i, i);
                        string searchPath = String.Join("/", searchPathParts);
                        //Console.WriteLine(searchPath);
                        List<RAFFileListEntry> matches = new List<RAFFileListEntry>();
                        RAFArchive[] archives = rafArchives.Values.ToArray();
                        for (int j = 0; j < archives.Length; j++)
                        {
                            List<RAFFileListEntry> newmatches = archives[j].GetDirectoryFile().GetFileList().SearchFileEntries(searchPath);
                            matches.AddRange(newmatches);
                        }
                        if (matches.Count == 1)
                        {
                            matchedEntry = matches[0];
                            done = true;
                        }
                        else if (matches.Count == 0)
                        {
                            done = true;
                        }
                        else
                        {
                            lastMatches = matches;
                        }
                    }
                    if (matchedEntry == null)
                    {
                        if (lastMatches != null && lastMatches.Count > 0)
                        {
                            //Resolve ambiguity
                            FileEntryAmbiguityResolver ambiguityResolver = new FileEntryAmbiguityResolver(lastMatches.ToArray(), "!");
                            ambiguityResolver.ShowDialog();
                            RAFFileListEntry resolvedItem = (RAFFileListEntry)ambiguityResolver.SelectedItem;
                            if (resolvedItem != null)
                            {
                                matchedEntry = resolvedItem;
                            }
                        }
                        else if (advancedUser)
                        {
                            //We'll use the file browser to select where we want to save...
                            string rafPath = PickRafPath(false) + "/";
                            RAFArchive archive = rafArchives[rafPath.Replace("\\", "/").Split("/").First()];
                            rafPath = rafPath.Substring(rafPath.IndexOf("/") + 1); //remove the archive name now...
                            if (rafPath.Length != 0)
                            {
                                Console.WriteLine("FRP: " + "len!= 0");
                                if (rafPath[rafPath.Length - 1] == '/') 
                                {
                                    Console.WriteLine("FRP: " + rafPath);
                                    rafPath = rafPath.Substring(0, rafPath.Length - 1);//remove the trailing /, since we add it later
                                }
                            }
                            Console.WriteLine("FRP: " + rafPath);
                            if (rafPath == "")
                                matchedEntry = new RAFFileListEntry(archive, pathParts.Last(), UInt32.MaxValue, (UInt32)new FileInfo(filePath).Length, UInt32.MaxValue);
                            else
                                matchedEntry = new RAFFileListEntry(archive, rafPath + "/" + pathParts.Last(), UInt32.MaxValue, (UInt32)new FileInfo(filePath).Length, UInt32.MaxValue);
                            
                            //Add the tree node to the raf viewer
                        }
                    }
                    if (matchedEntry != null) //If it's still not resolved
                    {
                        node.Tag = new ChangesViewEntry(filePath, matchedEntry, node);
                        node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath));
                        node.Nodes.Add(new TristateTreeNode("RAF Path: " + matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName));
                        node.Nodes[0].HasCheckBox = false;
                        node.Nodes[1].HasCheckBox = false;
                        //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Value = matchedEntry.RAFArchive.GetID() + "/" + matchedEntry.FileName;
                        //changesView.Rows[rowIndex].Cells[CN_RAFPATH].Tag = matchedEntry;
                    }
                    else
                    {
                        node.Tag = new ChangesViewEntry(filePath, null, node);
                        node.Nodes.Add(new TristateTreeNode("Local Path: " + filePath));
                        node.Nodes.Add(new TristateTreeNode("RAF Path: " + "undefined"));
                        node.Nodes[0].HasCheckBox = false;
                        node.Nodes[1].HasCheckBox = false;
                        Log("Unable to link file '" + filePath + "' to RAF Archive.  Please manually select RAF path");
                    }
                }
                changesView.Nodes.Add(topNode);
                changesView.Invalidate();
                SetTaskbarProgress(0);
            }
        }