예제 #1
0
        public DLCEditor(DLCBase dlcBase)
        {
            this.dlcBase = dlcBase;
            listAdd = new SortedDictionary<FileNameHash, add>();
            listReplace = new SortedDictionary<FileNameHash, string>();
            listDelete = new SortedDictionary<FileNameHash, string>();
            listComplete = new SortedDictionary<FileNameHash, action>();
            blockSizeCount = (int)(this.dlcBase.dataOffset - this.dlcBase.blockTableOffset) / 2;

            foreach (sfarFile entry in dlcBase.fileList)
            {
                listComplete.Add(entry.nameHash, action.copy);
            }
            //listComplete.Add(DLCBase.fileListHash, action.copy);
        }
예제 #2
0
 private void scanToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DebugOutput.StartDebugger("Meshplorer2");
     int count = 0;
     timer1.Enabled = false;
     Entries = new List<EntryStruct>();
     bool ScanDLC = false;
     if (MessageBox.Show("Scan DLCs too?", "Meshplorer 2", MessageBoxButtons.YesNo) == DialogResult.Yes)
         ScanDLC = true;
     if (ScanDLC)
     {
         #region DLC Stuff
         string dirDLC = ME3Directory.DLCPath;
         if (!Directory.Exists(dirDLC))
             DebugOutput.PrintLn("No DLC Folder found!");
         else
         {
             string[] subdirs = Directory.GetDirectories(dirDLC);
             string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
             Directory.CreateDirectory(loc + "temp");
             foreach (string DLCpath in subdirs)
                 if (!DLCpath.StartsWith("__") && !DLCpath.StartsWith("DLC_UPD"))
                 {
                     string path = DLCpath + "\\CookedPCConsole\\Default.sfar";
                     DLCBase dlcbase;
                     try
                     {
                         dlcbase = new DLCBase(path);
                         count = 0;
                         pbar1.Maximum = dlcbase.fileList.Count;
                         foreach (sfarFile file in dlcbase.fileList)
                             try
                             {
                                 string filename = Path.GetFileName(file.fileName);
                                 if (Path.GetExtension(filename).ToLower().EndsWith(".pcc"))
                                 {
                                     using (Stream input = File.OpenRead(path), output = File.Create(loc + "temp\\" + filename))
                                     {
                                         AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlcbase.CompressionScheme);
                                     }
                                     FileInfo f = new FileInfo(loc + "temp\\" + filename);
                                     DebugOutput.PrintLn("checking DLC: " + Path.GetFileName(DLCpath) + " File: " + filename + " Size: " + f.Length + " bytes", count % 3 == 0);
                                     PCCObject pcc = new PCCObject(loc + "temp\\" + filename);
                                     for (int i = 0; i < pcc.Exports.Count; i++)
                                         if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                                             pcc.Exports[i].ClassName == "StaticMesh")
                                         {
                                             EntryStruct ent = new EntryStruct();
                                             ent.DLCName = Path.GetFileName(DLCpath);
                                             ent.Filename = filename;
                                             ent.Index = i;
                                             ent.isDLC = true;
                                             ent.ObjectPath = pcc.Exports[i].GetFullPath;
                                             ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                                             Entries.Add(ent);
                                         }
                                     File.Delete(loc + "temp\\" + filename);
                                 }
                                 if (count % 3 == 0)
                                 {
                                     pbar1.Value = count;
                                     Application.DoEvents();
                                 }
                                 count++;
                             }
                             catch (Exception ex)
                             {
                                 DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                             }
                     }
                     catch (Exception ex)
                     {
                         DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                     }
                 }
             Directory.Delete(loc + "temp", true);
         }
         #endregion
     }
     #region Basegame Stuff
     string dir = ME3Directory.cookedPath;
     string[] files = Directory.GetFiles(dir,"*.pcc");            
     pbar1.Maximum = files.Length - 1;
     foreach (string file in files)
     {
         DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0);
         try
         {
             PCCObject pcc = new PCCObject(file);
             for (int i = 0; i < pcc.Exports.Count; i++)
                 if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                     pcc.Exports[i].ClassName == "StaticMesh")
                 {
                     EntryStruct ent = new EntryStruct();
                     ent.DLCName = "";
                     ent.Filename = Path.GetFileName(file);
                     ent.Index = i;
                     ent.isDLC = false;
                     ent.ObjectPath = pcc.Exports[i].GetFullPath;
                     ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                     Entries.Add(ent);
                 }
             if (count % 10 == 0)
             {
                 Application.DoEvents();
                 pbar1.Value = count;
             }
             count++;
         }
         catch (Exception ex)
         {
             DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
         }
     }
     #endregion
     #region Sorting
     bool run = true;
     DebugOutput.PrintLn("=====Info=====\n\nSorting names...\n\n=====Info=====");
     count = 0;
     while (run)
     {
         run = false;
         for(int i=0;i<Entries.Count -1;i++)
             if (Entries[i].Filename.CompareTo(Entries[i + 1].Filename) > 0)
             {
                 EntryStruct tmp = Entries[i];
                 Entries[i] = Entries[i + 1];
                 Entries[i + 1] = tmp;
                 run = true;
                 if (count++ % 100 == 0)
                     Application.DoEvents();
             }
     }
     #endregion
     TreeRefresh();
     timer1.Enabled = true;
 }
