Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string bjpath = textBox1.Text;
            string cjpath = Application.StartupPath + @"\pjass\common.j";

            if (!File.Exists(bjpath))
            {
                MessageBox.Show("invalid blizzard.j path!"); return;
            }
            if (openMapDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            MpqLib.Mpq.CArchive map      = new MpqLib.Mpq.CArchive(openMapDialog.FileName);
            string[]            listfile = GenerateMapFilelist(map);
            if (saveMpqDialog.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(saveMpqDialog.FileName))
                {
                    File.Delete(saveMpqDialog.FileName);
                }
                //==================
                MpqLib.Mpq.CArchive mpq = new MpqLib.Mpq.CArchive(saveMpqDialog.FileName, true, MpqLib.Mpq.EArchiveFormat.Version1, 10000);
                //添加地图内文件
                for (int i = 0; i < listfile.Length; i++)
                {
                    MpqLib.Mpq.CFileStream file = new MpqLib.Mpq.CFileStream(map, listfile[i]);
                    byte[] fileb = new byte[file.Length];
                    fileb = file.Read((int)file.Length);
                    file.Close();
                    mpq.ImportFile(listfile[i], fileb);
                    fileb = null;

                    /*
                     * if (map.FileExists(listfile[i]))
                     * {
                     *  if (File.Exists("temp")) { File.Delete("temp"); }
                     *  map.ExportFile(listfile[i], "temp");
                     *  mpq.ImportFile(listfile[i], "temp");
                     * }
                     */
                }
                map.Close();
                //添加blizzard.j
                mpq.ImportFile(@"Scripts\Blizzard.j", bjpath);
                //添加blizzard.j
                mpq.ImportFile(@"Scripts\common.j", cjpath);
                //添加additional resources...
                PackAllFileToMpq(textBox2.Text.Trim(), textBox2.Text.Trim(), mpq);
                //关闭mpq
                mpq.Flush();
                mpq.Compact();
                mpq.Close();
                //测试地图
                MessageBox.Show("Mpq generated at:" + Environment.NewLine + saveMpqDialog.FileName, "Finish!");
            }
        }
Exemple #2
0
        public Updater(Form1 parent, string patchMpqPath, string targetMpqPath, string gamePath, bool logging = true)
        {
            _parent = parent;
            doLogging = logging;
            nirPath = gamePath;

            PatchMPQ = new MpqLib.Mpq.CArchive(patchMpqPath);
            TargetMPQ = new MpqLib.Mpq.CArchive(targetMpqPath);
            MpqPath_for_del_listfile = targetMpqPath;

            // Import external listfile
            if (!TargetMPQ.FileExists("(listfile)"))
            {
                if (File.Exists("(listfile)")) TargetMPQ.ImportListFile("(listfile)");
                else return;
            }

            // Get version
            sourceVersion = "";
            destVersion = "";
            if (PatchMPQ.FileExists("(version)"))
            {
                var H_versionlist = new MpqLib.Mpq.CFileStream(PatchMPQ, "(version)");
                var versionlist_raw = new byte[H_versionlist.Length];
                versionlist_raw = H_versionlist.Read((int)H_versionlist.Length);
                H_versionlist.Close();
                string[] list = Encoding.ASCII.GetString(versionlist_raw).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                destVersion = list[0];
                if (list.Length > 1) sourceVersion = list[1];
            }

            // initialize progressBar
            if (_parent != null)
            {
                steps = PatchMPQ.FileCount;
                deletelist = readDeleteList();
                steps += deletelist.Length;
                exportlist = readExportList();
                steps += exportlist.Length;
                _parent.setProgressBarMax(steps);
            }
        }
