Exemple #1
0
        private void _loadMym(object mymFile)
        {
            //Unzip mym file
            try
            {
                ReportProgress(0, "Unpacking mym...");
                FastZip fZip = new FastZip();
                fZip.ExtractZip((string)mymFile, mymOut, "");
                ReportProgress(100, " ");
            }
            catch (Exception ex) { ErrorBox(ex.Message); return; }

            //Parse ini
            try
            {
                ini = new mymini();
                ini.ProgressChanged += new EventHandler <System.ComponentModel.ProgressChangedEventArgs>(ini_ProgressChanged);
                ini.Load(mymOut + "mym.ini");
                ReportProgress(100, " ");
            }
            catch (Exception ex) { ErrorBox(ex.Message); return; }

            openedMym = Path.GetFileNameWithoutExtension((string)mymFile);

            //Add entries
            MethodInvoker m = new MethodInvoker(this.AddEntries);

            this.Invoke(m);
        }
Exemple #2
0
        public static mymini CreateIni(iniEntry[] iniEntries)
        {
            mymini m = new mymini();

            m.entries = new List <iniEntry>(iniEntries);
            return(m);
        }
Exemple #3
0
        public static mymini LoadIni(string iniPath)
        {
            mymini m = new mymini();

            m.iniFile = iniPath;
            m.ParseIni();
            return(m);
        }