예제 #3
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;
            if (DisplayStyle == 0)
            {
                if (t.Parent == null || t.Name == "")
                    return;
                Renderer.STM = null;
                Renderer.SKM = null;
                Renderer.CamDistance = 10;
                Renderer.CamOffset = new Microsoft.DirectX.Vector3(0, 0, 0);
                try
                {
                    int i = 0;
                    if (Int32.TryParse(t.Name, out i))
                    {
                        EntryStruct en = Entries[i];
                        if (!en.isDLC)
                        {
                            PCCObject pcc = new PCCObject(ME3Directory.cookedPath + en.Filename);
                            if (en.isSkeletal)
                            {
                                Renderer.SKM = new SkeletalMesh(pcc, en.Index);
                                Renderer.CamDistance = Renderer.SKM.Bounding.r * 2.0f;
                                Renderer.CamOffset = Renderer.SKM.Bounding.origin;
                                treeView2.Nodes.Clear();
                                if (previewWithTreeToolStripMenuItem.Checked)
                                {
                                    treeView2.Visible = false;
                                    Application.DoEvents();
                                    treeView2.Nodes.Add(Renderer.SKM.ToTree());
                                    treeView2.Visible = true;
                                }
                            }
                            else
                            {

                            }
                        }
                        else
                        {
                            string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                            string dirDLC = ME3Directory.DLCPath;
                            dirDLC += en.DLCName;
                            dirDLC += "\\CookedPCConsole\\Default.sfar";
                            DLCBase dlc = new DLCBase(dirDLC);
                            foreach (sfarFile file in dlc.fileList)
                                try
                                {
                                    string filename = Path.GetFileName(file.fileName);
                                    if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                                    {
                                        using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + filename))
                                        {
                                            AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                        }
                                        if (File.Exists(loc + filename))
                                        {
                                            try
                                            {
                                                PCCObject pcc = new PCCObject(loc + filename);
                                                if (en.isSkeletal)
                                                {
                                                    Renderer.SKM = new SkeletalMesh(pcc, en.Index);
                                                    Renderer.CamDistance = Renderer.SKM.Bounding.r * 2.0f;
                                                    Renderer.CamOffset = Renderer.SKM.Bounding.origin;
                                                    treeView2.Nodes.Clear();
                                                    if (previewWithTreeToolStripMenuItem.Checked)
                                                    {
                                                        treeView2.Visible = false;
                                                        Application.DoEvents();
                                                        treeView2.Nodes.Add(Renderer.SKM.ToTree());
                                                        treeView2.Visible = true;
                                                    }
                                                }
                                                else
                                                {

                                                }
                                            }
                                            catch (Exception)
                                            {
                                            }
                                            File.Delete(loc + filename);
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #4
0
        //------------------------- GUI Menu Functions --------------------------
        private void openSfarFile(string fileName)
        {
            dlcBase = new DLCBase(fileName);
            dlcEditor = new DLCEditor(dlcBase);

            TreeNode root = new TreeNode(fileName);
            root.Name = fileName;
            TreeNode node = root;
            treeViewSfar.Nodes.Clear();
            treeViewSfar.Nodes.Add(root);

            foreach (sfarFile entry in dlcBase.fileList)
            {
                if (entry.fileName != null)
                {
                    string filePath = entry.fileName;
                    node = root;
                    System.Diagnostics.Debug.WriteLine("Parsing: " + entry.fileName);
                    string[] pathBits = filePath.Substring(1).Split('/');
                    for (int i = 0; i < pathBits.Length - 1; i++)
                    {
                        System.Diagnostics.Debug.WriteLine("Parsing pathbit: " + pathBits[i]);
                        node = AddNode(node, pathBits[i]);
                    }
                    //Add the 'file' object to the list
                    TreeNode last = node.Nodes.Add(pathBits[pathBits.Length - 1], pathBits[pathBits.Length - 1]);
                    last.Name = filePath;

                    switch (Path.GetExtension(filePath))
                    {
                        case ".afc": last.ImageIndex = 3; break;
                        case ".bik": last.ImageIndex = 4; break;
                        case ".tfc": last.ImageIndex = 2; break;
                        default: last.ImageIndex = 1; break;
                    }
                }
            }
            float fileSize;
            string strFileSize = "";

            textBoxNumOfFiles.Text = dlcBase.numOfFiles.ToString();

            //show the total uncompressed size
            setSize(dlcBase.totalUncSize, out fileSize, ref strFileSize);
            textBoxTotalUncSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture);
            labelTotalUncBytes.Text = strFileSize;

            //show the total compressed size
            setSize(dlcBase.totalComprSize, out fileSize, ref strFileSize);
            textBoxTotalComprSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture);
            labelTotalComprBytes.Text = strFileSize;

            textBoxCRatio.Text = ((float)dlcBase.totalComprSize / (float)dlcBase.totalUncSize * (float)100).ToString("0.#") + "%";
            textBoxFirstEntryOffset.Text = "0x" + dlcBase.entryOffset.ToString("X8");
            textBoxFirstBlockOffset.Text = "0x" + dlcBase.blockTableOffset.ToString("X8");
            textBoxFirstDataOffset.Text = "0x" + dlcBase.dataOffset.ToString("X8");

            //enable the right-click menu for nodes selection
            treeViewSfar.ContextMenuStrip = contextMenuStripEditor;

            //clear the previous values;
            textBoxFullName.Text = "";
            textBoxHash.Text = "";
            textBoxUncSize.Text = "";
            textBoxComprSize.Text = "";
            textBoxEntry.Text = "";
            textBoxBlockIndex.Text = "";
            textBoxDataOffset.Text = "";

            toolStripSaveFile.Enabled = false;
        }
예제 #5
0
        public static void RepackDLCs(bool MakeBackup = true)
        {
            if (!repackEnabled)
                return;
            String[] dlcupdates = GetFilesForRepacking();
            if (!Directory.Exists(GetDLCCachePath()))
                throw new FileNotFoundException("DLC Cache Path not found");
            if (dlcupdates.Length == 0)
            {
                DebugOutput.PrintLn("No updates found!");
                return;
            }

            List<String> tempdlcupdates = new List<string>();
            for (int i = 0; i < dlcupdates.Length; i++)
            {
                bool filefound = false;
                for (int j = 0; j < tempdlcupdates.Count; j++)
                {
                    if (String.Compare(dlcupdates[i], tempdlcupdates[j]) == 0)
                    {
                        filefound = true;
                        break;
                    }
                }
                if (!filefound)
                    tempdlcupdates.Add(dlcupdates[i]);
            }
            dlcupdates = tempdlcupdates.ToArray();

            DebugOutput.PrintLn("Repacking modified DLCs...");
            String DLCPath = Path.GetDirectoryName(listpath);
            string[] DLCs = Directory.EnumerateDirectories(DLCPath, "*", SearchOption.TopDirectoryOnly).ToArray();

            for (int i = 0; i < DLCs.Length; i++)
            {
                DirectoryInfo dinfo = new DirectoryInfo(DLCs[i]);
                FileInfo[] files = dinfo.GetFiles();
                List<String> updates = new List<string>();
                string commonname = Path.GetFileName(DLCs[i]);
                for (int j = 0; j < dlcupdates.Length; j++)
                {
                    if (Path.GetFileName(Path.GetDirectoryName(dlcupdates[j])) != commonname)
                        continue;

                    for (int k = 0; k < files.Length; k++)
                    {
                        if (String.Compare(files[k].Name, Path.GetFileName(dlcupdates[j]), true) == 0)
                        {
                            updates.Add(dlcupdates[j]);
                            break;
                        }
                    }
                }

                if (updates.Count <= 0)
                    continue;

                DebugOutput.PrintLn("DLC Updates found for " + commonname + ". Now fixing PCConsoleTOC.bin and repacking...");

                DLCBase dlcbase;
                try
                {
                    string[] tempdlc = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(DLCPath), "DLC", commonname), "Default.sfar", SearchOption.AllDirectories);
                    if (tempdlc == null || tempdlc.Length == 0)
                        throw new FileNotFoundException("DLC File not found!");

                    // KFreon: Allow no backup file creation
                    if (MakeBackup)
                    {
                        if (!File.Exists(Path.ChangeExtension(tempdlc[0], ".bak")))
                        {
                            DebugOutput.PrintLn("DLC backup file not found. Creating...");
                            File.Copy(tempdlc[0], Path.ChangeExtension(tempdlc[0], ".bak"), true);
                        }
                    }
                    dlcbase = new DLCBase(tempdlc[0]);
                }
                catch (FileNotFoundException)
                {
                    DebugOutput.PrintLn("DLC File Not Found");
                    continue;
                }
                catch 
                { 
                    DebugOutput.PrintLn("DLC Opening failed");
                    continue;
                }

                DLCEditor editor = new DLCEditor(dlcbase);

                String tocpath = null;
                for (int j = 0; j < files.Length; j++)
                {
                    if (String.Compare(Path.GetFileName(files[j].Name), "PCConsoleTOC.bin", true) == 0)
                    {
                        DLCTocFix(files[j].FullName);
                        tocpath = files[j].FullName;
                        break;
                    }
                }

                for (int j = 0; j < updates.Count; j++)
                {
                    String tempname = dlcbase.getFullNameOfEntry(updates[j]);
                    if (tempname == null)
                        throw new FileNotFoundException("Filename not found in DLC's files");
                    editor.setReplaceFile(tempname, updates[j]);
                }

                // Also add toc.bin
                String temptoc = dlcbase.getFullNameOfEntry(tocpath);
                if (temptoc == null)
                    throw new FileNotFoundException("TOC not found in DLC's files");
                editor.setReplaceFile(temptoc, tocpath);

                editor.Execute(Path.ChangeExtension(dlcbase.fileName, ".new"), null, Properties.Settings.Default.NumThreads);
                if (File.Exists(Path.ChangeExtension(dlcbase.fileName, ".new")))
                {
                    File.Copy(Path.ChangeExtension(dlcbase.fileName, ".new"), dlcbase.fileName, true);
                    File.Delete(Path.ChangeExtension(dlcbase.fileName, ".new"));
                }
                DebugOutput.PrintLn("Finished updating " + commonname, true);
            }
            File.Delete(listpath); // Reset the repack file
        }
예제 #6
0
        private void importLODToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            int m = listBox2.SelectedIndex;

            if (m == -1)
            {
                return;
            }
            TreeNode t1 = treeView1.SelectedNode;

            if (t1 == null || t1.Parent == null || t1.Name == "")
            {
                return;
            }
            PCCObject    pcc = new PCCObject();
            SkeletalMesh skm = new SkeletalMesh();
            EntryStruct  en;
            string       loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";

            if (DisplayStyle == 0)
            {
                int o = 0;
                if (!Int32.TryParse(t1.Name, out o))
                {
                    return;
                }
                en = Entries[o];
                if (!en.isDLC)
                {
                    pcc = new PCCObject(ME3Directory.cookedPath + en.Filename);
                    if (en.isSkeletal)
                    {
                        skm = new SkeletalMesh(pcc, en.Index);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    string dirDLC = ME3Directory.DLCPath;
                    dirDLC += en.DLCName;
                    dirDLC += "\\CookedPCConsole\\Default.sfar";
                    DLCBase dlc = new DLCBase(dirDLC);
                    foreach (sfarFile file in dlc.fileList)
                    {
                        try
                        {
                            string filename = Path.GetFileName(file.fileName);
                            if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                            {
                                if (File.Exists(loc + "dlc.pcc"))
                                {
                                    File.Delete(loc + "dlc.pcc");
                                }
                                using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + "dlc.pcc"))
                                {
                                    AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                }
                                if (File.Exists(loc + "dlc.pcc"))
                                {
                                    try
                                    {
                                        pcc = new PCCObject(loc + "dlc.pcc");
                                        if (en.isSkeletal)
                                        {
                                            skm = new SkeletalMesh(pcc, en.Index);
                                            break;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                return;
            }
            if (!skm.Loaded || !pcc.Loaded)
            {
                return;
            }
            SkeletalMesh.LODModelStruct          lodpcc = skm.LODModels[0];
            UDKExplorer.UDK.Classes.SkeletalMesh skmudk = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[n]);
            UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lodudk = skmudk.LODModels[m];
            lodpcc.Sections = new List <SkeletalMesh.SectionStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lodudk.Sections)
            {
                SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct();
                secpcc.BaseIndex     = secudk.BaseIndex;
                secpcc.ChunkIndex    = secudk.ChunkIndex;
                secpcc.MaterialIndex = secudk.MaterialIndex;
                secpcc.NumTriangles  = secudk.NumTriangles;
                lodpcc.Sections.Add(secpcc);
            }
            lodpcc.IndexBuffer            = new SkeletalMesh.MultiSizeIndexContainerStruct();
            lodpcc.IndexBuffer.IndexCount = lodudk.IndexBuffer.IndexCount;
            lodpcc.IndexBuffer.IndexSize  = lodudk.IndexBuffer.IndexSize;
            lodpcc.IndexBuffer.Indexes    = new List <ushort>();
            foreach (ushort Idx in lodudk.IndexBuffer.Indexes)
            {
                lodpcc.IndexBuffer.Indexes.Add(Idx);
            }
            List <int> BoneMap = new List <int>();

            for (int i = 0; i < skmudk.Bones.Count; i++)
            {
                string udkb  = udk.GetName(skmudk.Bones[i].Name);
                bool   found = false;
                for (int j = 0; j < skm.Bones.Count; j++)
                {
                    string pccb = pcc.getNameEntry(skm.Bones[j].Name);
                    if (pccb == udkb)
                    {
                        found = true;
                        BoneMap.Add(j);
                        if (importBonesToolStripMenuItem.Checked)
                        {
                            SkeletalMesh.BoneStruct bpcc = skm.Bones[j];
                            UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = skmudk.Bones[i];
                            bpcc.Orientation = budk.Orientation;
                            bpcc.Position    = budk.Position;
                            skm.Bones[j]     = bpcc;
                        }
                    }
                }
                if (!found)
                {
                    DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + udkb + "\"");
                    BoneMap.Add(0);
                }
            }

            lodpcc.ActiveBones = new List <ushort>();
            foreach (ushort Idx in lodudk.ActiveBones)
            {
                lodpcc.ActiveBones.Add((ushort)BoneMap[Idx]);
            }
            lodpcc.Chunks = new List <SkeletalMesh.SkelMeshChunkStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lodudk.Chunks)
            {
                SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct();
                chunkpcc.BaseVertexIndex   = chunkudk.BaseVertexIndex;
                chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences;
                chunkpcc.NumRigidVertices  = chunkudk.NumRigidVertices;
                chunkpcc.NumSoftVertices   = chunkudk.NumSoftVertices;
                chunkpcc.BoneMap           = new List <ushort>();
                chunkpcc.RiginSkinVertices = new List <SkeletalMesh.RigidSkinVertexStruct>();
                chunkpcc.SoftSkinVertices  = new List <SkeletalMesh.SoftSkinVertexStruct>();
                foreach (ushort Idx in chunkudk.BoneMap)
                {
                    chunkpcc.BoneMap.Add((ushort)BoneMap[Idx]);
                }
                lodpcc.Chunks.Add(chunkpcc);
            }
            lodpcc.Size          = lodudk.Size;
            lodpcc.NumVertices   = lodudk.NumVertices;
            lodpcc.RequiredBones = new List <byte>();
            foreach (byte b in lodudk.RequiredBones)
            {
                lodpcc.RequiredBones.Add(b);
            }
            lodpcc.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct();
            lodpcc.VertexBufferGPUSkin.NumTexCoords = lodudk.VertexBufferGPUSkin.NumTexCoords;
            lodpcc.VertexBufferGPUSkin.Extension    = lodudk.VertexBufferGPUSkin.Extension;
            lodpcc.VertexBufferGPUSkin.Origin       = lodudk.VertexBufferGPUSkin.Origin;
            lodpcc.VertexBufferGPUSkin.VertexSize   = lodudk.VertexBufferGPUSkin.VertexSize;
            lodpcc.VertexBufferGPUSkin.Vertices     = new List <SkeletalMesh.GPUSkinVertexStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lodudk.VertexBufferGPUSkin.Vertices)
            {
                SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct();
                vpcc.TangentX         = vudk.TangentX;
                vpcc.TangentZ         = vudk.TangentZ;
                vpcc.Position         = vudk.Position;
                vpcc.InfluenceBones   = vudk.InfluenceBones;
                vpcc.InfluenceWeights = vudk.InfluenceWeights;
                vpcc.U = vudk.U;
                vpcc.V = vudk.V;
                lodpcc.VertexBufferGPUSkin.Vertices.Add(vpcc);
            }
            for (int i = 0; i < skm.LODModels.Count; i++)
            {
                skm.LODModels[i] = lodpcc;
            }
            SerializingContainer con = new SerializingContainer();

            con.Memory    = new MemoryStream();
            con.isLoading = false;
            skm.Serialize(con);
            int          end = skm.GetPropertyEnd();
            MemoryStream mem = new MemoryStream();

            mem.Write(pcc.Exports[en.Index].Data, 0, end);
            mem.Write(con.Memory.ToArray(), 0, (int)con.Memory.Length);
            pcc.Exports[en.Index].Data = mem.ToArray();
            pcc.altSaveToFile(pcc.pccFileName, true);
            if (!en.isDLC)
            {
                MessageBox.Show("Done");
            }
            else
            {
                MessageBox.Show("Done. The file is now in following folder, please replace it back to DLC :\n" + loc + "dlc.pcc");
            }
            globalTreeToolStripMenuItem.Visible       =
                optionsToolStripMenuItem.Visible      =
                    transferToolStripMenuItem.Visible =
                        splitContainer1.Visible       = true;
            fileToolStripMenuItem.Visible             =
                importLODToolStripMenuItem.Visible    =
                    splitContainer3.Visible           = false;
        }
예제 #7
0
        private void scanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(ME3Directory.cookedPath))
            {
                MessageBox.Show("This functionality requires ME3 to be installed. Set its path at:\n Options > Set Custom Path > Mass Effect 3");
                return;
            }
            DebugOutput.StartDebugger("Meshplorer2");
            int count = 0;

            timer1.Enabled = false;
            Entries        = new List <EntryStruct>();
            bool ScanDLC = false;

            if (MessageBox.Show("Scan DLCs too?", "Meshplorer 2", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                ScanDLC = true;
            }
            if (ScanDLC)
            {
                #region DLC Stuff
                string dirDLC = ME3Directory.DLCPath;
                if (!Directory.Exists(dirDLC))
                {
                    DebugOutput.PrintLn("No DLC Folder found!");
                }
                else
                {
                    string[] subdirs = Directory.GetDirectories(dirDLC);
                    string   loc     = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                    Directory.CreateDirectory(loc + "temp");
                    foreach (string DLCpath in subdirs)
                    {
                        if (!DLCpath.StartsWith("__") && !DLCpath.StartsWith("DLC_UPD"))
                        {
                            string  path = DLCpath + "\\CookedPCConsole\\Default.sfar";
                            DLCBase dlcbase;
                            try
                            {
                                dlcbase       = new DLCBase(path);
                                count         = 0;
                                pbar1.Maximum = dlcbase.fileList.Count;
                                foreach (sfarFile file in dlcbase.fileList)
                                {
                                    try
                                    {
                                        string filename = Path.GetFileName(file.fileName);
                                        if (Path.GetExtension(filename).ToLower().EndsWith(".pcc"))
                                        {
                                            using (Stream input = File.OpenRead(path), output = File.Create(loc + "temp\\" + filename))
                                            {
                                                AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlcbase.CompressionScheme);
                                            }
                                            FileInfo f = new FileInfo(loc + "temp\\" + filename);
                                            DebugOutput.PrintLn("checking DLC: " + Path.GetFileName(DLCpath) + " File: " + filename + " Size: " + f.Length + " bytes", count % 3 == 0);
                                            PCCObject pcc = new PCCObject(loc + "temp\\" + filename);
                                            for (int i = 0; i < pcc.Exports.Count; i++)
                                            {
                                                if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                                                    pcc.Exports[i].ClassName == "StaticMesh")
                                                {
                                                    EntryStruct ent = new EntryStruct();
                                                    ent.DLCName    = Path.GetFileName(DLCpath);
                                                    ent.Filename   = filename;
                                                    ent.Index      = i;
                                                    ent.isDLC      = true;
                                                    ent.ObjectPath = pcc.Exports[i].GetFullPath;
                                                    ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                                                    Entries.Add(ent);
                                                }
                                            }
                                            File.Delete(loc + "temp\\" + filename);
                                        }
                                        if (count % 3 == 0)
                                        {
                                            pbar1.Value = count;
                                            Application.DoEvents();
                                        }
                                        count++;
                                    }
                                    catch (Exception ex)
                                    {
                                        DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                            }
                        }
                    }
                    Directory.Delete(loc + "temp", true);
                }
                #endregion
            }
            #region Basegame Stuff
            string   dir   = ME3Directory.cookedPath;
            string[] files = Directory.GetFiles(dir, "*.pcc");
            pbar1.Maximum = files.Length - 1;
            foreach (string file in files)
            {
                DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0);
                try
                {
                    PCCObject pcc = new PCCObject(file);
                    for (int i = 0; i < pcc.Exports.Count; i++)
                    {
                        if (pcc.Exports[i].ClassName == "SkeletalMesh" ||
                            pcc.Exports[i].ClassName == "StaticMesh")
                        {
                            EntryStruct ent = new EntryStruct();
                            ent.DLCName    = "";
                            ent.Filename   = Path.GetFileName(file);
                            ent.Index      = i;
                            ent.isDLC      = false;
                            ent.ObjectPath = pcc.Exports[i].GetFullPath;
                            ent.isSkeletal = (pcc.Exports[i].ClassName == "SkeletalMesh");
                            Entries.Add(ent);
                        }
                    }
                    if (count % 10 == 0)
                    {
                        Application.DoEvents();
                        pbar1.Value = count;
                    }
                    count++;
                }
                catch (Exception ex)
                {
                    DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR=====");
                }
            }
            #endregion
            #region Sorting
            bool run = true;
            DebugOutput.PrintLn("=====Info=====\n\nSorting names...\n\n=====Info=====");
            count = 0;
            while (run)
            {
                run = false;
                for (int i = 0; i < Entries.Count - 1; i++)
                {
                    if (Entries[i].Filename.CompareTo(Entries[i + 1].Filename) > 0)
                    {
                        EntryStruct tmp = Entries[i];
                        Entries[i]     = Entries[i + 1];
                        Entries[i + 1] = tmp;
                        run            = true;
                        if (count++ % 100 == 0)
                        {
                            Application.DoEvents();
                        }
                    }
                }
            }
            #endregion
            TreeRefresh();
            timer1.Enabled = true;
        }