Exemple #3
0
        public static string getGameVersion(string gamePath, string mpqName = "Nirvana.mpq")
        {
            gamePath = resolvePath(gamePath);
            string mpqPath = gamePath + mpqName;
            var Archive = new MpqLib.Mpq.CArchive(mpqPath);

            string version = "";
            try
            {
                if (Archive.FileExists("(version)"))
                {
                    var H_versionFile = new MpqLib.Mpq.CFileStream(Archive, "(version)");
                    var version_raw = new byte[H_versionFile.Length];
                    version_raw = H_versionFile.Read((int)H_versionFile.Length);
                    H_versionFile.Close();
                    version = Encoding.ASCII.GetString(version_raw);
                }
            }
            catch
            {
            }
            Archive.Close();
            return version;
        }
Exemple #4
0
 public string[] readExportList()
 {
     if (!PatchMPQ.FileExists("(export)"))
         return new string[] {};
     var H_exportlist = new MpqLib.Mpq.CFileStream(PatchMPQ, "(export)");
     var exportlist_raw = new byte[H_exportlist.Length];
     exportlist_raw = H_exportlist.Read((int)H_exportlist.Length);
     H_exportlist.Close();
     string[] list = Encoding.ASCII.GetString(exportlist_raw).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
     return list;
 }
Exemple #5
0
        // Adds all files from source mpq to target mpq
        public void AddAll(bool ignoreInternalFiles = true)
        {
            log("[Start Adding Files]");
            setStatus("Adding Files...");
            foreach (var file in PatchMPQ.FindFiles("*"))
            {
                // ignore internal files
                if (ignoreInternalFiles && DEFAULT_IGNORE_LIST.Contains(file.FileName))
                {
                    //log("Ignored - " + file.FileName);
                    _parent.incProgressBar();
                    continue;
                }

                // add files
                try
                {
                    var H_File = new MpqLib.Mpq.CFileStream(PatchMPQ, file.FileName);
                    Add(file.FileName, H_File);
                    //log("Added - " + file.FileName);
                }
                catch (Exception e)
                {
                    log("Error when adding file to mpq - " + e.Message);
                }
                _parent.incProgressBar();
            }
            log("[Finish Adding Files]");
        }
Exemple #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            string bjpath = textBox1.Text;
            string cjpath = Application.StartupPath + @"\pjass\common.j";
            if (!File.Exists(bjpath)) { MessageBox.Show("invalid blizzard.j path!"); return; }
            if (openMapDialog.ShowDialog() != DialogResult.OK) { return; }
            MpqLib.Mpq.CArchive map = new MpqLib.Mpq.CArchive(openMapDialog.FileName);
            string[] listfile = GenerateMapFilelist(map);
            if (saveMpqDialog.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(saveMpqDialog.FileName)) { File.Delete(saveMpqDialog.FileName); }
                //==================
                MpqLib.Mpq.CArchive mpq = new MpqLib.Mpq.CArchive(saveMpqDialog.FileName, true, MpqLib.Mpq.EArchiveFormat.Version1, 10000);
                //添加地图内文件
                for (int i = 0; i < listfile.Length; i++)
                {

                    MpqLib.Mpq.CFileStream file = new MpqLib.Mpq.CFileStream(map, listfile[i]);
                    byte[] fileb = new byte[file.Length];
                    fileb = file.Read((int)file.Length);
                    file.Close();
                    mpq.ImportFile(listfile[i], fileb);
                    fileb = null;

                    /*
                    if (map.FileExists(listfile[i]))
                    {
                        if (File.Exists("temp")) { File.Delete("temp"); }
                        map.ExportFile(listfile[i], "temp");
                        mpq.ImportFile(listfile[i], "temp");
                    }
                    */
                }
                map.Close();
                //添加blizzard.j
                mpq.ImportFile(@"Scripts\Blizzard.j", bjpath);
                //添加blizzard.j
                mpq.ImportFile(@"Scripts\common.j", cjpath);
                //添加additional resources...
                PackAllFileToMpq(textBox2.Text.Trim(), textBox2.Text.Trim(), mpq);
                //关闭mpq
                mpq.Flush();
                mpq.Compact();
                mpq.Close();
                //测试地图
                MessageBox.Show("Mpq generated at:"+Environment.NewLine+saveMpqDialog.FileName,"Finish!");
            }
        }