Exemple #4
0
 private void msNew_Click(object sender, EventArgs e)
 {
     if (pbProgress.Value == 100)
     {
         Initialize();
         SetControls(true);
         ini       = new mymini();
         openedMym = string.Empty;
     }
 }
        private void _saveMym(object _creationInfo)
        {
            SetControls(false);
            CreationInfo cInfo = (CreationInfo)_creationInfo;
            string outDir = tempDir + "newMym\\";
            if (Directory.Exists(outDir)) Directory.Delete(outDir, true);
            Directory.CreateDirectory(outDir);

            int counter = 0;
            int[] counters = new int[5];

            //Build new ini
            List<iniEntry> tempEntries = new List<iniEntry>();
            List<string[]> dataSources = new List<string[]>();
            List<string[]> imageSources = new List<string[]>();

            foreach (object tempObject in cInfo.lbEntries)
            {
                ReportProgress(++counter * 100 / cInfo.lbEntries.Length, "Building mym.ini...");

                try
                {
                    iniEntry tempEntry = ini.GetEntry(tempObject.ToString());
                    if (!CheckEntry(tempEntry))
                    {
                        if (!settings.ignoreMissing) { ReportProgress(100, " "); SetControls(true); return; }
                        else continue;
                    }

                    if (settings.sourceManage)
                    {
                        //Manage source
                        if (tempEntry.entryType == iniEntry.EntryType.StaticData)
                        {
                            if (Path.HasExtension(tempEntry.filepath))
                            {
                                tempEntry.source = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath);

                                string tempSource = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath);
                                int i = 1;

                                while (EntryExists(tempEntry, dataSources))
                                {
                                    tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                                }

                                FileInfo fi = new FileInfo(tempEntry.filepath);
                                dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                            }
                            else
                            {
                                tempEntry.source = "\\" + Path.GetFileName(tempEntry.filepath);

                                string tempSource = "\\" + "\\" + Path.GetFileName(tempEntry.filepath);
                                int i = 1;

                                while (EntryExists(tempEntry, dataSources))
                                {
                                    tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                                }

                                FileInfo fi = new FileInfo(tempEntry.filepath);
                                dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                            }
                        }
                        else if (tempEntry.entryType == iniEntry.EntryType.StaticImage)
                        {
                            tempEntry.source = "\\images\\" + Path.GetFileName(tempEntry.filepath);

                            string tempSource = "\\images\\" + Path.GetFileName(tempEntry.filepath);
                            int i = 1;

                            while (EntryExists(tempEntry, imageSources))
                            {
                                tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                            }

                            FileInfo fi = new FileInfo(tempEntry.filepath);
                            imageSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                        }
                    }
                    if (settings.autoImageSize)
                    {
                        if (tempEntry.entryType == iniEntry.EntryType.CustomImage ||
                            tempEntry.entryType == iniEntry.EntryType.StaticImage)
                        {
                            //Get png width and height
                            Image img = Image.FromFile(tempEntry.filepath);
                            tempEntry.width = img.Width;
                            tempEntry.height = img.Height;
                        }
                    }

                    tempEntries.Add(tempEntry);
                }
                catch { }
            }

            if (tempEntries.Count < 1)
            {
                ErrorBox("No entries left...");
                SetControls(true);
                return;
            }

            //Manage Containers
            if (settings.containerManage)
            {
                List<string> containersToManage = new List<string>();
                List<string> managedContainers = new List<string>();

                foreach (iniEntry tempEntry in tempEntries)
                {
                    if (tempEntry.entryType == iniEntry.EntryType.Container)
                        managedContainers.Add(tempEntry.file);
                    else
                    {
                        if (tempEntry.file.Contains("_out"))
                        {
                            string tmpString = tempEntry.file.Remove(tempEntry.file.IndexOf("_out"));
                            tmpString = tmpString.Substring(0, tmpString.Length - 5) + tmpString.Substring(tmpString.Length - 5).Replace("_", ".");

                            if (!StringExistsInStringArray(tmpString, containersToManage.ToArray()))
                                containersToManage.Add(tmpString);
                        }
                    }
                }

                List<string> leftContainers = new List<string>();

                foreach (string thisContainer in containersToManage)
                {
                    if (!StringExistsInStringArray(thisContainer, managedContainers.ToArray()))
                        leftContainers.Add(thisContainer);
                }

                if (leftContainers.Count > 0)
                {
                    List<iniEntry> newList = new List<iniEntry>();

                    foreach (string thisContainer in leftContainers)
                    {
                        iniEntry tempEntry = new iniEntry();
                        tempEntry.entryType = iniEntry.EntryType.Container;
                        tempEntry.file = thisContainer;
                        tempEntry.type = iniEntry.ContainerType.ASH;

                        newList.Add(tempEntry);
                    }

                    newList.AddRange(tempEntries);
                    tempEntries = newList;
                }
            }

            ini = new mymini();
            ini.EntryList = tempEntries;
            ini.Save(outDir + "mym.ini");
            counter = 0;

            //Copy files
            foreach (iniEntry tempEntry in ini.EntryList)
            {
                ReportProgress(++counter * 100 / ini.EntryList.Count, "Copying files...");

                if (tempEntry.entryType == iniEntry.EntryType.StaticImage ||
                    tempEntry.entryType == iniEntry.EntryType.StaticData)
                {
                    string sourceFile = tempEntry.filepath;
                    string destFile = outDir + tempEntry.source;

                    if (!Directory.Exists(Path.GetDirectoryName(destFile))) Directory.CreateDirectory(Path.GetDirectoryName(destFile));
                    File.Copy(sourceFile, destFile, true);
                }
            }

            //Zip file
            ReportProgress(0, "Packing mym...");
            ReportProgress(80, ""); // Fake, hm?!
            FastZip fZip = new FastZip();
            fZip.CreateZip((cInfo.createCsm) ? tempDir + "temp.mym" : cInfo.savePath, outDir, true, "");
            ReportProgress(100, " ");

            if (cInfo.closeAfter) { MethodInvoker m = new MethodInvoker(this.ExitApplication); this.Invoke(m); return; }
            if (!cInfo.createCsm) { InfoBox("Saved mym to:\n" + cInfo.savePath); SetControls(true); return; }

            _createCsm(cInfo.savePath, cInfo.appFile, tempDir + "temp.mym");
        }
        private void _loadMym(object mymFile)
        {
            //Unzip mym file
            try
            {
                ReportProgress(0, "Unpacking mym...");
                FastZip fZip = new FastZip();
                fZip.ExtractZip((string)mymFile, mymOut, "");
                ReportProgress(100, " ");
            }
            catch (Exception ex) { ErrorBox(ex.Message); return; }

            //Parse ini
            try
            {
                ini = new mymini();
                ini.ProgressChanged += new EventHandler<System.ComponentModel.ProgressChangedEventArgs>(ini_ProgressChanged);
                ini.Load(mymOut + "mym.ini");
                ReportProgress(100, " ");
            }
            catch (Exception ex) { ErrorBox(ex.Message); return; }

            openedMym = Path.GetFileNameWithoutExtension((string)mymFile);

            //Add entries
            MethodInvoker m = new MethodInvoker(this.AddEntries);
            this.Invoke(m);
        }