예제 #8
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath);
            int i, status, updatecode, recode;
            for (i = 0; i < Program.filestatus.Count; i++)
            {
                status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString());
                fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath);
                string path = "";
                if (i < 4)
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null);
                else path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar";
                if (i < 4)
                {
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; }));
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = "处理中..."; this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; }));
                    }
                    if (i > 1)
                    {
                        if (status == 1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i);
                            if (recode == 0)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else updatecode = recode;
                        }
                        else updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                    }
                    else
                    {
                        recode=fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                         if (recode == 1)
                         {
                             updatecode = Program.ChoseVer;
                         }
                         else updatecode = recode;
                    }
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = fun.fileupdatcode(updatecode); listView1.Items[i].EnsureVisible(); }));
                    }

                    if (updatecode == 1 || updatecode == -1||updatecode==2||updatecode==4)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Green; }));
                    }
                    else
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; }));
                    }
                }
                else
                {
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; }));
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = "处理中..."; listView1.Items[i + 1].EnsureVisible(); }));
                    }
                    if (status >=7)
                    {

                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(status); listView1.Items[i + 1].EnsureVisible(); }));
                        this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
                        fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath);
                        continue;

                    }
                    else
                    {
                        if (Program.ChoseVer==-1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3,i+1);
                            if (recode == 0)
                                updatecode = 1;
                            else updatecode = recode;
                        }
                        else
                        {
                            this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; }));
                            dlcBase = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string[] arr1 = file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            FileInfo aa = new FileInfo(oldSfar);
                            if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(oldSfar, FileAttributes.Normal);
                            }
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                    return;
                                else
                                    Application.DoEvents();
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path)+"\\"+replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            updatecode = 2;
                        }
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(updatecode); }));
                        if (updatecode == 1 || updatecode == 2)
                        {
                            this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Green; listView1.Items[i + 1].EnsureVisible(); }));
                        }
                        else
                        {
                            this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; listView1.Items[i + 1].EnsureVisible(); }));
                        }
                    }
                }

                fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath);

                stdd = status;
                this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i+1)/(double)Program.filestatus.Count))*100)));
            }
        }
