void bw_AnalyzeArchiveWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Console.WriteLine("Analyzing - doing work");
            BackgroundWorker bw = (BackgroundWorker)sender;

            RAFArchive[] archives = (RAFArchive[])e.Argument;

            TimeSpan updateInterval = new TimeSpan(0, 0, 0, 0, 100);
            DateTime lastUpdate     = DateTime.Now - updateInterval;

            long bytesWasted = 0;

            Console.WriteLine("Enter for.  Archives count: " + archives.Length);
            for (int i = 0; i < archives.Length; i++)
            {
                RAFArchive archive = archives[i];

                long archiveBytesUsed = 0; //We add to this each time, then find out how many bytes could have been saved.

                List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries();
                Console.WriteLine("Analyzing Archive: " + archive.GetID() + "; " + entries.Count + " entries");
                for (int j = 0; j < entries.Count; j++)
                {
                    //Console.WriteLine("  " + j);
                    //Report progress to main thread
                    if (j % 100 == 0)
                    {
                        bw.ReportProgress(0, new long[] { j, i, bytesWasted });
                        lastUpdate = DateTime.Now;
                    }
                    //Console.WriteLine("  !");
                    archiveBytesUsed += entries[j].FileSize;
                }
                bytesWasted += new FileInfo(archive.RAFFilePath + ".dat").Length - archiveBytesUsed;
                Console.WriteLine("Current Bytes Wasted: " + bytesWasted);
            }
        }
        void bw_MinifyArchiveWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw      = (BackgroundWorker)sender;
            RAFArchive       archive = (RAFArchive)e.Argument;

            Console.WriteLine("Minifying Archive: " + archive.GetID());
            //Create temporary dat file
            Console.WriteLine("-> Creating temporary file");
            string     tempDatFilePath = archive.RAFFilePath + ".dat.temp";
            FileStream datFs           = File.Create(tempDatFilePath);

            Console.WriteLine("-> Begin Writing New Entries");
            List <RAFFileListEntry> entries = archive.GetDirectoryFile().GetFileList().GetFileEntries();

            for (int i = 0; i < entries.Count; i++)
            {
                //Report progress to main thread
                if ((i % 100) == 0)
                {
                    bw.ReportProgress((int)(i * 100 / entries.Count), entries[i].FileName);
                }

                byte[] rawContent = entries[i].GetRawContent();
                datFs.Write(rawContent, 0, rawContent.Length);
            }
            Console.WriteLine("    ->Done");
            Console.WriteLine("-> Delete old Archive File... (Closing File Stream)");
            archive.GetDataFileContentStream().Close(); //First we close the old .dat file stream, so we can replace the unowned file
            Console.WriteLine("   Stream Closed... Now deleting old DAT file");
            File.Delete(archive.RAFFilePath + ".dat");
            Console.WriteLine("   Move Replacement DAT File...");
            File.Move(tempDatFilePath, archive.RAFFilePath + ".dat");

            Console.WriteLine("-> Generate new Archive Directory File (*.raf).");
            archive.SaveDirectoryFile();
            Console.WriteLine("-> Done");
        }
예제 #3
0
        void MainForm_Load(object sender, EventArgs e)
        {
            MainWindowLoading loader = new MainWindowLoading();

            loader.Show();

            loader.Log("Begin Check For Updates");
            CheckForUpdates();

            loader.Log("Find Archives Folder");
            SetArchivesRoot();

            loader.Log("Begin Loading RAF Archives");
            consoleLogTB.Text = "www.ItzWarty.com Riot Archive File Packer/Unpacker " + ApplicationInformation.BuildTime;

            rafContentView.TreeViewNodeSorter = new RAFFSOTreeNodeSorter();

            //Enumerate RAF files
            string[] archivePaths = Directory.GetDirectories(archivesRoot);
            #region load_raf_archives
            for (int i = 0; i < archivePaths.Length; i++)
            {
                string archiveName = archivePaths[i].Replace(archivesRoot, "").Replace("/", "");

                loader.Log("Load Archive - " + archiveName + " [0%]");
                //Title("Loading RAF File - " + archiveName);
                //Log("Loading RAF Archive Folder: " + archiveName);

                RAFArchive raf = null;
                RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName);
                rafContentView.Nodes.Add(archiveRoot);
#if !DEBUG
                try
                {
#endif
                //Load raf file table and add to our list of archives
                rafArchives.Add(archiveName,
                                raf = new RAFArchive(
                                    Directory.GetFiles(archivePaths[i], "*.raf")[0]
                                    )
                                );

                //Enumerate entries and add to our tree... in the future this should become sorted
                List <RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries();
                for (int j = 0; j < entries.Count; j++)
                {
                    // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper());
                    if (j % 1000 == 0)
                    {
                        loader.Log("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]");
                    }
                    //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count);

                    RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName);
                }
                //Log(entries.Count.ToString() + " Files");
#if !DEBUG
            }
            catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); }