Exemple #7
0
        private void _convertCsm()
        {
            string appDir = tempDir + "\\appOut\\";
            string csmDir = tempDir + "\\csmOut\\";
            string mymDir = tempDir + "\\mymOut\\";

            if (Directory.Exists(appDir))
            {
                Directory.Delete(appDir, true);
            }
            if (Directory.Exists(csmDir))
            {
                Directory.Delete(csmDir, true);
            }
            if (Directory.Exists(mymDir))
            {
                Directory.Delete(mymDir, true);
            }

            List <iniEntry> entryList = new List <iniEntry>();

            Wii.U8.UnpackU8(tbCsm.Text, csmDir);
            Wii.U8.UnpackU8(tbApp.Text, appDir);

            string[] csmFiles = Directory.GetFiles(csmDir, "*", SearchOption.AllDirectories);

            if (intensiveAlgorithm)
            {
                for (int i = 0; i < csmFiles.Length; i++)
                {
                    ReportProgress((i * 100 / csmFiles.Length) / 2);

                    byte[] temp = Wii.Tools.LoadFileToByteArray(csmFiles[i], 0, 4);
                    if (temp[0] == 'Y' && temp[1] == 'a' && temp[2] == 'z' && temp[3] == '0')
                    {
                        continue;
                    }

                    bool extracted = false;

                    while (!extracted)
                    {
                        byte[] fourBytes = Wii.Tools.LoadFileToByteArray(csmFiles[i].Replace(csmDir, appDir), 0, 4);

                        if (fourBytes[0] == 'A' && fourBytes[1] == 'S' &&
                            fourBytes[2] == 'H' && fourBytes[3] == '0')     //ASH0
                        {
                            try
                            {
                                DeASH(csmFiles[i].Replace(csmDir, appDir));

                                File.Delete(csmFiles[i].Replace(csmDir, appDir));
                                FileInfo fi = new FileInfo(csmFiles[i].Replace(csmDir, appDir) + ".arc");
                                fi.MoveTo(csmFiles[i].Replace(csmDir, appDir));
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'L' && fourBytes[1] == 'Z' &&
                                 fourBytes[2] == '7' && fourBytes[3] == '7') //Lz77
                        {
                            try
                            {
                                byte[] decompressedFile = Wii.Lz77.Decompress(File.ReadAllBytes(csmFiles[i].Replace(csmDir, appDir)), 0);

                                File.Delete(csmFiles[i].Replace(csmDir, appDir));
                                File.WriteAllBytes(csmFiles[i].Replace(csmDir, appDir), decompressedFile);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'Y' && fourBytes[1] == 'a' &&
                                 fourBytes[2] == 'z' && fourBytes[3] == '0') //Yaz0
                        {
                            //Nothing to do about yet...
                            break;
                        }
                        else if (fourBytes[0] == 0x55 && fourBytes[1] == 0xaa &&
                                 fourBytes[2] == 0x38 && fourBytes[3] == 0x2d) //U8
                        {
                            try
                            {
                                Wii.U8.UnpackU8(csmFiles[i].Replace(csmDir, appDir), csmFiles[i].Replace(csmDir, appDir).Replace(".", "_") + "_out");
                                File.Delete(csmFiles[i].Replace(csmDir, appDir));
                                extracted = true;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    extracted = false;

                    while (!extracted)
                    {
                        byte[] fourBytes = Wii.Tools.LoadFileToByteArray(csmFiles[i], 0, 4);

                        if (fourBytes[0] == 'A' && fourBytes[1] == 'S' &&
                            fourBytes[2] == 'H' && fourBytes[3] == '0')     //ASH0
                        {
                            try
                            {
                                DeASH(csmFiles[i]);

                                File.Delete(csmFiles[i]);
                                FileInfo fi = new FileInfo(csmFiles[i] + ".arc");
                                fi.MoveTo(csmFiles[i]);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'L' && fourBytes[1] == 'Z' &&
                                 fourBytes[2] == '7' && fourBytes[3] == '7') //Lz77
                        {
                            try
                            {
                                byte[] decompressedFile = Wii.Lz77.Decompress(File.ReadAllBytes(csmFiles[i]), 0);

                                File.Delete(csmFiles[i]);
                                File.WriteAllBytes(csmFiles[i], decompressedFile);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'Y' && fourBytes[1] == 'a' &&
                                 fourBytes[2] == 'z' && fourBytes[3] == '0') //Yaz0
                        {
                            //Nothing to do about yet...
                            break;
                        }
                        else if (fourBytes[0] == 0x55 && fourBytes[1] == 0xaa &&
                                 fourBytes[2] == 0x38 && fourBytes[3] == 0x2d) //U8
                        {
                            try
                            {
                                Wii.U8.UnpackU8(csmFiles[i], csmFiles[i].Replace(".", "_") + "_out");
                                File.Delete(csmFiles[i]);
                                extracted = true;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                csmFiles = Directory.GetFiles(csmDir, "*", SearchOption.AllDirectories);
            }

            for (int i = 0; i < csmFiles.Length; i++)
            {
                ReportProgress(((i * 100 / csmFiles.Length) / (intensiveAlgorithm ? 2 : 1)) + (intensiveAlgorithm ? 50 : 0));

                if (File.Exists(csmFiles[i].Replace(csmDir, appDir)))
                {
                    //File exists in original app
                    FileInfo fi  = new FileInfo(csmFiles[i]);
                    FileInfo fi2 = new FileInfo(csmFiles[i].Replace(csmDir, appDir));

                    if (fi.Length == fi2.Length) //Same file
                    {
                        continue;
                    }
                }

                iniEntry tempEntry = new iniEntry();
                tempEntry.entryType = iniEntry.EntryType.StaticData;
                tempEntry.file      = csmFiles[i].Replace(csmDir, string.Empty);
                if (!tempEntry.file.StartsWith("\\"))
                {
                    tempEntry.file = tempEntry.file.Insert(0, "\\");
                }

                if (!Directory.Exists(Path.GetDirectoryName(mymDir + Path.GetExtension(csmFiles[i]).Remove(0, 1) + "\\" + Path.GetFileName(csmFiles[i]))))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(mymDir + Path.GetExtension(csmFiles[i]).Remove(0, 1) + "\\" + Path.GetFileName(csmFiles[i])));
                }

                string destFile = mymDir + Path.GetExtension(csmFiles[i]).Remove(0, 1) + "\\" + Path.GetFileName(csmFiles[i]);

                int      counter  = 0;
                FileInfo fi1      = new FileInfo(csmFiles[i]);
                string   tempFile = destFile;

                while (File.Exists(destFile))
                {
                    FileInfo fi2 = new FileInfo(destFile);
                    if (fi1.Length == fi2.Length)
                    {
                        break;
                    }

                    destFile = tempFile.Replace(Path.GetExtension(tempFile), (++counter).ToString() + Path.GetExtension(tempFile));
                }

                File.Copy(csmFiles[i], destFile, true);
                tempEntry.source = "\\" + Path.GetExtension(destFile).Remove(0, 1) + "\\" + Path.GetFileName(destFile);
                entryList.Add(tempEntry);
            }

            //---

            List <string> containersToManage = new List <string>();
            List <string> managedContainers  = new List <string>();

            foreach (iniEntry tempEntry in entryList)
            {
                if (tempEntry.entryType == iniEntry.EntryType.Container)
                {
                    managedContainers.Add(tempEntry.file);
                }
                else
                {
                    if (tempEntry.file.Contains("_out"))
                    {
                        string tmpString = tempEntry.file.Remove(tempEntry.file.IndexOf("_out"));
                        tmpString = tmpString.Substring(0, tmpString.Length - 5) + tmpString.Substring(tmpString.Length - 5).Replace("_", ".");

                        if (!StringExistsInStringArray(tmpString, containersToManage.ToArray()))
                        {
                            containersToManage.Add(tmpString);
                        }
                    }
                }
            }

            List <string> leftContainers = new List <string>();

            foreach (string thisContainer in containersToManage)
            {
                if (!StringExistsInStringArray(thisContainer, managedContainers.ToArray()))
                {
                    leftContainers.Add(thisContainer);
                }
            }

            if (leftContainers.Count > 0)
            {
                List <iniEntry> newList = new List <iniEntry>();

                foreach (string thisContainer in leftContainers)
                {
                    iniEntry tempEntry = new iniEntry();
                    tempEntry.entryType = iniEntry.EntryType.Container;
                    tempEntry.file      = thisContainer;
                    tempEntry.type      = iniEntry.ContainerType.ASH;

                    newList.Add(tempEntry);
                }

                newList.AddRange(entryList);
                entryList = newList;
            }

            //---

            mymini ini = mymini.CreateIni(entryList.ToArray());

            ini.Save(mymDir + "mym.ini");

            FastZip fZip = new FastZip();

            fZip.CreateZip(saveFile, mymDir, true, "");

            if (Directory.Exists(appDir))
            {
                Directory.Delete(appDir, true);
            }
            if (Directory.Exists(csmDir))
            {
                Directory.Delete(csmDir, true);
            }
            if (Directory.Exists(mymDir))
            {
                Directory.Delete(mymDir, true);
            }

            ReportProgress(100);
            MessageBox.Show("Saved mym to:\n" + saveFile, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #8
0
        private void _saveMym(object _creationInfo)
        {
            SetControls(false);
            CreationInfo cInfo  = (CreationInfo)_creationInfo;
            string       outDir = tempDir + "newMym\\";

            if (Directory.Exists(outDir))
            {
                Directory.Delete(outDir, true);
            }
            Directory.CreateDirectory(outDir);

            int counter = 0;

            int[] counters = new int[5];

            //Build new ini
            List <iniEntry> tempEntries  = new List <iniEntry>();
            List <string[]> dataSources  = new List <string[]>();
            List <string[]> imageSources = new List <string[]>();

            foreach (object tempObject in cInfo.lbEntries)
            {
                ReportProgress(++counter * 100 / cInfo.lbEntries.Length, "Building mym.ini...");

                try
                {
                    iniEntry tempEntry = ini.GetEntry(tempObject.ToString());
                    if (!CheckEntry(tempEntry))
                    {
                        if (!settings.ignoreMissing)
                        {
                            ReportProgress(100, " "); SetControls(true); return;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (settings.sourceManage)
                    {
                        //Manage source
                        if (tempEntry.entryType == iniEntry.EntryType.StaticData)
                        {
                            if (Path.HasExtension(tempEntry.filepath))
                            {
                                tempEntry.source = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath);

                                string tempSource = "\\" + Path.GetExtension(tempEntry.filepath).Remove(0, 1) + "\\" + Path.GetFileName(tempEntry.filepath);
                                int    i          = 1;

                                while (EntryExists(tempEntry, dataSources))
                                {
                                    tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                                }

                                FileInfo fi = new FileInfo(tempEntry.filepath);
                                dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                            }
                            else
                            {
                                tempEntry.source = "\\" + Path.GetFileName(tempEntry.filepath);

                                string tempSource = "\\" + "\\" + Path.GetFileName(tempEntry.filepath);
                                int    i          = 1;

                                while (EntryExists(tempEntry, dataSources))
                                {
                                    tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                                }

                                FileInfo fi = new FileInfo(tempEntry.filepath);
                                dataSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                            }
                        }
                        else if (tempEntry.entryType == iniEntry.EntryType.StaticImage)
                        {
                            tempEntry.source = "\\images\\" + Path.GetFileName(tempEntry.filepath);

                            string tempSource = "\\images\\" + Path.GetFileName(tempEntry.filepath);
                            int    i          = 1;

                            while (EntryExists(tempEntry, imageSources))
                            {
                                tempEntry.source = tempSource.Insert(tempSource.LastIndexOf('.'), (++i).ToString());
                            }

                            FileInfo fi = new FileInfo(tempEntry.filepath);
                            imageSources.Add(new string[] { tempEntry.source, fi.Length.ToString() });
                        }
                    }
                    if (settings.autoImageSize)
                    {
                        if (tempEntry.entryType == iniEntry.EntryType.CustomImage ||
                            tempEntry.entryType == iniEntry.EntryType.StaticImage)
                        {
                            //Get png width and height
                            Image img = Image.FromFile(tempEntry.filepath);
                            tempEntry.width  = img.Width;
                            tempEntry.height = img.Height;
                        }
                    }

                    tempEntries.Add(tempEntry);
                }
                catch { }
            }

            if (tempEntries.Count < 1)
            {
                ErrorBox("No entries left...");
                SetControls(true);
                return;
            }

            //Manage Containers
            if (settings.containerManage)
            {
                List <string> containersToManage = new List <string>();
                List <string> managedContainers  = new List <string>();

                foreach (iniEntry tempEntry in tempEntries)
                {
                    if (tempEntry.entryType == iniEntry.EntryType.Container)
                    {
                        managedContainers.Add(tempEntry.file);
                    }
                    else
                    {
                        if (tempEntry.file.Contains("_out"))
                        {
                            string tmpString = tempEntry.file.Remove(tempEntry.file.IndexOf("_out"));
                            tmpString = tmpString.Substring(0, tmpString.Length - 5) + tmpString.Substring(tmpString.Length - 5).Replace("_", ".");

                            if (!StringExistsInStringArray(tmpString, containersToManage.ToArray()))
                            {
                                containersToManage.Add(tmpString);
                            }
                        }
                    }
                }

                List <string> leftContainers = new List <string>();

                foreach (string thisContainer in containersToManage)
                {
                    if (!StringExistsInStringArray(thisContainer, managedContainers.ToArray()))
                    {
                        leftContainers.Add(thisContainer);
                    }
                }

                if (leftContainers.Count > 0)
                {
                    List <iniEntry> newList = new List <iniEntry>();

                    foreach (string thisContainer in leftContainers)
                    {
                        iniEntry tempEntry = new iniEntry();
                        tempEntry.entryType = iniEntry.EntryType.Container;
                        tempEntry.file      = thisContainer;
                        tempEntry.type      = iniEntry.ContainerType.ASH;

                        newList.Add(tempEntry);
                    }

                    newList.AddRange(tempEntries);
                    tempEntries = newList;
                }
            }

            ini           = new mymini();
            ini.EntryList = tempEntries;
            ini.Save(outDir + "mym.ini");
            counter = 0;

            //Copy files
            foreach (iniEntry tempEntry in ini.EntryList)
            {
                ReportProgress(++counter * 100 / ini.EntryList.Count, "Copying files...");

                if (tempEntry.entryType == iniEntry.EntryType.StaticImage ||
                    tempEntry.entryType == iniEntry.EntryType.StaticData)
                {
                    string sourceFile = tempEntry.filepath;
                    string destFile   = outDir + tempEntry.source;

                    if (!Directory.Exists(Path.GetDirectoryName(destFile)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(destFile));
                    }
                    File.Copy(sourceFile, destFile, true);
                }
            }

            //Zip file
            ReportProgress(0, "Packing mym...");
            ReportProgress(80, ""); // Fake, hm?!
            FastZip fZip = new FastZip();

            fZip.CreateZip((cInfo.createCsm) ? tempDir + "temp.mym" : cInfo.savePath, outDir, true, "");
            ReportProgress(100, " ");

            if (cInfo.closeAfter)
            {
                MethodInvoker m = new MethodInvoker(this.ExitApplication); this.Invoke(m); return;
            }
            if (!cInfo.createCsm)
            {
                InfoBox("Saved mym to:\n" + cInfo.savePath); SetControls(true); return;
            }

            _createCsm(cInfo.savePath, cInfo.appFile, tempDir + "temp.mym");
        }
Exemple #9
0
        private void _createCsm(string savePath, string appPath, string mymPath)
        {
            ReportProgress(0, "Unpacking base app...");

            tempDir = Path.GetTempPath() + Guid.NewGuid().ToString() + "\\";
            string          appOut           = tempDir + "appOut\\";
            string          mymOut           = tempDir + "mymOut\\";
            List <iniEntry> editedContainers = new List <iniEntry>();

            Directory.CreateDirectory(appOut);
            int counter = 1;

            //Unpack .app
            try
            {
                Wii.U8.UnpackU8(File.ReadAllBytes(appPath), appOut);
            }
            catch (Exception ex) { SetControls(true); ErrorBox(ex.Message); return; }

            //Unpack .mym
            try
            {
                FastZip zFile = new FastZip();
                zFile.ExtractZip(mymPath, mymOut, "");
            }
            catch (Exception ex) { SetControls(true); ErrorBox(ex.Message); return; }

            //Parse ini
            if (!File.Exists(mymOut + "mym.ini"))
            {
                SetControls(true); ErrorBox("mym.ini wasn't found!"); return;
            }
            mymini ini = mymini.LoadIni(mymOut + "mym.ini");

            foreach (iniEntry tempEntry in ini.Entries)
            {
                ReportProgress(counter++ *100 / ini.Entries.Length, "Parsing mym.ini...");

                if (tempEntry.entryType == iniEntry.EntryType.Container)
                {
                    if (!File.Exists(appOut + tempEntry.file))
                    {
                        continue;
                    }

                    bool extracted = false;

                    while (!extracted)
                    {
                        byte[] fourBytes = Wii.Tools.LoadFileToByteArray(appOut + tempEntry.file, 0, 4);

                        if (fourBytes[0] == 'A' && fourBytes[1] == 'S' &&
                            fourBytes[2] == 'H' && fourBytes[3] == '0')     //ASH0
                        {
                            try
                            {
                                DeASH(tempEntry, appOut);

                                File.Delete(appOut + tempEntry.file);
                                FileInfo fi = new FileInfo(appOut + tempEntry.file + ".arc");
                                fi.MoveTo(appOut + tempEntry.file);
                            }
                            catch
                            {
                                SetControls(true);
                                ErrorBox("Entry: " + tempEntry.entry + "\n\nASH.exe returned an error!\nYou may try to decompress the ASH files manually...");
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'L' && fourBytes[1] == 'Z' &&
                                 fourBytes[2] == '7' && fourBytes[3] == '7') //Lz77
                        {
                            try
                            {
                                byte[] decompressedFile = Wii.Lz77.Decompress(File.ReadAllBytes(appOut + tempEntry.file), 0);

                                File.Delete(appOut + tempEntry.file);
                                File.WriteAllBytes(appOut + tempEntry.file, decompressedFile);
                            }
                            catch (Exception ex)
                            {
                                SetControls(true);
                                ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                                return;
                            }
                        }
                        else if (fourBytes[0] == 'Y' && fourBytes[1] == 'a' &&
                                 fourBytes[2] == 'z' && fourBytes[3] == '0') //Yaz0
                        {
                            //Nothing to do about yet...
                            break;
                        }
                        else if (fourBytes[0] == 0x55 && fourBytes[1] == 0xaa &&
                                 fourBytes[2] == 0x38 && fourBytes[3] == 0x2d) //U8
                        {
                            try
                            {
                                Wii.U8.UnpackU8(appOut + tempEntry.file, appOut + tempEntry.file.Replace('.', '_') + "_out");
                                File.Delete(appOut + tempEntry.file);
                                extracted = true;
                            }
                            catch (Exception ex)
                            {
                                SetControls(true);
                                ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                                return;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    editedContainers.Add(tempEntry);
                }
                else if (tempEntry.entryType == iniEntry.EntryType.CustomImage)
                {
                    try
                    {
                        if (File.Exists(appOut + tempEntry.file))
                        {
                            OpenFileDialog ofd = new OpenFileDialog();
                            ofd.Title  = tempEntry.name;
                            ofd.Filter = "PNG|*.png";

                            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                Image img = Image.FromFile(ofd.FileName);
                                img = ResizeImage(img, tempEntry.width, tempEntry.height);

                                if (File.Exists(appOut + tempEntry.file))
                                {
                                    File.Delete(appOut + tempEntry.file);
                                }
                                Wii.TPL.ConvertToTPL(img, appOut + tempEntry.file, (int)tempEntry.format);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SetControls(true);
                        ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                        return;
                    }
                }
                else if (tempEntry.entryType == iniEntry.EntryType.StaticImage)
                {
                    try
                    {
                        if (File.Exists(mymOut + tempEntry.source))
                        {
                            Image img = Image.FromFile(mymOut + tempEntry.source);
                            img = ResizeImage(img, tempEntry.width, tempEntry.height);

                            if (File.Exists(appOut + tempEntry.file))
                            {
                                File.Delete(appOut + tempEntry.file);
                            }
                            Wii.TPL.ConvertToTPL(img, appOut + tempEntry.file, (int)tempEntry.format);
                        }
                    }
                    catch (Exception ex)
                    {
                        SetControls(true);
                        ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                        return;
                    }
                }
                else if (tempEntry.entryType == iniEntry.EntryType.CustomData)
                {
                    try
                    {
                        if (File.Exists(appOut + tempEntry.file))
                        {
                            OpenFileDialog ofd = new OpenFileDialog();
                            ofd.FileName = tempEntry.name;

                            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                File.Copy(ofd.FileName, appOut + tempEntry.file, true);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SetControls(true);
                        ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                        return;
                    }
                }
                else if (tempEntry.entryType == iniEntry.EntryType.StaticData)
                {
                    try
                    {
                        if (File.Exists(mymOut + tempEntry.source))
                        {
                            File.Copy(mymOut + tempEntry.source, appOut + tempEntry.file, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        SetControls(true);
                        ErrorBox("Entry: " + tempEntry.entry + "\n\n" + ex.Message);
                        return;
                    }
                }
            }

            //Repack Containers
            foreach (iniEntry tempEntry in editedContainers)
            {
                if (!settings.lz77Containers)
                {
                    Wii.U8.PackU8(appOut + tempEntry.file.Replace('.', '_') + "_out", appOut + tempEntry.file);
                }
                else
                {
                    byte[] u8Container = Wii.U8.PackU8(appOut + tempEntry.file.Replace('.', '_') + "_out");
                    Wii.Lz77.Compress(u8Container, appOut + tempEntry.file);
                }

                Directory.Delete(appOut + tempEntry.file.Replace('.', '_') + "_out", true);
            }

            //Repack app
            Wii.U8.PackU8(appOut, savePath);

            CsmFinish finish = new CsmFinish(this._csmFinish);

            this.Invoke(finish, savePath, mymPath);
        }
Exemple #10
0
 public static mymini LoadIni(string iniPath)
 {
     mymini m = new mymini();
     m.iniFile = iniPath;
     m.ParseIni();
     return m;
 }
Exemple #11
0
 public static mymini CreateIni(iniEntry[] iniEntries)
 {
     mymini m = new mymini();
     m.entries = new List<iniEntry>(iniEntries);
     return m;
 }