예제 #9
0
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath);
            int i, status, updatecode, recode;

            for (i = 0; i < Program.filestatus.Count; i++)
            {
                status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString());
                fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath);
                string path = "";
                if (i < 4)
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null);
                }
                else
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar";
                }
                if (i < 4)
                {
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; }));
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = "处理中..."; this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; }));
                    }
                    if (i > 1)
                    {
                        if (status == 1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i);
                            if (recode == 0)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else
                            {
                                updatecode = recode;
                            }
                        }
                        else
                        {
                            updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                        }
                    }
                    else
                    {
                        recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                        if (recode == 1)
                        {
                            updatecode = Program.ChoseVer;
                        }
                        else
                        {
                            updatecode = recode;
                        }
                    }
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = fun.fileupdatcode(updatecode); listView1.Items[i].EnsureVisible(); }));
                    }

                    if (updatecode == 1 || updatecode == -1 || updatecode == 2 || updatecode == 4)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Green; }));
                    }
                    else
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; }));
                    }
                }
                else
                {
                    if (listView1.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; }));
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = "处理中..."; listView1.Items[i + 1].EnsureVisible(); }));
                    }
                    if (status >= 7)
                    {
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(status); listView1.Items[i + 1].EnsureVisible(); }));
                        this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
                        fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath);
                        continue;
                    }
                    else
                    {
                        if (Program.ChoseVer == -1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i + 1);
                            if (recode == 0)
                            {
                                updatecode = 1;
                            }
                            else
                            {
                                updatecode = recode;
                            }
                        }
                        else
                        {
                            this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; }));
                            dlcBase   = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string   file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string[] arr1 = file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            string   oldSfar = dlcBase.fileName;
                            string   newSfar = oldSfar + ".tmp";
                            FileInfo aa      = new FileInfo(oldSfar);
                            if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(oldSfar, FileAttributes.Normal);
                            }
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] {
                                newSfar
                            });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                {
                                    return;
                                }
                                else
                                {
                                    Application.DoEvents();
                                }
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            updatecode = 2;
                        }
                        this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(updatecode); }));
                        if (updatecode == 1 || updatecode == 2)
                        {
                            this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Green; listView1.Items[i + 1].EnsureVisible(); }));
                        }
                        else
                        {
                            this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; listView1.Items[i + 1].EnsureVisible(); }));
                        }
                    }
                }

                fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath);

                stdd = status;
                this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
            }
        }
예제 #10
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            StartPosition : string temp = System.IO.Path.GetTempPath();
            fun.SaveRecordFile(temp, "bgm2", ".wma");
            string path; int status;

            fun.logger("开始校验文件", false, System.Windows.Forms.Application.StartupPath); this.Invoke(new MethodInvoker(delegate()
                                                                                                                     { this.label6.Hide(); }));
            #region MD5计算
            for (int FileID = 0; FileID < Program.filecode.Count + 1; FileID++)
            {
                this.Invoke(new MethodInvoker(delegate()
                {
                    this.progressBar1.Value = 0; this.progressBar2.Maximum = Program.filecode.Count + 1;
                    if (FileID < 4)
                    {
                        listView1.Items[fun.codetrans(FileID)].SubItems.Add("校验中...");
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        listView1.Items[FileID].SubItems[1].ForeColor        = Color.Red;
                    }
                    else if (FileID > 4)
                    {
                        listView1.Items[fun.codetrans(FileID - 1)].SubItems.Add("校验中...");
                        listView1.Items[FileID].EnsureVisible();
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        listView1.Items[FileID].SubItems[1].ForeColor        = Color.Red;
                    }
                    Application.DoEvents();
                }));
                if (FileID == 4)
                {
                    continue;
                }
                if (FileID < 4)
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID), "Filename", null);
                }
                else
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID - 1)] + "Default.sfar";
                }
                if (!File.Exists(path))
                {
                    if (FileID < 4)
                    {
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text             = "核心文件缺失,修复中...";
                            this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                            listView1.Items[FileID].SubItems[1].ForeColor        = Color.Red;
                            Application.DoEvents();
                        }));
                        fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID);
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text = " 重新校验中...";
                            Application.DoEvents();
                        }));
                    }
                    else
                    {
                        Program.filehash.Add(Convert.ToString(FileID), "");
                        this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Value = FileID; this.label4.Text = Convert.ToString(Math.Ceiling((FileID + 1) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%"; Application.DoEvents(); }));
                        if (FileID > 4)
                        {
                            Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                        }
                        else
                        {
                            Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                        }
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            if (FileID != 4)
                            {
                                listView1.Items[FileID].SubItems[1].Text             = fun.codestatustrans(status);
                                this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                                if (status == 1 || status == 6)
                                {
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                                }
                                else if (status == 2 || status == 4)
                                {
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                                }
                                else if (status == 3 || status == 5)
                                {
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                                }
                                else
                                {
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                }
                            }
                        }));
                        continue;
                    }
                }
                Program.filehash.Add(Convert.ToString(FileID), fun.AnyscMD5(path, progressBar1, label3));
                #endregion
                if (FileID > 4)
                {
                    Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                    status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                    #region DLC修复
                    if (status == 8)
                    {
                        for (int t = 1; t < 4; t++)
                        {
                            if (status != 8)
                            {
                                break;
                            }
                            fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text      = "损坏,第" + Convert.ToString(t) + "次尝试修复中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                progressBar1.Maximum = 100;
                                Application.DoEvents();
                            }));
                            dlcBase   = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string   file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "FileName", null);
                            string[] arr1 = file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, FileID - 1);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID - 1)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] {
                                newSfar
                            });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                {
                                    return;
                                }
                                else
                                {
                                    Application.DoEvents();
                                }
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text      = "重新校验中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                Application.DoEvents();
                            }));
                            Program.filehash[Convert.ToString(FileID)]       = fun.AnyscMD5(path, progressBar1, label3);
                            Program.filestatus[Convert.ToString(FileID - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                        }
                        if (status == 8)
                        {
                            MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            System.Environment.Exit(0);
                        }
                    }
                    #endregion
                    #region DLC升级
                    if (status == 3 || status == 5 || ((status == 1 || status == 6) && (Convert.ToInt32(Program.filestatus["1"].ToString()) != 1)))
                    {
                        fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath);
                        if (!Program.updst)
                        {
                            if (bgm)
                            {
                                fun.Pause(std);
                                std = 2;
                                fun.Play(std);
                            }
                            else
                            {
                                std = 2;
                            }
                        }
                        Program.updst = true;
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text      = "升级中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            progressBar1.Maximum = 100;
                            progressBar1.Value   = 0;
                            Application.DoEvents();
                        }));

                        dlcBase   = new DLCBase(path);
                        dlcEditor = new DLCEditor(dlcBase);
                        string   file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "FileName", null);
                        string[] arr1 = file.Split(';');
                        foreach (string replacefile in arr1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "Type", null), Convert.ToInt32(Program.filestatus["1"].ToString()), FileID - 1);
                            dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID - 1)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                        }
                        string oldSfar = dlcBase.fileName;
                        string newSfar = oldSfar + ".tmp";
                        backgroundWorkerEditFile.RunWorkerAsync(new object[1] {
                            newSfar
                        });
                        while (backgroundWorkerEditFile.IsBusy)
                        {
                            // Keep UI messages moving, so the form remains
                            // responsive during the asynchronous operation.
                            if (backgroundWorkerEditFile.CancellationPending)
                            {
                                return;
                            }
                            else
                            {
                                Application.DoEvents();
                            }
                        }
                        File.Delete(oldSfar);
                        foreach (string replacefile in arr1)
                        {
                            File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                        }
                        File.Move(newSfar, oldSfar);
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text      = "重新校验中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        Program.filehash[Convert.ToString(FileID)]       = fun.AnyscMD5(path, progressBar1, label3);
                        Program.filestatus[Convert.ToString(FileID - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                        status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                    }
                    #endregion
                }
                else
                {
                    Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                    status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                    #region 核心文件修复
                    if (status == 8 && FileID < 4)
                    {
                        for (int t = 1; t < 4; t++)
                        {
                            if (status != 8)
                            {
                                break;
                            }
                            fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text      = "损坏,第" + Convert.ToString(t) + "次尝试修复中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                Application.DoEvents();
                            }));
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text      = "重新校验中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                Application.DoEvents();
                            }));
                            Program.filehash[Convert.ToString(FileID)]   = fun.AnyscMD5(path, progressBar1, label3);
                            Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                        }
                        if (status == 8)
                        {
                            MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            System.Environment.Exit(0);
                        }
                    }
                    #endregion
                    #region 核心文件升级
                    if (status == 3 || status == 5)
                    {
                        fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath);
                        Program.updst = true;
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text      = "升级中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        if (FileID < 3)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID), "Type", null), status, FileID);
                        }
                        else
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, FileID);
                            VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, FileID);
                            File.Delete(path);
                            File.Move(Path.GetFileNameWithoutExtension(path) + ".tmp", path);
                        }
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text      = "重新校验中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        Program.filehash[Convert.ToString(FileID)]   = fun.AnyscMD5(path, progressBar1, label3);
                        Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                        status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                    }
                    #endregion
                }

                this.Invoke(new MethodInvoker(delegate()
                {
                    if (FileID > 4)
                    {
                        listView1.Items[FileID].SubItems[1].Text             = fun.codestatustrans(status);
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        if (status == 1 || status == 6)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                        }
                        else if (status == 2 || status == 4)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                        }
                        else if (status == 3 || status == 5)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                        }
                        else
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                        }
                    }
                    else if (FileID < 4)
                    {
                        listView1.Items[FileID].SubItems[1].Text             = fun.codestatustrans(status);
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        if (status == 1 || status == 6)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                        }
                        else if (status == 2 || status == 4)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                        }
                        else if (status == 3 || status == 5)
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                        }
                        else
                        {
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                        }
                        if (status == 1 && FileID == 1)
                        {
                            this.button2.Text         = "开始汉化(&S)";
                            this.radioButton1.Checked = true;
                        }
                        else if ((status == 2 || status == 4) && FileID == 1)
                        {
                            this.button2.Text = "开始还原(&S)";
                            if (status == 2)
                            {
                                this.radioButton1.Checked = true;
                            }
                            if (status == 4)
                            {
                                this.radioButton2.Checked = true;
                            }
                            this.groupBox3.Enabled = false;
                        }
                    }
                    this.progressBar2.Value = FileID;
                    this.label4.Text        = Convert.ToString(Math.Ceiling((FileID) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%";
                    Application.DoEvents();
                }));
            }

            #region 输出文件状态信息
            StreamWriter sw;
            sw = File.AppendText(System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log");
            sw.WriteLine(DateTime.Now + " 文件状态已确认,内部信息代码如下:");
            for (int i = 0; i < Program.filestatus.Count; i++)
            {
                sw.WriteLine("                   " + "文件:" + Convert.ToString(i) + "  " + "状态:" + Program.filestatus[Convert.ToString(i)].ToString());
            }
            sw.Close();
            #endregion
        }