#endif

                //Add to our tree displayer
                //Title("Sorting nodes... this might take a while");
                if (archiveRoot.Nodes.Count == 0)
                {
                    MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" +
                                    "If not, then another application has not released control over the \r\n" +
                                    "RAF Archives.  RAF Manager will continue to run, but some features \r\n" +
                                    "may not work properly.  Usually a restart of the application will \r\n" +
                                    "fix this.  If you have issues, post a reply on the forum thread, \r\n" +
                                    "whose link can be found under the 'About' menu header.");
                }
            }
            #endregion

            try
            {
                while (loader.Visible) //Hack - i have no idea why this is necessary sometimes... probs race condition somewhere
                {
                    loader.Hide();
                    Application.DoEvents();
                }
            }catch {}

            lock (consoleLogTB)
            {
                Log("");
                Log("A simple guide for using RAF Manager can be located at About->Simple Guide.");
                Log("");

                if (File.Exists(".laststate.rmproj"))
                {
                    Log("Open last state");
                    OpenProject(".laststate.rmproj");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Loads the RAF Archives
        /// </summary>
        public void LoadRAFArchives()
        {
            ArchiveFSOs = new List <RAFInMemoryFileSystemObject>();
            Archives    = new List <RAFArchive>();
            TreeView temp = new TreeView();

            //temp.TreeViewNodeSorter = new RAFFSOTreeNodeSorter();

            string[] archivePaths = Directory.GetDirectories(fileArchivesPath);

            for (int i = 0; i < archivePaths.Length; i++)
            {
                string archiveName = archivePaths[i].Replace(fileArchivesPath, "").Replace("/", "");

                gui.LogToLoader("Load Archive - " + archiveName + " [0%]");
                //Title("Loading RAF File - " + archiveName);
                //Log("Loading RAF Archive Folder: " + archiveName);
                RAFArchive raf = null;
                RAFInMemoryFileSystemObject archiveRoot = new RAFInMemoryFileSystemObject(null, RAFFSOType.ARCHIVE, archiveName);
                temp.Nodes.Add(archiveRoot);
                ArchiveFSOs.Add(archiveRoot);
#if !DEBUG
                try
                {
#endif
                //Load raf file table and add to our list of archives
                Archives.Add(
                    raf = new RAFArchive(
                        Directory.GetFiles(archivePaths[i], "*.raf")[0]
                        )
                    );

                //Enumerate entries and add to our tree... in the future this should become sorted
                List <RAFFileListEntry> entries = raf.GetDirectoryFile().GetFileList().GetFileEntries();
                for (int j = 0; j < entries.Count; j++)
                {
                    // Console.WriteLine(entries[j].StringNameHash.ToString("x").PadLeft(8, '0').ToUpper());
                    if (j % 1000 == 1000)
                    {
                        gui.SetLastLoaderLine("Load Archive - " + archiveName + " [" + (j * 100 / entries.Count) + "%]");
                    }
                    //Title("Loading RAF Files - " + archiveName +" - " + j+"/"+entries.Count);

                    RAFInMemoryFileSystemObject node = archiveRoot.AddToTree(RAFFSOType.FILE, entries[j].FileName);
                }
                //Log(entries.Count.ToString() + " Files");
#if !DEBUG
            }
            catch (Exception exception) { Log("FAILED:\r\n" + exception.Message + "\r\n"); }
#endif

                //Add to our tree displayer
                //Title("Sorting nodes... this might take a while");
                if (archiveRoot.Nodes.Count == 0)
                {
                    MessageBox.Show("Another instance of RAF Manager is likely already open.\r\n" +
                                    "If not, then another application has not released control over the \r\n" +
                                    "RAF Archives.  RAF Manager will continue to run, but some features \r\n" +
                                    "may not work properly.  Usually a restart of the application will \r\n" +
                                    "fix this.  If you have issues, post a reply on the forum thread, \r\n" +
                                    "whose link can be found under the 'About' menu header.");
                }
            }
        }