public bool Open(string path) { bool successful = false; try { string pakFilename = Path.GetFileNameWithoutExtension(path); PakCollection pakFile = new PakCollection(); pakFile.Open(path); PakRecord cfgRecord = GetCFGRecord(pakFilename, pakFile); if (cfgRecord == null) { throw new InvalidDataException("Unable to find a cfg file in the level pack."); } ParseCFG(UTF8Encoding.ASCII.GetString(cfgRecord.Buffer)); //Load levels foreach (LevelInfo linfo in mLevelInfos) { byte[] buffer = pakFile.GetRecord("levels\\" + linfo.Filename + ".dat").Buffer; LevelReader levelReader = new LevelReader(buffer); Level level = levelReader.Read(); levelReader.Dispose(); if (level == null) { MessageBox.Show("Unable to open " + linfo.Name, "Open Level Pack" , MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } mLevels.Add(level); level.Info = linfo; level.Background = GetBackground(pakFile, linfo.Filename); } //Load any images foreach (PakRecord record in pakFile) { if (record.FileName.StartsWith("levels\\")) continue; if (Path.GetExtension(record.FileName) == ".png") { mImages.Add(record.FileName, GetImageFromBuffer(record.Buffer)); } } successful = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Open Level Pack", MessageBoxButtons.OK, MessageBoxIcon.Error); } return successful; }
private void AddLevel(string name, string displayname, int acescore) { PakRecord record = mPakCollection.GetRecord("levels\\" + name + ".dat"); LevelReader reader = new LevelReader(record.Buffer); Level level = reader.Read(); reader.Dispose(); if (level == null) throw new Exception("Unable to read " + name); LevelInfo info = new LevelInfo(name, displayname, acescore, -3); level.Info = info; Image bgImage = GetBackground(name); level.Background = bgImage; mPack.Levels.Add(level); }
private void mnuLevelFolderImport_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Import level"; dialog.Filter = "Peggle Level Files (*.dat)|*.dat"; if (dialog.ShowDialog() == DialogResult.OK) { LevelReader lreader = new LevelReader(dialog.FileName); Level level = lreader.Read(); lreader.Dispose(); if (level != null) { LevelInfo info = LevelInfo.DefaultInfo; info.Filename = Path.GetFileNameWithoutExtension(dialog.FileName).ToLower(); info.Name = Path.GetFileNameWithoutExtension(dialog.FileName); level.Info = info; level.Background = OpenBackground(dialog.FileName); mPack.Levels.Add(level); LevelFolderNode.Nodes.Add(GetLevelNode(level)); } else { MessageBox.Show("This level could not be opened by " + Program.AppTitle + ".", "Import Level", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void OpenNewPackWithLevelImport(string path) { LevelReader reader = new LevelReader(path); Level level = reader.Read(); reader.Dispose(); NewPack(); if (level != null) { LevelInfo info = LevelInfo.DefaultInfo; info.Name = Path.GetFileNameWithoutExtension(path); level.Info = info; mPack.Levels.Clear(); mPack.Levels.Add(level); OpenLevel(level); } UpdatePackExplorerView(); }