예제 #11
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath);
            int i, status, updatecode=0, recode;
            for (i = 0; i < Program.filestatus.Count; i++)
            {
                this.Invoke(new MethodInvoker(delegate() { this.label6.Text=fun.codetrans(i);}));
                status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString());
                fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath);
                string path = "", bakpath = "", pathRus="";
                if (i < 4)
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null);
                    pathRus = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename2", null);
                }
                else
                {
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar";
                    bakpath = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar.mebak";
                }
                if (i < 4)
                {

                        this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; }));

                    if (i > 1)
                    {
                        if (status == 1 && Program.ChoseVer != -1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, status, i);
                            //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i);
                            if (recode == 0)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else updatecode = recode;
                        }
                        else
                        {
                            updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                        }
                    }
                    else
                    {
                        if (Program.RusVer == true && (IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null)!="COM"))
                        {
                            File.Delete(pathRus);
                            File.Move(path, path+".bak");
                            recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            File.Move(path, pathRus);
                            File.Move(path + ".bak",path );
                            if (recode == 1)
                            {
                                updatecode = Program.ChoseVer;
                            }
                        }
                        else
                        {
                            recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            if (recode == 1)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else updatecode = recode;
                        }
                    }
                }
                else
                {

                    if (status >= 7)
                    {
                        this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
                        fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath);
                        continue;
                    }
                    else
                    {
                        if (Program.ChoseVer == -1)
                        {
                            dlcBase = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string[] arr1 = file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, i);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                    return;
                                else
                                    Application.DoEvents();
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            //Program.filehash[Convert.ToString(i)] = fun.AnyscMD5(path, progressBar1, label3);
                           // Program.filestatus[Convert.ToString(i - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(i)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            //status = Convert.ToInt32(Program.filestatus[Convert.ToString(i - 1)].ToString());
                            //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            //recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i + 1);
                            //if (recode == 0)
                                updatecode = 1;
                            //else updatecode = recode;
                        }
                        else
                        {
                            if (Program.DLCbak == true&&(!File.Exists(bakpath)))
                            {
                                File.Copy(path,bakpath);
                            }
                            this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; }));
                            dlcBase = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string file2 = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName2", null);
                            string[] arr1 = file.Split(';');
                            string[] arr2 = file.Split(';');
                            int j=0;
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                                if (Program.RusVer == true)
                                {
                                    if(replacefile!="SFXGUI_Fonts_DLC.pcc")
                                    {
                                        if (File.Exists(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()))
                                            File.Delete(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString());
                                        File.Move(Path.GetDirectoryName(path) + "\\" + replacefile, Path.GetDirectoryName(path) + "\\" + arr2[j].ToString());
                                    }

                                    dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + arr2[j].ToString(), Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()); j++;
                                }
                                else
                                {
                                    dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            FileInfo aa = new FileInfo(oldSfar);
                            if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(oldSfar, FileAttributes.Normal);
                            }
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                    return;
                                else
                                    Application.DoEvents();
                            }
                            File.Delete(oldSfar);
                            if (Program.RusVer == true)
                            {
                                foreach (string replacefile in arr2)
                                {
                                    File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            else
                            {
                                foreach (string replacefile in arr1)
                                {
                                    File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            File.Move(newSfar, oldSfar);
                            updatecode = 2;
                        }
                    }
                }

                fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath);

                stdd = status;
                this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
            }
        }
예제 #12
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (DisplayStyle == 0)
            {
                if (t.Parent == null || t.Name == "")
                {
                    return;
                }
                preview?.Dispose();
                preview = null;
                try
                {
                    int i = 0;
                    if (Int32.TryParse(t.Name, out i))
                    {
                        EntryStruct en = Entries[i];
                        if (!en.isDLC)
                        {
                            ME3Package pcc = MEPackageHandler.OpenME3Package(ME3Directory.cookedPath + en.Filename);
                            if (en.isSkeletal)
                            {
                                SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index); // TODO: pass device
                                preview = new ModelPreview(view.Device, skmesh, view.TextureCache);
                                CenterView();
                                treeView2.Nodes.Clear();
                                if (previewWithTreeToolStripMenuItem.Checked)
                                {
                                    treeView2.Visible = false;
                                    Application.DoEvents();
                                    treeView2.Nodes.Add(skmesh.ToTree());
                                    treeView2.Visible = true;
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            string loc    = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                            string dirDLC = ME3Directory.DLCPath;
                            dirDLC += en.DLCName;
                            dirDLC += "\\CookedPCConsole\\Default.sfar";
                            DLCBase dlc = new DLCBase(dirDLC);
                            foreach (sfarFile file in dlc.fileList)
                            {
                                try
                                {
                                    string filename = Path.GetFileName(file.fileName);
                                    if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                                    {
                                        using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + filename))
                                        {
                                            AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                        }
                                        if (File.Exists(loc + filename))
                                        {
                                            try
                                            {
                                                ME3Package pcc = MEPackageHandler.OpenME3Package(loc + filename);
                                                if (en.isSkeletal)
                                                {
                                                    SkeletalMesh skmesh = new SkeletalMesh(pcc, en.Index);
                                                    CenterView();
                                                    treeView2.Nodes.Clear();
                                                    if (previewWithTreeToolStripMenuItem.Checked)
                                                    {
                                                        treeView2.Visible = false;
                                                        Application.DoEvents();
                                                        treeView2.Nodes.Add(skmesh.ToTree());
                                                        treeView2.Visible = true;
                                                    }
                                                }
                                                else
                                                {
                                                }
                                            }
                                            catch (Exception)
                                            {
                                            }
                                            File.Delete(loc + filename);
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #13
0
        //------------------------- GUI Menu Functions --------------------------

        private void openSfarFile(string fileName)
        {
            dlcBase   = new DLCBase(fileName);
            dlcEditor = new DLCEditor(dlcBase);



            TreeNode root = new TreeNode(fileName);

            root.Name = fileName;
            TreeNode node = root;

            treeViewSfar.Nodes.Clear();
            treeViewSfar.Nodes.Add(root);

            foreach (sfarFile entry in dlcBase.fileList)
            {
                if (entry.fileName != null)
                {
                    string filePath = entry.fileName;
                    node = root;
                    System.Diagnostics.Debug.WriteLine("Parsing: " + entry.fileName);
                    string[] pathBits = filePath.Substring(1).Split('/');
                    for (int i = 0; i < pathBits.Length - 1; i++)
                    {
                        System.Diagnostics.Debug.WriteLine("Parsing pathbit: " + pathBits[i]);
                        node = AddNode(node, pathBits[i]);
                    }
                    //Add the 'file' object to the list
                    TreeNode last = node.Nodes.Add(pathBits[pathBits.Length - 1], pathBits[pathBits.Length - 1]);
                    last.Name = filePath;

                    switch (Path.GetExtension(filePath))
                    {
                    case ".afc": last.ImageIndex = 3; break;

                    case ".bik": last.ImageIndex = 4; break;

                    case ".tfc": last.ImageIndex = 2; break;

                    default: last.ImageIndex = 1; break;
                    }
                }
            }
            float  fileSize;
            string strFileSize = "";

            textBoxNumOfFiles.Text = dlcBase.numOfFiles.ToString();

            //show the total uncompressed size
            setSize(dlcBase.totalUncSize, out fileSize, ref strFileSize);
            textBoxTotalUncSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture);
            labelTotalUncBytes.Text  = strFileSize;

            //show the total compressed size
            setSize(dlcBase.totalComprSize, out fileSize, ref strFileSize);
            textBoxTotalComprSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture);
            labelTotalComprBytes.Text  = strFileSize;

            textBoxCRatio.Text           = (dlcBase.totalComprSize / (float)dlcBase.totalUncSize * 100).ToString("0.#") + "%";
            textBoxFirstEntryOffset.Text = "0x" + dlcBase.entryOffset.ToString("X8");
            textBoxFirstBlockOffset.Text = "0x" + dlcBase.blockTableOffset.ToString("X8");
            textBoxFirstDataOffset.Text  = "0x" + dlcBase.dataOffset.ToString("X8");

            //enable the right-click menu for nodes selection
            treeViewSfar.ContextMenuStrip = contextMenuStripEditor;

            //clear the previous values;
            textBoxFullName.Text   = "";
            textBoxHash.Text       = "";
            textBoxUncSize.Text    = "";
            textBoxComprSize.Text  = "";
            textBoxEntry.Text      = "";
            textBoxBlockIndex.Text = "";
            textBoxDataOffset.Text = "";

            toolStripSaveFile.Enabled = false;
        }
예제 #14
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath);
            int i, status, updatecode = 0, recode;

            for (i = 0; i < Program.filestatus.Count; i++)
            {
                this.Invoke(new MethodInvoker(delegate() { this.label6.Text = fun.codetrans(i); }));
                status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString());
                fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath);
                string path = "", bakpath = "", pathRus = "";
                if (i < 4)
                {
                    path    = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null);
                    pathRus = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename2", null);
                }
                else
                {
                    path    = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar";
                    bakpath = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar.mebak";
                }
                if (i < 4)
                {
                    this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; }));

                    if (i > 1)
                    {
                        if (status == 1 && Program.ChoseVer != -1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, status, i);
                            //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i);
                            recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i);
                            if (recode == 0)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else
                            {
                                updatecode = recode;
                            }
                        }
                        else
                        {
                            updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                        }
                    }
                    else
                    {
                        if (Program.RusVer == true && (IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null) != "COM"))
                        {
                            File.Delete(pathRus);
                            File.Move(path, path + ".bak");
                            recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            File.Move(path, pathRus);
                            File.Move(path + ".bak", path);
                            if (recode == 1)
                            {
                                updatecode = Program.ChoseVer;
                            }
                        }
                        else
                        {
                            recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            if (recode == 1)
                            {
                                updatecode = Program.ChoseVer;
                            }
                            else
                            {
                                updatecode = recode;
                            }
                        }
                    }
                }
                else
                {
                    if (status >= 7)
                    {
                        this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
                        fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath);
                        continue;
                    }
                    else
                    {
                        if (Program.ChoseVer == -1)
                        {
                            dlcBase   = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string   file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string[] arr1 = file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, i);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] {
                                newSfar
                            });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                {
                                    return;
                                }
                                else
                                {
                                    Application.DoEvents();
                                }
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            //Program.filehash[Convert.ToString(i)] = fun.AnyscMD5(path, progressBar1, label3);
                            // Program.filestatus[Convert.ToString(i - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(i)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            //status = Convert.ToInt32(Program.filestatus[Convert.ToString(i - 1)].ToString());
                            //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                            //recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i + 1);
                            //if (recode == 0)
                            updatecode = 1;
                            //else updatecode = recode;
                        }
                        else
                        {
                            if (Program.DLCbak == true && (!File.Exists(bakpath)))
                            {
                                File.Copy(path, bakpath);
                            }
                            this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; }));
                            dlcBase   = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string   file  = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null);
                            string   file2 = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName2", null);
                            string[] arr1  = file.Split(';');
                            string[] arr2  = file.Split(';');
                            int      j     = 0;
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i);
                                if (Program.RusVer == true)
                                {
                                    if (replacefile != "SFXGUI_Fonts_DLC.pcc")
                                    {
                                        if (File.Exists(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()))
                                        {
                                            File.Delete(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString());
                                        }
                                        File.Move(Path.GetDirectoryName(path) + "\\" + replacefile, Path.GetDirectoryName(path) + "\\" + arr2[j].ToString());
                                    }

                                    dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + arr2[j].ToString(), Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()); j++;
                                }
                                else
                                {
                                    dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            string   oldSfar = dlcBase.fileName;
                            string   newSfar = oldSfar + ".tmp";
                            FileInfo aa      = new FileInfo(oldSfar);
                            if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                File.SetAttributes(oldSfar, FileAttributes.Normal);
                            }
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] {
                                newSfar
                            });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                {
                                    return;
                                }
                                else
                                {
                                    Application.DoEvents();
                                }
                            }
                            File.Delete(oldSfar);
                            if (Program.RusVer == true)
                            {
                                foreach (string replacefile in arr2)
                                {
                                    File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            else
                            {
                                foreach (string replacefile in arr1)
                                {
                                    File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                                }
                            }
                            File.Move(newSfar, oldSfar);
                            updatecode = 2;
                        }
                    }
                }

                fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath);

                stdd = status;
                this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100)));
            }
        }
