Пример #1
0
        /// <summary>
        /// Deletes a file from the MPQ. CALL openMPQ(); after this !!
        /// </summary>
        /// <param name="mpqHandle">Handle of the MPQ file.</param>
        /// <param name="fileName">Filename to delete</param>
        /// <param name="mpqFileName">MPQ file location (open for modification)</param>
        /// <param name="mpqCloseFunc">Function to close the MPQ file</param>
        /// <returns></returns>
        public static bool deleteFile(uint mpqHandle, string fileName, string mpqFileName, Action mpqCloseFunc)
        {
            uint hFile = 0;

            if (!Storm.SFileOpenFileEx(mpqHandle, fileName, 0, ref hFile))
            {
                throw new System.IO.FileNotFoundException("File not found in the MPQ: " + fileName);
            }

            if (hFile != 0)
            {
                Storm.SFileCloseFile(hFile);
            }

            System.Threading.Thread.Sleep(1000);
            mpqCloseFunc();

            int modMPQ = Storm.MpqOpenArchiveForUpdate(mpqFileName, Storm.MOAU_OPEN_EXISTING, uint.MaxValue);

            if (modMPQ != 0)
            {
                Storm.MpqDeleteFile(modMPQ, fileName);
            }
            else
            {
                throw new System.IO.IOException("ErrCode: " + Convert.ToString(Marshal.GetLastWin32Error()));
            }

            Storm.MpqCloseUpdatedArchive(modMPQ, 0);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Rebuild DIABDAT.MPQ from DIABDAT folder.
        /// </summary>
        public void RebuildDiabdat()
        {
            try
            {
                // create new mpq
                hMPQ = Storm.MpqOpenArchiveForUpdate(Environment.CurrentDirectory + "/diabdat.mpq", Storm.MOAU_CREATE_NEW, ushort.MaxValue);

                // read list file
                listFile = File.ReadAllLines(Environment.CurrentDirectory + "/EquineData/DIABDAT/DIABDAT.listfile.txt").ToList();

                // add files to mpq
                foreach (var file in listFile)
                {
                    // update the string
                    currentFile = file;

                    // check if file exists
                    if (File.Exists(Environment.CurrentDirectory + "\\EquineData\\DIABDAT\\" + file))
                    {
                        switch (Path.GetExtension(file))
                        {
                        // if the file is wav

                        case ".wav":
                        case ".WAV":
                            currentFile = currentFile + " (WAVE)";
                            Storm.MpqAddWaveToArchive(hMPQ, Environment.CurrentDirectory + "\\EquineData\\DIABDAT\\" + file, file, 0x00000001, 1);
                            break;

                        case ".smk":
                        case ".SMK":
                        case ".DUN":
                        case ".dun":
                        case ".MIN":
                        case ".min":
                        case ".SOL":
                        case ".sol":
                        case ".TIL":
                        case ".til":
                        case ".PAL":
                        case ".pal":
                        case ".AMP":
                        case ".amp":
                        case ".MPQ":
                        case ".mpq":
                            Storm.MpqAddFileToArchiveEx(hMPQ, Environment.CurrentDirectory + "\\EquineData\\DIABDAT\\" + file, file, 0x80000000, 0,
                                                        0);
                            break;

                        // if the file is not wav
                        default:
                            Storm.MpqAddFileToArchiveEx(hMPQ, Environment.CurrentDirectory + "\\EquineData\\DIABDAT\\" + file, file, 0x00000100 | 0x00010000, Storm.MAFA_COMPRESS_STANDARD,
                                                        0);
                            break;
                        }
                    }
                }

                Storm.MpqCloseUpdatedArchive(hMPQ, 0);
            }
            catch (Exception ex)
            {
                throw new System.IO.IOException("MPQ/Listfile I/O error.\n" + ex.ToString());
            }
        }