예제 #15
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            StartPosition: string temp = System.IO.Path.GetTempPath();
            fun.SaveRecordFile(temp, "bgm2", ".wma");
            string path; int status;
            fun.logger("开始校验文件", false, System.Windows.Forms.Application.StartupPath);this.Invoke(new MethodInvoker(delegate()
                    {this.label6.Hide();}));
            #region MD5计算
            for (int FileID = 0; FileID < Program.filecode.Count+1; FileID++)
            {
                this.Invoke(new MethodInvoker(delegate()
                    {

                    this.progressBar1.Value = 0; this.progressBar2.Maximum = Program.filecode.Count+1;
                    if (FileID < 4)
                    {
                        listView1.Items[fun.codetrans(FileID)].SubItems.Add("校验中...");
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                    }
                    else if (FileID > 4)
                    {
                        listView1.Items[fun.codetrans(FileID - 1)].SubItems.Add("校验中...");
                        listView1.Items[FileID].EnsureVisible();
                        this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                        listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                    }
                    Application.DoEvents();
                    }));
                if (FileID == 4)
                    continue;
                if(FileID<4)
                    path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID)] + IniFiles.ini.INIGetStringValue(Program.IniPath,Convert.ToString(FileID),"Filename",null);
                else path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID-1)]+"Default.sfar";
                if (!File.Exists(path))
                {
                    if (FileID < 4)
                    {
                        this.Invoke(new MethodInvoker(delegate()
                   {
                       listView1.Items[FileID].SubItems[1].Text = "核心文件缺失,修复中...";
                       this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                       listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                       Application.DoEvents();
                   }));
                        fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID);
                        this.Invoke(new MethodInvoker(delegate()
                   {
                       listView1.Items[FileID].SubItems[1].Text = " 重新校验中...";
                       Application.DoEvents();
                   }));
                    }
                    else
                    {
                        Program.filehash.Add(Convert.ToString(FileID), "");
                        this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Value = FileID; this.label4.Text = Convert.ToString(Math.Ceiling((FileID + 1) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%"; Application.DoEvents(); }));
                        if (FileID > 4)
                        {
                            Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                        }
                        else
                        {
                            Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                        }
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            if (FileID != 4)
                            {
                                listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status);
                                this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                                if (status == 1 || status == 6)
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                                else if (status == 2 || status == 4)
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                                else if (status == 3 || status == 5)
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                                else listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            }
                        }));
                        continue;
                    }
                }
                Program.filehash.Add(Convert.ToString(FileID),fun.AnyscMD5(path,progressBar1,label3));
                #endregion
                if (FileID > 4)
                {
                    Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                    status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID-1)].ToString());
                    #region DLC修复
                    if (status == 8)
                    {
                        for (int t = 1; t < 4; t++)
                        {
                            if (status != 8)
                                break;
                            fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text = "损坏,第" + Convert.ToString(t) + "次尝试修复中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                progressBar1.Maximum = 100;
                                Application.DoEvents();
                            }));
                            dlcBase = new DLCBase(path);
                            dlcEditor = new DLCEditor(dlcBase);
                            string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID-1), "FileName", null);
                            string[] arr1=file.Split(';');
                            foreach (string replacefile in arr1)
                            {
                                fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, FileID-1);
                                dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID-1)].ToString().Replace('\\','/')+replacefile, Path.GetDirectoryName(path)+"\\"+replacefile);
                            }
                            string oldSfar = dlcBase.fileName;
                            string newSfar = oldSfar + ".tmp";
                            backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar });
                            while (backgroundWorkerEditFile.IsBusy)
                            {
                                // Keep UI messages moving, so the form remains
                                // responsive during the asynchronous operation.
                                if (backgroundWorkerEditFile.CancellationPending)
                                    return;
                                else
                                    Application.DoEvents();
                            }
                            File.Delete(oldSfar);
                            foreach (string replacefile in arr1)
                            {
                                File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                            }
                            File.Move(newSfar, oldSfar);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text = "重新校验中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                Application.DoEvents();
                            }));
                            Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3);
                            Program.filestatus[Convert.ToString(FileID-1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID-1)].ToString());

                        }
                        if (status == 8)
                        {
                            MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            System.Environment.Exit(0);
                        }
                    }
                    #endregion
                    #region DLC升级
                    if (status == 3 || status == 5||((status==1||status==6)&&(Convert.ToInt32(Program.filestatus["1"].ToString())!=1)))
                    {
                        fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath);
                        if (!Program.updst)
                        {
                            if (bgm)
                            {
                                fun.Pause(std);
                                std = 2;
                                fun.Play(std);
                            }
                            else std = 2;
                        }
                        Program.updst = true;
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text = "升级中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            progressBar1.Maximum = 100;
                            progressBar1.Value = 0;
                            Application.DoEvents();
                        }));

                        dlcBase = new DLCBase(path);
                        dlcEditor = new DLCEditor(dlcBase);
                        string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "FileName", null);
                        string[] arr1 = file.Split(';');
                        foreach (string replacefile in arr1)
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "Type", null), Convert.ToInt32(Program.filestatus["1"].ToString()), FileID - 1);
                            dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID - 1)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile);
                        }
                        string oldSfar = dlcBase.fileName;
                        string newSfar = oldSfar + ".tmp";
                        backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar });
                        while (backgroundWorkerEditFile.IsBusy)
                        {
                            // Keep UI messages moving, so the form remains
                            // responsive during the asynchronous operation.
                            if (backgroundWorkerEditFile.CancellationPending)
                                return;
                            else
                                Application.DoEvents();
                        }
                        File.Delete(oldSfar);
                        foreach (string replacefile in arr1)
                        {
                            File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile);
                        }
                        File.Move(newSfar, oldSfar);
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text = "重新校验中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3);
                        Program.filestatus[Convert.ToString(FileID - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                        status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString());
                    }
                    #endregion

                }
                else
                {
                    Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)));
                    status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                    #region 核心文件修复
                    if (status == 8 && FileID < 4)
                    {
                        for (int t = 1; t < 4; t++)
                        {

                            if (status != 8)
                                break;
                            fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath);
                            this.Invoke(new MethodInvoker(delegate()
                                {
                                    listView1.Items[FileID].SubItems[1].Text = "损坏,第"+Convert.ToString(t)+"次尝试修复中...";
                                    listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                    Application.DoEvents();
                                }));
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID);
                            this.Invoke(new MethodInvoker(delegate()
                            {
                                listView1.Items[FileID].SubItems[1].Text = "重新校验中...";
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                                Application.DoEvents();
                            }));
                            Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3);
                            Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                            status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());

                        }
                        if (status == 8)
                        {
                            MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            System.Environment.Exit(0);
                        }
                    }
                    #endregion
                    #region 核心文件升级
                    if (status == 3 || status == 5)
                    {
                        fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath);
                        Program.updst = true;
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text = "升级中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        if (FileID < 3)
                            fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID), "Type", null), status, FileID);
                        else
                        {
                            fun.fileupdate(Path.GetDirectoryName(path), "Data.pat","COM", status, FileID);
                            VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, FileID);
                            File.Delete(path);
                            File.Move(Path.GetFileNameWithoutExtension(path) + ".tmp", path);
                        }
                        this.Invoke(new MethodInvoker(delegate()
                        {
                            listView1.Items[FileID].SubItems[1].Text = "重新校验中...";
                            listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            Application.DoEvents();
                        }));
                        Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3);
                        Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile));
                        status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString());
                    }
                    #endregion

                }

                this.Invoke(new MethodInvoker(delegate()
                    {
                        if (FileID > 4)
                        {
                            listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status);
                            this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                            if (status == 1 || status == 6)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                            else if (status == 2 || status == 4)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                            else if (status == 3 || status == 5)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                            else listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                        }
                        else if (FileID < 4)
                        {
                            listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status);
                            this.listView1.Items[FileID].UseItemStyleForSubItems = false;
                            if (status == 1 || status == 6)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Black;
                            else if (status == 2 || status == 4)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Green;
                            else if (status == 3 || status == 5)
                                listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown;
                            else listView1.Items[FileID].SubItems[1].ForeColor = Color.Red;
                            if (status == 1 && FileID == 1)
                            {
                                this.button2.Text = "开始汉化(&S)";
                                this.radioButton1.Checked = true;
                            }
                            else if ((status == 2 || status == 4) && FileID == 1)
                            {
                                this.button2.Text = "开始还原(&S)";
                                if (status == 2)
                                    this.radioButton1.Checked = true;
                                if (status == 4)
                                    this.radioButton2.Checked = true;
                                this.groupBox3.Enabled = false;
                            }
                        }
                        this.progressBar2.Value = FileID ;
                        this.label4.Text = Convert.ToString(Math.Ceiling((FileID) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%";
                        Application.DoEvents();
                    }));

            }

            #region 输出文件状态信息
            StreamWriter sw;
            sw = File.AppendText(System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log");
            sw.WriteLine(DateTime.Now + " 文件状态已确认,内部信息代码如下:");
            for (int i = 0; i < Program.filestatus.Count; i++)
            {
                sw.WriteLine("                   " + "文件:" + Convert.ToString(i) + "  " + "状态:" + Program.filestatus[Convert.ToString(i)].ToString());
            }
            sw.Close();
            #endregion
        }
예제 #16
0
        private void importLODToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;
            if (n == -1)
                return;
            int m = listBox2.SelectedIndex;
            if (m == -1)
                return;
            TreeNode t1 = treeView1.SelectedNode;
            if (t1 == null || t1.Parent == null || t1.Name == "")
                return;
            PCCObject pcc = new PCCObject();
            SkeletalMesh skm = new SkeletalMesh();
            EntryStruct en;
            string loc = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
            if (DisplayStyle == 0)
            {
                int o = 0;
                if (!Int32.TryParse(t1.Name, out o))
                    return;
                en = Entries[o];                
                if (!en.isDLC)
                {
                    pcc = new PCCObject(ME3Directory.cookedPath + en.Filename);
                    if (en.isSkeletal)
                    {
                        skm = new SkeletalMesh(pcc, en.Index);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {                    
                    string dirDLC = ME3Directory.DLCPath;
                    dirDLC += en.DLCName;
                    dirDLC += "\\CookedPCConsole\\Default.sfar";
                    DLCBase dlc = new DLCBase(dirDLC);
                    foreach (sfarFile file in dlc.fileList)
                        try
                        {
                            string filename = Path.GetFileName(file.fileName);
                            if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                            {
                                if (File.Exists(loc + "dlc.pcc"))
                                    File.Delete(loc + "dlc.pcc");
                                using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + "dlc.pcc"))
                                {
                                    AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                }
                                if (File.Exists(loc + "dlc.pcc"))
                                {
                                    try
                                    {
                                        pcc = new PCCObject(loc + "dlc.pcc");
                                        if (en.isSkeletal)
                                        {
                                            skm = new SkeletalMesh(pcc, en.Index);
                                            break;
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            return;
                        }
                }
            }
            else
                return;
            if (!skm.Loaded || !pcc.Loaded)
                return;
            SkeletalMesh.LODModelStruct lodpcc = skm.LODModels[0];
            UDKExplorer.UDK.Classes.SkeletalMesh skmudk = new UDKExplorer.UDK.Classes.SkeletalMesh(udk, Objects[n]);
            UDKExplorer.UDK.Classes.SkeletalMesh.LODModelStruct lodudk = skmudk.LODModels[m];
            lodpcc.Sections = new List<SkeletalMesh.SectionStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SectionStruct secudk in lodudk.Sections)
            {
                SkeletalMesh.SectionStruct secpcc = new SkeletalMesh.SectionStruct();
                secpcc.BaseIndex = secudk.BaseIndex;
                secpcc.ChunkIndex = secudk.ChunkIndex;
                secpcc.MaterialIndex = secudk.MaterialIndex;
                secpcc.NumTriangles = secudk.NumTriangles;
                lodpcc.Sections.Add(secpcc);
            }
            lodpcc.IndexBuffer = new SkeletalMesh.MultiSizeIndexContainerStruct();
            lodpcc.IndexBuffer.IndexCount = lodudk.IndexBuffer.IndexCount;
            lodpcc.IndexBuffer.IndexSize = lodudk.IndexBuffer.IndexSize;
            lodpcc.IndexBuffer.Indexes = new List<ushort>();
            foreach (ushort Idx in lodudk.IndexBuffer.Indexes)
                lodpcc.IndexBuffer.Indexes.Add(Idx);
            List<int> BoneMap = new List<int>();
            for (int i = 0; i < skmudk.Bones.Count; i++)
            {
                string udkb = udk.GetName(skmudk.Bones[i].Name);
                bool found = false;
                for (int j = 0; j < skm.Bones.Count; j++)
                {
                    string pccb = pcc.getNameEntry(skm.Bones[j].Name);
                    if (pccb == udkb)
                    {
                        found = true;
                        BoneMap.Add(j);
                        if (importBonesToolStripMenuItem.Checked)
                        {
                            SkeletalMesh.BoneStruct bpcc = skm.Bones[j];
                            UDKExplorer.UDK.Classes.SkeletalMesh.BoneStruct budk = skmudk.Bones[i];
                            bpcc.Orientation = budk.Orientation;
                            bpcc.Position = budk.Position;
                            skm.Bones[j] = bpcc;
                        }
                    }
                }
                if (!found)
                {
                    DebugOutput.PrintLn("ERROR: Cant Match Bone \"" + udkb + "\"");
                    BoneMap.Add(0);
                }
            }

            lodpcc.ActiveBones = new List<ushort>();
            foreach (ushort Idx in lodudk.ActiveBones)
                lodpcc.ActiveBones.Add((ushort)BoneMap[Idx]);
            lodpcc.Chunks = new List<SkeletalMesh.SkelMeshChunkStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.SkelMeshChunkStruct chunkudk in lodudk.Chunks)
            {
                SkeletalMesh.SkelMeshChunkStruct chunkpcc = new SkeletalMesh.SkelMeshChunkStruct();
                chunkpcc.BaseVertexIndex = chunkudk.BaseVertexIndex;
                chunkpcc.MaxBoneInfluences = chunkudk.MaxBoneInfluences;
                chunkpcc.NumRigidVertices = chunkudk.NumRigidVertices;
                chunkpcc.NumSoftVertices = chunkudk.NumSoftVertices;
                chunkpcc.BoneMap = new List<ushort>();
                chunkpcc.RiginSkinVertices = new List<SkeletalMesh.RigidSkinVertexStruct>();
                chunkpcc.SoftSkinVertices = new List<SkeletalMesh.SoftSkinVertexStruct>();
                foreach (ushort Idx in chunkudk.BoneMap)
                    chunkpcc.BoneMap.Add((ushort)BoneMap[Idx]);
                lodpcc.Chunks.Add(chunkpcc);
            }
            lodpcc.Size = lodudk.Size;
            lodpcc.NumVertices = lodudk.NumVertices;
            lodpcc.RequiredBones = new List<byte>();
            foreach (byte b in lodudk.RequiredBones)
                lodpcc.RequiredBones.Add(b);
            lodpcc.VertexBufferGPUSkin = new SkeletalMesh.VertexBufferGPUSkinStruct();
            lodpcc.VertexBufferGPUSkin.NumTexCoords = lodudk.VertexBufferGPUSkin.NumTexCoords;
            lodpcc.VertexBufferGPUSkin.Extension = lodudk.VertexBufferGPUSkin.Extension;
            lodpcc.VertexBufferGPUSkin.Origin = lodudk.VertexBufferGPUSkin.Origin;
            lodpcc.VertexBufferGPUSkin.VertexSize = lodudk.VertexBufferGPUSkin.VertexSize;
            lodpcc.VertexBufferGPUSkin.Vertices = new List<SkeletalMesh.GPUSkinVertexStruct>();
            foreach (UDKExplorer.UDK.Classes.SkeletalMesh.GPUSkinVertexStruct vudk in lodudk.VertexBufferGPUSkin.Vertices)
            {
                SkeletalMesh.GPUSkinVertexStruct vpcc = new SkeletalMesh.GPUSkinVertexStruct();
                vpcc.TangentX = vudk.TangentX;
                vpcc.TangentZ = vudk.TangentZ;
                vpcc.Position = vudk.Position;
                vpcc.InfluenceBones = vudk.InfluenceBones;
                vpcc.InfluenceWeights = vudk.InfluenceWeights;
                vpcc.U = vudk.U;
                vpcc.V = vudk.V;
                lodpcc.VertexBufferGPUSkin.Vertices.Add(vpcc);
            }
            for (int i = 0; i < skm.LODModels.Count; i++)
                skm.LODModels[i] = lodpcc;
            SerializingContainer con = new SerializingContainer();
            con.Memory = new MemoryStream();
            con.isLoading = false;
            skm.Serialize(con);
            int end = skm.GetPropertyEnd();
            MemoryStream mem = new MemoryStream();
            mem.Write(pcc.Exports[en.Index].Data, 0, end);
            mem.Write(con.Memory.ToArray(), 0, (int)con.Memory.Length);
            pcc.Exports[en.Index].Data = mem.ToArray();
            pcc.altSaveToFile(pcc.pccFileName, true);
            if (!en.isDLC)
                MessageBox.Show("Done");
            else
                MessageBox.Show("Done. The file is now in following folder, please replace it back to DLC :\n" + loc + "dlc.pcc");
            globalTreeToolStripMenuItem.Visible =
            optionsToolStripMenuItem.Visible =
            transferToolStripMenuItem.Visible =
            splitContainer1.Visible = true;
            fileToolStripMenuItem.Visible =
            importLODToolStripMenuItem.Visible =
            splitContainer3.Visible = false;
        }
예제 #17
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode t = treeView1.SelectedNode;

            if (DisplayStyle == 0)
            {
                if (t.Parent == null || t.Name == "")
                {
                    return;
                }
                Renderer.STM         = null;
                Renderer.SKM         = null;
                Renderer.CamDistance = 10;
                Renderer.CamOffset   = new Microsoft.DirectX.Vector3(0, 0, 0);
                try
                {
                    int i = 0;
                    if (Int32.TryParse(t.Name, out i))
                    {
                        EntryStruct en = Entries[i];
                        if (!en.isDLC)
                        {
                            PCCObject pcc = new PCCObject(ME3Directory.cookedPath + en.Filename);
                            if (en.isSkeletal)
                            {
                                Renderer.SKM         = new SkeletalMesh(pcc, en.Index);
                                Renderer.CamDistance = Renderer.SKM.Bounding.r * 2.0f;
                                Renderer.CamOffset   = Renderer.SKM.Bounding.origin;
                                treeView2.Nodes.Clear();
                                if (previewWithTreeToolStripMenuItem.Checked)
                                {
                                    treeView2.Visible = false;
                                    Application.DoEvents();
                                    treeView2.Nodes.Add(Renderer.SKM.ToTree());
                                    treeView2.Visible = true;
                                }
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            string loc    = Path.GetDirectoryName(Application.ExecutablePath) + "\\exec\\";
                            string dirDLC = ME3Directory.DLCPath;
                            dirDLC += en.DLCName;
                            dirDLC += "\\CookedPCConsole\\Default.sfar";
                            DLCBase dlc = new DLCBase(dirDLC);
                            foreach (sfarFile file in dlc.fileList)
                            {
                                try
                                {
                                    string filename = Path.GetFileName(file.fileName);
                                    if (Path.GetExtension(filename).ToLower().EndsWith(".pcc") && filename == en.Filename)
                                    {
                                        using (Stream input = File.OpenRead(dirDLC), output = File.Create(loc + filename))
                                        {
                                            AmaroK86.MassEffect3.DLCUnpack.DecompressEntry(file, input, output, dlc.CompressionScheme);
                                        }
                                        if (File.Exists(loc + filename))
                                        {
                                            try
                                            {
                                                PCCObject pcc = new PCCObject(loc + filename);
                                                if (en.isSkeletal)
                                                {
                                                    Renderer.SKM         = new SkeletalMesh(pcc, en.Index);
                                                    Renderer.CamDistance = Renderer.SKM.Bounding.r * 2.0f;
                                                    Renderer.CamOffset   = Renderer.SKM.Bounding.origin;
                                                    treeView2.Nodes.Clear();
                                                    if (previewWithTreeToolStripMenuItem.Checked)
                                                    {
                                                        treeView2.Visible = false;
                                                        Application.DoEvents();
                                                        treeView2.Nodes.Add(Renderer.SKM.ToTree());
                                                        treeView2.Visible = true;
                                                    }
                                                }
                                                else
                                                {
                                                }
                                            }
                                            catch (Exception)
                                            {
                                            }
                                            File.Delete(loc + filename);
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #18
0
        public static void RepackDLCs(bool MakeBackup = true)
        {
            if (!repackEnabled)
            {
                return;
            }
            String[] dlcupdates = GetFilesForRepacking();
            if (!Directory.Exists(GetDLCCachePath()))
            {
                throw new FileNotFoundException("DLC Cache Path not found");
            }
            if (dlcupdates.Length == 0)
            {
                DebugOutput.PrintLn("No updates found!");
                return;
            }

            List <String> tempdlcupdates = new List <string>();

            for (int i = 0; i < dlcupdates.Length; i++)
            {
                bool filefound = false;
                for (int j = 0; j < tempdlcupdates.Count; j++)
                {
                    if (String.Compare(dlcupdates[i], tempdlcupdates[j]) == 0)
                    {
                        filefound = true;
                        break;
                    }
                }
                if (!filefound)
                {
                    tempdlcupdates.Add(dlcupdates[i]);
                }
            }
            dlcupdates = tempdlcupdates.ToArray();

            DebugOutput.PrintLn("Repacking modified DLCs...");
            String DLCPath = Path.GetDirectoryName(listpath);

            string[] DLCs = Directory.EnumerateDirectories(DLCPath, "*", SearchOption.TopDirectoryOnly).ToArray();

            for (int i = 0; i < DLCs.Length; i++)
            {
                DirectoryInfo dinfo      = new DirectoryInfo(DLCs[i]);
                FileInfo[]    files      = dinfo.GetFiles();
                List <String> updates    = new List <string>();
                string        commonname = Path.GetFileName(DLCs[i]);
                for (int j = 0; j < dlcupdates.Length; j++)
                {
                    if (Path.GetFileName(Path.GetDirectoryName(dlcupdates[j])) != commonname)
                    {
                        continue;
                    }

                    for (int k = 0; k < files.Length; k++)
                    {
                        if (String.Compare(files[k].Name, Path.GetFileName(dlcupdates[j]), true) == 0)
                        {
                            updates.Add(dlcupdates[j]);
                            break;
                        }
                    }
                }

                if (updates.Count <= 0)
                {
                    continue;
                }

                DebugOutput.PrintLn("DLC Updates found for " + commonname + ". Now fixing PCConsoleTOC.bin and repacking...");

                DLCBase dlcbase;
                try
                {
                    string[] tempdlc = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(DLCPath), "DLC", commonname), "Default.sfar", SearchOption.AllDirectories);
                    if (tempdlc == null || tempdlc.Length == 0)
                    {
                        throw new FileNotFoundException("DLC File not found!");
                    }

                    // KFreon: Allow no backup file creation
                    if (MakeBackup)
                    {
                        if (!File.Exists(Path.ChangeExtension(tempdlc[0], ".bak")))
                        {
                            DebugOutput.PrintLn("DLC backup file not found. Creating...");
                            File.Copy(tempdlc[0], Path.ChangeExtension(tempdlc[0], ".bak"), true);
                        }
                    }
                    dlcbase = new DLCBase(tempdlc[0]);
                }
                catch (FileNotFoundException)
                {
                    DebugOutput.PrintLn("DLC File Not Found");
                    continue;
                }
                catch
                {
                    DebugOutput.PrintLn("DLC Opening failed");
                    continue;
                }

                DLCEditor editor = new DLCEditor(dlcbase);

                String tocpath = null;
                for (int j = 0; j < files.Length; j++)
                {
                    if (String.Compare(Path.GetFileName(files[j].Name), "PCConsoleTOC.bin", true) == 0)
                    {
                        DLCTocFix(files[j].FullName);
                        tocpath = files[j].FullName;
                        break;
                    }
                }

                for (int j = 0; j < updates.Count; j++)
                {
                    String tempname = dlcbase.getFullNameOfEntry(updates[j]);
                    if (tempname == null)
                    {
                        throw new FileNotFoundException("Filename not found in DLC's files");
                    }
                    editor.setReplaceFile(tempname, updates[j]);
                }

                // Also add toc.bin
                String temptoc = dlcbase.getFullNameOfEntry(tocpath);
                if (temptoc == null)
                {
                    throw new FileNotFoundException("TOC not found in DLC's files");
                }
                editor.setReplaceFile(temptoc, tocpath);

                editor.Execute(Path.ChangeExtension(dlcbase.fileName, ".new"), null, Properties.Settings.Default.NumThreads);
                if (File.Exists(Path.ChangeExtension(dlcbase.fileName, ".new")))
                {
                    File.Copy(Path.ChangeExtension(dlcbase.fileName, ".new"), dlcbase.fileName, true);
                    File.Delete(Path.ChangeExtension(dlcbase.fileName, ".new"));
                }
                DebugOutput.PrintLn("Finished updating " + commonname, true);
            }
            File.Delete(listpath); // Reset the repack file
        }