public void StartSave( string path ) { path += Name()+"/"; if( !Directory.Exists( path ) ) Directory.CreateDirectory( path ); try { GenericWriter idx = new BinaryFileWriter( path+Name()+".idx", false ); GenericWriter tdb = new BinaryFileWriter( path+Name()+".tdb", false ); GenericWriter bin = new BinaryFileWriter( path+Name()+".bin", true ); Console.Write( " - Saving {0}...", Name() ); Save( idx, tdb, bin ); idx.Close(); tdb.Close(); bin.Close(); Console.WriteLine( "Done." ); } catch( Exception err ) { Console.WriteLine( "Failed. Exception: "+err ); } }
public void Serialize() { FileInfo info = new FileInfo("Data/VoteSystem.cfg"); if (!info.Exists) { info.Create().Close(); } using (FileStream fs = info.Open(FileMode.Truncate, FileAccess.Write)) { GenericWriter writer = new BinaryFileWriter(fs, true); int version = 0; writer.Write(version); switch (version) { case 0: { writer.Write(_DefaultName); writer.Write(_DefaultURL); writer.Write(_DefaultCoolDown); } break; } writer.Close(); } }
public static void EventSink_WorldSave(WorldSaveEventArgs e) { if (!Directory.Exists(Path.Combine(Core.BaseDirectory, "Saves\\Duels"))) { Directory.CreateDirectory(Path.Combine(Core.BaseDirectory, "Saves\\Duels")); } GenericWriter writer = new BinaryFileWriter(SavePath, true); try { writer.Write((int)0); //version List <Serial> keyList = new List <Serial>(); List <DuelInfo> valueList = new List <DuelInfo>(); if (m_Infos == null) { m_Infos = new Dictionary <Serial, DuelInfo>(); } IDictionaryEnumerator myEnum = m_Infos.GetEnumerator(); while (myEnum.MoveNext()) { keyList.Add((Serial)myEnum.Key); valueList.Add((DuelInfo)myEnum.Value); } writer.Write(keyList.Count); for (int i = 0; i < keyList.Count; ++i) { writer.Write((int)keyList[i]); valueList[i].Serialize(writer); } if (m_Arenas == null) { m_Arenas = new List <DuelArena>(); } writer.Write(m_Arenas.Count); for (int i = 0; i < m_Arenas.Count; ++i) { m_Arenas[i].Serialize(writer); } writer.Write(m_Enabled); } catch (Exception ex) { Console.WriteLine(ex); } finally { writer.Close(); } }
public static void Save() { string basePath = Path.Combine("Saves", "CTFScore"); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } string idxPath = Path.Combine(basePath, "CTFLScore.idx"); string binPath = Path.Combine(basePath, "CTFLScore.bin"); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write((int)Players.Values.Count); foreach (CTFPlayer player in Players.Values) { long startPos = bin.Position; player.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } idx.Close(); bin.Close(); }
private static void OnSave(WorldSaveEventArgs e) { try{ if (!Directory.Exists("Saves/Commands/")) { Directory.CreateDirectory("Saves/Commands/"); } GenericWriter writer = new BinaryFileWriter(Path.Combine("Saves/Commands/", "Commands.bin"), true); writer.Write(0); // version ArrayList list = new ArrayList(s_Defaults.Values); writer.Write(list.Count); foreach (DefaultInfo info in list) { writer.Write(info.NewCommand); writer.Write(info.OldCommand); writer.Write((int)info.NewAccess); } writer.Close(); }catch { Errors.Report("Commands-> OnSave"); } }
protected static void SaveMobiles(List <Mobile> moblist) { GenericWriter idx = new BinaryFileWriter(MobileIndexPath, false); GenericWriter tdb = new BinaryFileWriter(MobileTypesPath, false); GenericWriter bin = new BinaryFileWriter(MobileDataPath, true); idx.Write(moblist.Count); foreach (Mobile m in moblist) { long start = bin.Position; idx.Write(m.TypeRef); idx.Write(m.Serial); idx.Write(start); m.Serialize(bin); idx.Write((int)(bin.Position - start)); m.FreeCache(); } tdb.Write(World.MobileTypes.Count); foreach (Type t in World.MobileTypes) { tdb.Write(t.FullName); } idx.Close(); tdb.Close(); bin.Close(); }
/// <summary> /// Saves persistent data /// </summary> private static void OnWorldSave(WorldSaveEventArgs args) { if (!Directory.Exists(DataPath)) { Directory.CreateDirectory(DataPath); } BinaryFileWriter writer = new BinaryFileWriter(DataFile, true); writer.Write((int)0); //version writer.Write((int)PerkTable.Count); foreach (KeyValuePair <Player, Tuple <Perk, Perk> > kvp in PerkTable) { if (kvp.Key == null || kvp.Key.Deleted) { continue; } writer.WriteMobile <Player>(kvp.Key); writer.Write(kvp.Value.Item1.GetType().FullName); kvp.Value.Item1.Serialize(writer); writer.Write(kvp.Value.Item2.GetType().FullName); kvp.Value.Item2.Serialize(writer); } writer.Close(); }
public void ReadByteTest() { File file = new File(System.IO.Path.Combine(TestDirectory, "Test1.bin")); try { BinaryFileWriter target = new BinaryFileWriter(file, Encoding.UTF32); byte b = 10; target.WriteByte(b); target.Close(); BinaryFileReader r = new BinaryFileReader(file); byte c = r.ReadByte(); Assert.AreEqual(b, c, "Should be equal"); r.Close(); } catch (Exception e) { Assert.Fail(e.ToString()); } }
private static void SaveLists() { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } BinaryFileWriter writer = new BinaryFileWriter(SaveFile, true); writer.Write((int)_userListTable.Count); if (_userListTable.Count > 0) { foreach (KeyValuePair <Mobile, ChatInfo> kvp in _userListTable) { if (kvp.Key == null || kvp.Key.Deleted || kvp.Value == null) { writer.Write((int)-1); } else { writer.Write((int)kvp.Key.Serial); kvp.Value.Serialize(writer); } } } writer.Close(); ChatMessageManager.SerializeMessages(); }
// Saves blue mage information to it's own file at Saves/BlueMagic/. public static void Save(WorldSaveEventArgs e) { if (!Directory.Exists("Saves/BlueMagic/")) { Directory.CreateDirectory("Saves/BlueMagic/"); } if (BlueMageSpells.Keys.Count > 0) { BinaryFileWriter writer = new BinaryFileWriter("Saves/BlueMagic/MobileAndSpellList.bin", false); writer.Write((int)BlueMageSpells.Keys.Count); writer.Write((int)SPELLCOUNT); foreach (KeyValuePair <Serial, bool[]> kvp in BlueMageSpells) { writer.Write((Serial)kvp.Key); for (int j = 0; j < kvp.Value.Length; j++) { writer.Write((bool)kvp.Value[j]); } } writer.Close(); PrintBlueMageLog(); } }
public static void OnSave(WorldSaveEventArgs e) { Console.WriteLine("ResourceLogger saving..."); if (!Directory.Exists("Saves/ResourcePool")) { Directory.CreateDirectory("Saves/ResourcePool"); } if (!Directory.Exists("Saves/ResourcePool/TransactionHistories")) { Directory.CreateDirectory("Saves/ResourcePool/TransactionHistories"); } BinaryFileWriter writer = new BinaryFileWriter(new FileStream("Saves/ResourcePool/Logger.dat", FileMode.Create, FileAccess.Write), true); writer.Write((int)0); // version // version 0 writer.Write((int)m_LogLevel); writer.Write((long)m_TransID); writer.Close(); foreach (Mobile m in m_History.Keys) { ArrayList list = (ArrayList)m_History[m]; writer = new BinaryFileWriter(new FileStream("Saves/ResourcePool/TransactionHistories/" + m.Serial.Value.ToString() + ".dat", FileMode.Create, FileAccess.Write), true); writer.Write((int)list.Count); foreach (ResourceTransaction rt in list) { rt.Serialize(writer); } writer.Close(); } }
public static void Save() { if (!Directory.Exists("Saves/FS Systems/FSBounty")) { Directory.CreateDirectory("Saves/FS Systems/FSBounty"); } string idxPath = Path.Combine("Saves/FS Systems/FSBounty", "BountyTable.idx"); string binPath = Path.Combine("Saves/FS Systems/FSBounty", "BountyTable.bin"); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write((int)BountyTable.Values.Count); foreach (Bounty b in BountyTable.Values) { long startPos = bin.Position; b.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } idx.Close(); bin.Close(); }
public static void Save() { Console.Write("DonatorAccountSettings: Saving..."); if (!Directory.Exists("Saves/Donation/")) { Directory.CreateDirectory("Saves/Donation/"); } string idxPath = Path.Combine("Saves/Donation", "DonatorAccountSettings.idx"); string binPath = Path.Combine("Saves/Donation", "DonatorAccountSettings.bin"); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write((int)DonatorAccountSettingsTable.Values.Count); foreach (DonatorAccountSettings das in DonatorAccountSettingsTable.Values) { long startPos = bin.Position; das.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } idx.Close(); bin.Close(); Console.WriteLine("done"); }
public static void OnSave(WorldSaveEventArgs e) { try { Console.WriteLine("KinCityManager Saving..."); if (!Directory.Exists("Saves/AngelIsland")) { Directory.CreateDirectory("Saves/AngelIsland"); } string filePath = Path.Combine("Saves/AngelIsland", "KinCityManager.bin"); GenericWriter writer; writer = new BinaryFileWriter(filePath, true); writer.Write(1); //version //v1 below //write out the city data class' writer.Write(_cityData.Count); foreach (KeyValuePair <KinFactionCities, KinCityData> pair in _cityData) { pair.Value.Save(writer); } writer.Close(); } catch (Exception ex) { System.Console.WriteLine("Error saving KinCityManager!"); Scripts.Commands.LogHelper.LogException(ex); } }
public void StartSave(string path) { path += Name() + "/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } try { GenericWriter idx = new BinaryFileWriter(path + Name() + ".idx", false); GenericWriter tdb = new BinaryFileWriter(path + Name() + ".tdb", false); GenericWriter bin = new BinaryFileWriter(path + Name() + ".bin", true); Console.Write(" - Saving {0}...", Name()); Save(idx, tdb, bin); idx.Close(); tdb.Close(); bin.Close(); Console.WriteLine("Done."); } catch (Exception err) { Console.WriteLine("Failed. Exception: " + err); } }
public static void SerializeMessages() { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } BinaryFileWriter writer = new BinaryFileWriter(SaveFile, true); writer.Write((int)_messageTable.Count); if (_messageTable.Count > 0) { foreach (KeyValuePair <Mobile, List <ChatMessage> > kvp in _messageTable) { if (kvp.Key == null || kvp.Key.Deleted || kvp.Value == null) { writer.Write((int)-1); } else { writer.Write((int)kvp.Key.Serial); writer.Write((int)kvp.Value.Count); kvp.Value.ForEach( delegate(ChatMessage message) { message.Serialize(writer); }); } } } writer.Close(); }
protected void SaveGuilds() { GenericWriter idx = new BinaryFileWriter(World.GuildIndexPath, false); GenericWriter tdb = new BinaryFileWriter(World.GuildTypesPath, false); GenericWriter bin = new BinaryFileWriter(World.GuildDataPath, true); idx.Write(BaseGuild.List.Count); foreach (var guild in BaseGuild.List.Values) { var start = bin.Position; idx.Write(guild.m_TypeRef); idx.Write(guild.Serial); idx.Write(start); guild.Serialize(bin); idx.Write((int)(bin.Position - start)); } tdb.Write(World.m_GuildTypes.Count); for (var i = 0; i < World.m_GuildTypes.Count; ++i) { tdb.Write(World.m_GuildTypes[i].FullName); } idx.Close(); tdb.Close(); bin.Close(); }
public static void Save() { try { if (!Directory.Exists(General.SavePath)) { Directory.CreateDirectory(General.SavePath); } GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "Channels.bin"), true); writer.Write(0); // version writer.Write(s_Channels.Count); foreach (Channel c in s_Channels) { writer.Write(c.GetType().ToString()); c.Save(writer); } writer.Close(); } catch (Exception e) { Errors.Report(General.Local(187)); Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } }
private static void Serialize() { if (!Directory.Exists(m_Directory)) { Directory.CreateDirectory(m_Directory); } GenericWriter writer = new BinaryFileWriter(m_FilePath, true); writer.Write(0);//version writer.Write(m_Messages.Count - 1); for (int i = 1; i < m_Messages.Count; i++) { MotDStruct mds = (MotDStruct)m_Messages[i]; writer.Write(mds.Subject); writer.Write(mds.Body); writer.Write(mds.Links.Count); for (int j = 0; j < mds.Links.Count; j++) { writer.Write((string)mds.Links[j]); } } writer.Close(); }
public void Serialize() { //Console.WriteLine("[Vote System]: Saving Config..."); FileInfo info = new FileInfo("Data\\VoteSystem.cfg"); if (!info.Exists) { info.Create().Close(); } using (FileStream fs = info.Open(FileMode.Truncate, FileAccess.Write)) { BinaryFileWriter bin = new BinaryFileWriter(fs, true); bin.Write(1); //version //version 1 bin.Write(_DefaultGold); //version 0 bin.Write(_DefaultName); bin.Write(_DefaultURL); bin.Write(_DefaultCoolDown); bin.Close(); } //Console.WriteLine("[Vote System]: Done."); }
public static void Save() { if (!Directory.Exists("Saves/FriendLists/")) { Directory.CreateDirectory("Saves/FriendLists/"); } string idxPath = Path.Combine("Saves/FriendLists", "FriendLists.idx"); string binPath = Path.Combine("Saves/FriendLists", "FriendLists.bin"); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write((int)FriendLists.Values.Count); foreach (FriendList fl in FriendLists.Values) { long startPos = bin.Position; fl.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } idx.Close(); bin.Close(); }
static void EventSink_WorldSave(WorldSaveEventArgs e) { List <LogObject> toremove = new List <LogObject>(); foreach (LogObject l in logs) { if (l.mob.Deleted) { toremove.Add(l); } } foreach (LogObject l in toremove) { logs.Remove(l); } BinaryFileWriter bn = new BinaryFileWriter(m_File, true); bn.Write((int)logs.Count); for (int i = 0; i < logs.Count; i++) { bn.Write(logs[i].mob); bn.Write(logs[i].message); } bn.Close(); }
//generates or updates .plg files public static void SavePluginSettings(TMPluginSave plugin) { if (pluginExists(plugin.getName())) { if (!Directory.Exists(loc)) { Directory.CreateDirectory(loc); } string FileName = plugin.getName() + ".plg"; string path = loc + FileName; Console.Write(" - Saving Settings for TMPlugin " + plugin.getName() + "..."); try { using (FileStream m_FileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) { BinaryFileWriter writer = new BinaryFileWriter(m_FileStream, true); plugin.SavePlugin(writer); writer.Close(); m_FileStream.Close(); } Console.WriteLine("done."); } catch (Exception e) { SkillSettings.DoTell(" TMPlugin " + plugin + " could not be saved. Error: " + e); } } else { SkillSettings.DoTell(" TMPlugin " + plugin + " not registered to system. Save cannot continue."); } }
private static void EventSink_WorldSave(WorldSaveEventArgs e) { int queue = 0; int deleted = RemovedDeletedQueue(out queue); if (queue != 0) { Console.Write("{0} Forum Posts Deleted...", deleted); } string SavePath = Path.Combine(m_SavePath, "forumdata.sig"); if (!Directory.Exists(m_SavePath)) { Directory.CreateDirectory(m_SavePath); } GenericWriter bin = new BinaryFileWriter(SavePath, true); try { bin.Write(( int )0); //Versioning WritePlayerStatistics(bin); bin.Write(( int )(m_Threads.Count)); foreach (ThreadEntry te in m_Threads) { te.Serialize(bin); } bin.WriteMobileList(m_Moderators); bin.Write(( int )m_ThreadDeleteAccessLevel); bin.Write(( int )m_ThreadLockAccesLevel); bin.Write(( bool )m_AutoCleanup); bin.Write(( int )m_AutoCleanupDays); bin.Write(( int )m_MinPostCharactersCount); bin.Write(( int )m_MaxPostCharactersCount); bin.Close(); } catch (Exception err) { bin.Close(); Console.Write("An error occurred while trying to save the forums. {0}", err.ToString()); } }
public static void Save(WorldSaveEventArgs args) { if (!Directory.Exists("Saves/ACC")) { Directory.CreateDirectory("Saves/ACC"); } string filename = "acc.sav"; string path = @"Saves/ACC/"; string pathNfile = path + filename; DateTime start = DateTime.Now; Console.WriteLine(); Console.WriteLine(); Console.WriteLine("----------"); Console.WriteLine("Saving ACC..."); try { using (FileStream m_FileStream = new FileStream(pathNfile, FileMode.OpenOrCreate, FileAccess.Write)) { BinaryFileWriter writer = new BinaryFileWriter(m_FileStream, true); writer.Write((int)m_RegSystems.Count); foreach (KeyValuePair <string, bool> kvp in m_RegSystems) { Type t = ScriptCompiler.FindTypeByFullName(kvp.Key); if (t != null) { writer.Write(kvp.Key); writer.Write(kvp.Value); if (kvp.Value) { ACCSystem system = (ACCSystem)Activator.CreateInstance(t); if (system != null) { system.StartSave(path); } } } } writer.Close(); m_FileStream.Close(); } Console.WriteLine("Done in {0:F1} seconds.", (DateTime.Now - start).TotalSeconds); Console.WriteLine("----------"); Console.WriteLine(); } catch (Exception err) { Console.WriteLine("Failed. Exception: " + err); } }
public static void SaveGlobalOptions() { CleanUpData(); if (!Directory.Exists(General.SavePath)) { Directory.CreateDirectory(General.SavePath); } GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "GlobalOptions.bin"), true); writer.Write(2); // version writer.Write(s_MultiPort); writer.Write(s_MultiServer); writer.Write(s_Notifications.Count); foreach (Notification not in s_Notifications) { not.Save(writer); } writer.Write(s_Filters.Count); foreach (string str in s_Filters) { writer.Write(str); } writer.Write((int)s_FilterPenalty); writer.Write((int)s_MacroPenalty); writer.Write(s_MaxMsgs); writer.Write(s_ChatSpam); writer.Write(s_MsgSpam); writer.Write(s_RequestSpam); writer.Write(s_FilterBanLength); writer.Write(s_FilterWarnings); writer.Write(s_AntiMacroDelay); writer.Write(s_IrcPort); writer.Write(s_IrcMaxAttempts); writer.Write(s_IrcEnabled); writer.Write(s_IrcAutoConnect); writer.Write(s_IrcAutoReconnect); writer.Write(s_FilterSpeech); writer.Write(s_FilterMsg); writer.Write(s_Debug); writer.Write(s_LogChat); writer.Write(s_LogPms); writer.Write((int)s_IrcStaffColor); writer.Write(s_IrcServer); writer.Write(s_IrcRoom); writer.Write(s_IrcNick); writer.Write(s_TotalChats + 1); writer.Close(); }
public static void SaveBackup(Mobile mobile, ArrayList ArgsList) { MC.SetProcess(Process.SaveBackup); if (!Directory.Exists(MC.BackupDirectory)) { Directory.CreateDirectory(MC.BackupDirectory); } string path = Path.Combine(MC.BackupDirectory, "Backup.mbk"); mobile.SendMessage("Creating backup file..."); MC.CheckSpawners(); ArrayList SpawnerList = CompileSpawnerList(); GenericWriter writer; try { writer = new BinaryFileWriter(path, true); } catch (Exception ex) { MC.SetProcess(Process.None); ArgsList[2] = "Create Backup File"; ArgsList[4] = String.Format("Exception caught:\n{0}", ex); mobile.SendGump(new FileMenuGump(mobile, ArgsList)); return; } writer.Write(SpawnerList.Count); try { foreach (MegaSpawner megaSpawner in SpawnerList) { Serialize(megaSpawner, writer); } } catch {} writer.Close(); MC.SetProcess(Process.None); ArgsList[2] = "Create Backup File"; ArgsList[4] = "All Mega Spawners have now been backed up to the backup file."; mobile.SendGump(new FileMenuGump(mobile, ArgsList)); }
private static void Serialize(WorldSaveEventArgs e) { if (!Directory.Exists(m_Directory)) { Directory.CreateDirectory(m_Directory); } GenericWriter writer = new BinaryFileWriter(m_FilePath, true); writer.Write(Version);//version writer.Close(); }
protected override void OnTarget(Mobile from, object targeted) { if (!(targeted is Container)) { from.SendMessage("Only containers can be dumped."); return; } Container cont = (Container)targeted; try { using (FileStream idxfs = new FileStream(m_Filename + ".idx", FileMode.Create, FileAccess.Write, FileShare.None)) { using (FileStream binfs = new FileStream(m_Filename + ".bin", FileMode.Create, FileAccess.Write, FileShare.None)) { GenericWriter idx = new BinaryFileWriter(idxfs, true); GenericWriter bin = new BinaryFileWriter(binfs, true); ArrayList items = new ArrayList(); items.Add(cont); items.AddRange(cont.GetDeepItems()); idx.Write((int)items.Count); foreach (Item item in items) { long start = bin.Position; idx.Write(item.GetType().FullName); // <--- DIFFERENT FROM WORLD SAVE FORMAT! idx.Write((int)item.Serial); idx.Write((long)start); item.Serialize(bin); idx.Write((int)(bin.Position - start)); } idx.Close(); bin.Close(); } } from.SendMessage("Container successfully dumped to {0}.", m_Filename); } catch (Exception e) { LogHelper.LogException(e); Console.WriteLine(e.ToString()); from.SendMessage("Exception: {0}", e.Message); } }
private static void OnSave(WorldSaveEventArgs e) { try{ if (!Directory.Exists("Saves/Gumps/")) { Directory.CreateDirectory("Saves/Gumps/"); } GenericWriter writer = new BinaryFileWriter(Path.Combine("Saves/Gumps/", "Gumps.bin"), true); writer.Write(0); // version ArrayList list = new ArrayList(); GumpInfo info; foreach (object o in new ArrayList(s_Infos.Values)) { if (!(o is Hashtable)) { continue; } foreach (object ob in new ArrayList(((Hashtable)o).Values)) { if (!(ob is GumpInfo)) { continue; } info = (GumpInfo)ob; if (info.Mobile != null && info.Mobile.Player && !info.Mobile.Deleted && info.Mobile.Account != null && ((Account)info.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays(30)) { list.Add(ob); } } } writer.Write(list.Count); foreach (GumpInfo ginfo in list) { ginfo.Save(writer); } writer.Close(); }catch { Errors.Report("GumpInfo-> OnSave"); } }
public void Save() { bool fileExists = false; if (s_Path == null) { return; } if (All.Count == 0) { if (File.Exists(s_Path)) { try { File.Delete(s_Path); } catch { // ... could not delete? } } return; } if (File.Exists(s_Path)) { fileExists = true; File.Copy(s_Path, s_Path + ".bak", true); } try { Tracer.Debug("Saving macros..."); BinaryFileWriter writer = new BinaryFileWriter(s_Path, false); Serialize(writer); writer.Close(); writer = null; } catch (Exception e) { Tracer.Warn(string.Format("Error saving macros: {0}", e.Message)); Tracer.Debug("Attempting to restore old macros..."); if (fileExists) { File.Copy(s_Path + ".bak", s_Path); } Tracer.Debug("Old macros restored."); } }
public static void Save() { if (!Directory.Exists("Saves/Lottery/")) Directory.CreateDirectory("Saves/Lottery/"); string idxPath = Path.Combine("Saves/Lottery", "Lottery.idx"); string binPath = Path.Combine("Saves/Lottery", "Lottery.bin"); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); long startPos = bin.Position; Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); idx.Close(); bin.Close(); }
public void Serialize() { //Console.WriteLine("[Vote System]: Saving Config..."); FileInfo info = new FileInfo("Data\\VoteSystem.cfg"); if (!info.Exists) info.Create().Close(); using(FileStream fs = info.Open(FileMode.Truncate, FileAccess.Write)) { BinaryFileWriter bin = new BinaryFileWriter(fs, true); bin.Write(1); //version //version 1 bin.Write(_DefaultGold); //version 0 bin.Write(_DefaultName); bin.Write(_DefaultURL); bin.Write(_DefaultCoolDown); bin.Close(); } //Console.WriteLine("[Vote System]: Done."); }
protected static void SaveMobiles(List<Mobile> moblist) { GenericWriter idx = new BinaryFileWriter(MobileIndexPath, false); GenericWriter tdb = new BinaryFileWriter(MobileTypesPath, false); GenericWriter bin = new BinaryFileWriter(MobileDataPath, true); idx.Write(moblist.Count); foreach (Mobile m in moblist) { long start = bin.Position; idx.Write(m.TypeRef); idx.Write(m.Serial); idx.Write(start); m.Serialize(bin); idx.Write((int) (bin.Position - start)); m.FreeCache(); } tdb.Write(World.MobileTypes.Count); foreach (Type t in World.MobileTypes) { tdb.Write(t.FullName); } idx.Close(); tdb.Close(); bin.Close(); }
protected void SaveMobiles() { Dictionary<Serial, Mobile> mobiles = World.Instance.m_Mobiles; GenericWriter idx = new BinaryFileWriter( World.MobileIndexPath, false ); GenericWriter tdb = new BinaryFileWriter( World.MobileTypesPath, false ); GenericWriter bin = new BinaryFileWriter( World.MobileDataPath, true ); idx.Write( (int) mobiles.Count ); foreach ( Mobile m in mobiles.Values ) { long start = bin.Position; idx.Write( (int) m.m_TypeRef ); idx.Write( (int) m.Serial ); idx.Write( (long) start ); m.Serialize( bin ); idx.Write( (int) ( bin.Position - start ) ); if ( m is IVendor ) { IVendor vendor = m as IVendor; if ( ( vendor.LastRestock + vendor.RestockDelay ) < DateTime.Now ) m_RestockQueue.Enqueue( vendor ); } m.FreeCache(); } tdb.Write( (int) World.m_MobileTypes.Count ); for ( int i = 0; i < World.m_MobileTypes.Count; ++i ) tdb.Write( World.m_MobileTypes[i].FullName ); idx.Close(); tdb.Close(); bin.Close(); }
protected void SaveGuilds() { GenericWriter idx = new BinaryFileWriter( World.GuildIndexPath, false ); GenericWriter tdb = new BinaryFileWriter( World.GuildTypesPath, false ); GenericWriter bin = new BinaryFileWriter( World.GuildDataPath, true ); idx.Write( (int) BaseGuild.List.Count ); foreach ( BaseGuild guild in BaseGuild.List.Values ) { long start = bin.Position; idx.Write( (int) guild.m_TypeRef ); idx.Write( (int) guild.Serial ); idx.Write( (long) start ); guild.Serialize( bin ); idx.Write( (int) ( bin.Position - start ) ); } tdb.Write( (int) World.m_GuildTypes.Count ); for ( int i = 0; i < World.m_GuildTypes.Count; ++i ) tdb.Write( World.m_GuildTypes[i].FullName ); idx.Close(); tdb.Close(); bin.Close(); }
private void SaveTypeDatabase( string path, List<Type> types ) { BinaryFileWriter bfw = new BinaryFileWriter( path, false ); bfw.Write( types.Count ); foreach ( Type type in types ) { bfw.Write( type.FullName ); } bfw.Flush(); bfw.Close(); }
private byte[] InternalGetBlockEntryBytes() { byte[] data; BinaryFileWriter mem_writer = new BinaryFileWriter(new MemoryStream(), false); for (int i = 0; i < m_Header.BlockCount; i++) m_BlockEntries[i].Serialize(mem_writer); data = ((MemoryStream)mem_writer.UnderlyingStream).ToArray(); mem_writer.Close(); mem_writer = null; return data; }
private static void Serialize(WorldSaveEventArgs e) { if (!Directory.Exists(m_Directory)) Directory.CreateDirectory(m_Directory); GenericWriter writer = new BinaryFileWriter(m_FilePath, true); writer.Write(Version);//version writer.Close(); }
public static void Save() { if (!Directory.Exists( "Saves/FS Systems/FSBounty" ) ) Directory.CreateDirectory( "Saves/FS Systems/FSBounty" ); string idxPath = Path.Combine( "Saves/FS Systems/FSBounty", "BountyTable.idx" ); string binPath = Path.Combine( "Saves/FS Systems/FSBounty", "BountyTable.bin" ); GenericWriter idx = new BinaryFileWriter( idxPath, false ); GenericWriter bin = new BinaryFileWriter( binPath, true ); idx.Write( (int)BountyTable.Values.Count ); foreach ( Bounty b in BountyTable.Values ) { long startPos = bin.Position; b.Serialize( bin ); idx.Write( (long)startPos ); idx.Write( (int)( bin.Position - startPos ) ); } idx.Close(); bin.Close(); }
public static void Save() { if (!Directory.Exists("Saves/FriendLists/")) Directory.CreateDirectory("Saves/FriendLists/"); string idxPath = Path.Combine( "Saves/FriendLists", "FriendLists.idx" ); string binPath = Path.Combine( "Saves/FriendLists", "FriendLists.bin" ); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write( (int)FriendLists.Values.Count ); foreach ( FriendList fl in FriendLists.Values ) { long startPos = bin.Position; fl.Serialize( bin ); idx.Write( (long)startPos ); idx.Write( (int)(bin.Position - startPos) ); } idx.Close(); bin.Close(); }
public static void SaveFights() { GenericWriter idx = new BinaryFileWriter(fightIdxPath, false); GenericWriter bin = new BinaryFileWriter(fightBinPath, true); idx.Write((int)fights.Count); foreach (Fight f in fights) { long startPos = bin.Position; f.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } idx.Close(); bin.Close(); }
public static void SaveDuels() { GenericWriter idx = new BinaryFileWriter(duelIdxPath, false); GenericWriter bin = new BinaryFileWriter(duelBinPath, true); idx.Write((int)duels.Count); foreach (DuelObject d in duels) { if (!d.Player1.Deleted && !d.Player2.Deleted) { long startPos = bin.Position; d.Serialize(bin); idx.Write((long)startPos); idx.Write((int)(bin.Position - startPos)); } } idx.Close(); bin.Close(); }
public static void SaveArenas() { GenericWriter bin = new BinaryFileWriter(arenaBinPath, true); bin.WriteItemList(arenas, true); bin.Close(); }
public static void SaveDuellers() { GenericWriter bin = new BinaryFileWriter(duellersBinPath, true); bin.WriteMobileList(duellers, true); bin.Close(); }
private static void EventSink_WorldSave( WorldSaveEventArgs e ) { int queue = 0; int deleted = RemovedDeletedQueue(out queue); if ( queue != 0 ) Console.Write( "{0} Forum Posts Deleted...", deleted ); string SavePath = Path.Combine( m_SavePath, "forumdata.sig" ); if( !Directory.Exists( m_SavePath ) ) Directory.CreateDirectory( m_SavePath ); GenericWriter bin = new BinaryFileWriter( SavePath, true ); try { bin.Write( ( int )0 );//Versioning WritePlayerStatistics( bin ); bin.Write( ( int )( m_Threads.Count ) ); foreach( ThreadEntry te in m_Threads ) { te.Serialize( bin ); } bin.WriteMobileList( m_Moderators ); bin.Write( ( int )m_ThreadDeleteAccessLevel ); bin.Write( ( int )m_ThreadLockAccesLevel ); bin.Write( ( bool )m_AutoCleanup ); bin.Write( ( int )m_AutoCleanupDays ); bin.Write( ( int )m_MinPostCharactersCount ); bin.Write( ( int )m_MaxPostCharactersCount ); bin.Close(); } catch( Exception err ) { bin.Close(); Console.Write( "An error occurred while trying to save the forums. {0}", err.ToString()); } }
private static void Serialize() { if (!Directory.Exists(m_Directory)) Directory.CreateDirectory(m_Directory); GenericWriter writer = new BinaryFileWriter(m_FilePath, true); writer.Write(0);//version writer.Write(m_Messages.Count - 1); for (int i = 1; i < m_Messages.Count; i++) { MotDStruct mds = (MotDStruct)m_Messages[i]; writer.Write(mds.Subject); writer.Write(mds.Body); writer.Write(mds.Links.Count); for (int j = 0; j < mds.Links.Count; j++) writer.Write((string)mds.Links[j]); } writer.Close(); }
/// <summary> /// Saves persistent data /// </summary> private static void OnWorldSave( WorldSaveEventArgs args ) { if( !Directory.Exists(DataPath) ) Directory.CreateDirectory(DataPath); BinaryFileWriter writer = new BinaryFileWriter(DataFile, true); writer.Write((int)EoCTable.Count); foreach( KeyValuePair<Player, EoCContext> kvp in EoCTable ) { if( kvp.Key == null || kvp.Key.Deleted ) { writer.Write(false); } else { writer.Write(true); writer.WriteMobile<Player>(kvp.Key); kvp.Value.Serialize(writer); } } writer.Write((int)HitsTable.Count); foreach( KeyValuePair<Player, HitsTimer> kvp in HitsTable ) { if( kvp.Key != null && !kvp.Key.Deleted && kvp.Value.Running ) { writer.Write(true); writer.WriteMobile<Player>(kvp.Key); writer.Write(kvp.Value.Next); } else { writer.Write(false); } } writer.Close(); }
private byte[] InternalGetHashEntryBytes() { byte[] hash_entry_data; BinaryFileWriter mem_writer = new BinaryFileWriter(new MemoryStream(), false); for (int i = 0; i < m_Header.Hashcount; i++) { if (m_HashEntries[i] != null) m_HashEntries[i].Serialize(mem_writer); else LPKHashEntry.SerializeAsEmpty(mem_writer); } hash_entry_data = ((MemoryStream)mem_writer.UnderlyingStream).ToArray(); mem_writer.Close(); mem_writer = null; return hash_entry_data; }
public static void Save(WorldSaveEventArgs e) { if (MobileAttachments == null && ItemAttachments == null) { return; } CleanUp(); if (!Directory.Exists("Saves/Attachments")) { Directory.CreateDirectory("Saves/Attachments"); } string filePath = Path.Combine("Saves/Attachments", "Attachments.bin"); // the attachment serializations string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima"); // the item/mob attachment tables string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi"); // the file position indices BinaryFileWriter writer = null; BinaryFileWriter imawriter = null; BinaryFileWriter fpiwriter = null; try { writer = new BinaryFileWriter(filePath, true); imawriter = new BinaryFileWriter(imaPath, true); fpiwriter = new BinaryFileWriter(fpiPath, true); } catch (Exception err) { ErrorReporter.GenerateErrorReport(err.ToString()); return; } if (writer != null && imawriter != null && fpiwriter != null) { // save the current global attachment serial state ASerial.GlobalSerialize(writer); // remove all deleted attachments FullDefrag(); // save the attachments themselves if (AllAttachments != null) { writer.Write(AllAttachments.Count); var valuearray = new object[AllAttachments.Count]; AllAttachments.Values.CopyTo(valuearray, 0); var keyarray = new object[AllAttachments.Count]; AllAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key writer.Write((int)keyarray[i]); XmlAttachment a = valuearray[i] as XmlAttachment; // write the value type writer.Write(a.GetType().ToString()); // serialize the attachment itself a.Serialize(writer); // save the fileposition index fpiwriter.Write(writer.Position); } } else { writer.Write(0); } writer.Close(); // save the hash table info for items and mobiles // mobile attachments if (MobileAttachments != null) { imawriter.Write(MobileAttachments.Count); var valuearray = new object[MobileAttachments.Count]; MobileAttachments.Values.CopyTo(valuearray, 0); var keyarray = new object[MobileAttachments.Count]; MobileAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Mobile)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write(alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write(a.Serial.Value); // write the value type imawriter.Write(a.GetType().ToString()); // save the fileposition index fpiwriter.Write(imawriter.Position); } } } else { // no mobile attachments imawriter.Write(0); } // item attachments if (ItemAttachments != null) { imawriter.Write(ItemAttachments.Count); var valuearray = new object[ItemAttachments.Count]; ItemAttachments.Values.CopyTo(valuearray, 0); var keyarray = new object[ItemAttachments.Count]; ItemAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Item)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write(alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write(a.Serial.Value); // write the value type imawriter.Write(a.GetType().ToString()); // save the fileposition index fpiwriter.Write(imawriter.Position); } } } else { // no item attachments imawriter.Write(0); } imawriter.Close(); fpiwriter.Close(); } }
private static void EventSink_WorldSave(WorldSaveEventArgs e) { try { if (!Directory.Exists(SaveDirectory)) Directory.CreateDirectory(SaveDirectory); GenericWriter writer = new BinaryFileWriter(new FileStream(PointsFile, FileMode.OpenOrCreate), true); InternalSave(writer); writer.Close(); Console.WriteLine("Onsite Dueling System: DuelPoints saved!"); } catch (Exception ex) { Console.WriteLine("Onsite Dueling System: Save failed!"); Console.WriteLine("Caught an exception: {0}", ex.ToString()); } }
public static void Save() { Console.Write("DonatorAccountSettings: Saving..."); if (!Directory.Exists("Saves/Donation/")) Directory.CreateDirectory("Saves/Donation/"); string idxPath = Path.Combine( "Saves/Donation", "DonatorAccountSettings.idx" ); string binPath = Path.Combine( "Saves/Donation", "DonatorAccountSettings.bin" ); GenericWriter idx = new BinaryFileWriter(idxPath, false); GenericWriter bin = new BinaryFileWriter(binPath, true); idx.Write( (int)DonatorAccountSettingsTable.Values.Count ); foreach ( DonatorAccountSettings das in DonatorAccountSettingsTable.Values ) { long startPos = bin.Position; das.Serialize( bin ); idx.Write( (long)startPos ); idx.Write( (int)(bin.Position - startPos) ); } idx.Close(); bin.Close(); Console.WriteLine("done"); }
protected void SaveItems() { Dictionary<Serial, Item> items = World.Instance.m_Items; GenericWriter idx = new BinaryFileWriter( World.ItemIndexPath, false ); GenericWriter tdb = new BinaryFileWriter( World.ItemTypesPath, false ); GenericWriter bin = new BinaryFileWriter( World.ItemDataPath, true ); idx.Write( (int) items.Count ); foreach ( Item item in items.Values ) { if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) m_DecayQueue.Enqueue( item ); long start = bin.Position; idx.Write( (int) item.m_TypeRef ); idx.Write( (int) item.Serial ); idx.Write( (long) start ); item.Serialize( bin ); idx.Write( (int) ( bin.Position - start ) ); item.FreeCache(); } tdb.Write( (int) World.m_ItemTypes.Count ); for ( int i = 0; i < World.m_ItemTypes.Count; ++i ) tdb.Write( World.m_ItemTypes[i].FullName ); idx.Close(); tdb.Close(); bin.Close(); }
/* ID's: 101 = Button Manage System 102 = Button Import Page 103 = Button Apply Location 104 = Button Apply Category 105 = Text Name 106 = Text X 107 = Text Y 108 = Text Z 109 = Text Hue 110 = Text Cost 111 = Radio Trammel 112 = Radio Malas 113 = Radio Felucca 114 = Radio Ilshenar 115 = Radio Tokuno 116 = Check Generate 117 = Check StaffOnly 118 = Check Reds 119 = Check Charge 120 = Check Young 121 = Button Add Category 122 = Button Add Location 123 = Button Export 124 = Button Import Systems 125 = Button Import Categories 126 = Button Import Locations 300+ = Imports */ public override void OnResponse(NetState state, RelayInfo info, ACCGumpParams subParams) { if (info.ButtonID == 0 || state.Mobile.AccessLevel < ACC.GlobalMinimumAccessLevel) return; if (subParams is PGGumpParams) Params = subParams as PGGumpParams; PGGumpParams newParams = new PGGumpParams(); if (info.ButtonID == 101) newParams.Page = Pages.Manage; else if (info.ButtonID == 102) newParams.Page = Pages.Import; #region Add/Remove else if (info.ButtonID == 103 || info.ButtonID == 104 || info.ButtonID == 121 || info.ButtonID == 122) { SetFlag(EntryFlag.Generate, info.IsSwitched(116)); SetFlag(EntryFlag.StaffOnly, info.IsSwitched(117)); SetFlag(EntryFlag.Reds, info.IsSwitched(118)); SetFlag(EntryFlag.Charge, info.IsSwitched(119)); Map Map = info.IsSwitched(111) ? Map.Trammel : info.IsSwitched(112) ? Map.Malas : info.IsSwitched(113) ? Map.Felucca : info.IsSwitched(114) ? Map.Ilshenar : info.IsSwitched(115) ? Map.Tokuno : Map.Trammel; string Name = GetString(info, 105); string X = GetString(info, 106); string Y = GetString(info, 107); string Z = GetString(info, 108); string H = GetString(info, 109); string C = GetString(info, 110); if (Name == null || Name.Length == 0) { try { state.Mobile.SendMessage("Removed the entry"); if (info.ButtonID == 103) Params.SelectedCategory.Key.Locations.Remove(Params.SelectedLocation.Key); else m_CategoryList.Remove(Params.SelectedCategory.Key); } catch { Console.WriteLine("Exception caught removing entry"); } } else { if (info.ButtonID == 103 || info.ButtonID == 122) { int x, y, z, h, c = 0; Point3D Loc; int Hue; int Cost; PGLocation PGL; if (X == null || X.Length == 0 || Y == null || Y.Length == 0 || Z == null || Z.Length == 0 || H == null || H.Length == 0 || C == null || C.Length == 0) { if (info.ButtonID == 122) { Hue = 0; Loc = new Point3D(0, 0, 0); Cost = 0; PGL = new PGLocation(Name, Flags, Loc, Map, Hue, Cost); if (PGL == null) { state.Mobile.SendMessage("Error adding Location."); return; } m_CategoryList[Params.SelectedCategory.Value].Locations.Add(PGL); } state.Mobile.SendMessage("Please fill in each field."); state.Mobile.SendGump(new ACCGump(state.Mobile, this.ToString(), Params)); return; } try { x = Int32.Parse(X); y = Int32.Parse(Y); z = Int32.Parse(Z); h = Int32.Parse(H); c = Int32.Parse(C); Loc = new Point3D(x, y, z); Hue = h; Cost = c; } catch { state.Mobile.SendMessage("Please enter an integer in each of the info fields. (X, Y, Z, H, Cost)"); state.Mobile.SendGump(new ACCGump(state.Mobile, this.ToString(), Params)); return; } PGL = new PGLocation(Name, Flags, Loc, Map, Hue, Cost); if (PGL == null) { state.Mobile.SendMessage("Bad Location information, can't add!"); } else { try { if (info.ButtonID == 122) { m_CategoryList[Params.SelectedCategory.Value].Locations.Add(PGL); state.Mobile.SendMessage("Added the Location."); } else { state.Mobile.SendMessage("Changed the Location."); m_CategoryList[Params.SelectedCategory.Value].Locations[Params.SelectedLocation.Value] = PGL; } } catch { Console.WriteLine("Problem adding/changing Location!"); } } } else { if (C == null || C.Length == 0) { state.Mobile.SendMessage("Please fill in each field."); state.Mobile.SendGump(new ACCGump(state.Mobile, this.ToString(), Params)); return; } int c = 0; int Cost; try { c = Int32.Parse(C); Cost = c; } catch { state.Mobile.SendMessage("Please enter an integer for the Cost"); state.Mobile.SendGump(new ACCGump(state.Mobile, this.ToString(), Params)); return; } try { if (info.ButtonID == 121) { m_CategoryList.Add(new PGCategory(Name, Flags, Cost)); state.Mobile.SendMessage("Added the Category."); } else { m_CategoryList[Params.SelectedCategory.Value].Name = Name; m_CategoryList[Params.SelectedCategory.Value].Flags = Flags; m_CategoryList[Params.SelectedCategory.Value].Cost = Cost; state.Mobile.SendMessage("Changed the Category."); } } catch { Console.WriteLine("Problems adding/changing Category!"); } } } } #endregion //Add/Remove #region Imports/Exports #region Exports else if (info.ButtonID == 123) { if (!Directory.Exists("ACC Exports")) Directory.CreateDirectory("ACC Exports"); string fileName; string Path = "ACC Exports/"; if (Params.SelectedLocation.Key != null) fileName = String.Format("Location - {0}.pgl", Params.SelectedLocation.Key.Name); else if (Params.SelectedCategory.Key != null) fileName = String.Format("Category - {0}.pgc", Params.SelectedCategory.Key.Name); else fileName = String.Format("System - {0:yyMMdd-HHmmss}.pgs", DateTime.Now); try { using (FileStream m_FileStream = new FileStream(Path + fileName, FileMode.Create, FileAccess.Write)) { GenericWriter writer = new BinaryFileWriter(m_FileStream, true); if (Params.SelectedLocation.Key != null) { Params.SelectedLocation.Key.Serialize(writer); state.Mobile.SendMessage("Exported the Location to {0}{1}", Path, fileName); } else if (Params.SelectedCategory.Key != null) { Params.SelectedCategory.Key.Serialize(writer); state.Mobile.SendMessage("Exported the Category (and all Locations contained within) to {0}{1}", Path, fileName); } else { writer.Write((int)0); //version writer.Write(m_CategoryList.Count); for (int i = 0; i < m_CategoryList.Count; i++) { m_CategoryList[i].Serialize(writer); } state.Mobile.SendMessage("Exported the entire Public Gates System to {0}{1}", Path, fileName); } writer.Close(); m_FileStream.Close(); } } catch (Exception e) { state.Mobile.SendMessage("Problem exporting the selection. Please contact the admin."); Console.WriteLine("Error exporting PGSystem : {0}", e); } } #endregion //Exports #region Imports //Switch between import types else if (info.ButtonID == 124 || info.ButtonID == 125 || info.ButtonID == 126) { newParams.Page = Pages.Import; switch (info.ButtonID) { case 124: newParams.ImportSelection = ImportSelections.Systems; break; case 125: newParams.ImportSelection = ImportSelections.Categories; break; case 126: newParams.ImportSelection = ImportSelections.Locations; break; } } //Perform the import else if (info.ButtonID >= 300 && Dirs != null && Dirs.Length > 0) { if (!Directory.Exists("ACC Exports")) Directory.CreateDirectory("ACC Exports"); string Path = null; try { Path = Dirs[info.ButtonID - 300]; if (File.Exists(Path)) { using (FileStream m_FileStream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(m_FileStream)); switch ((int)Params.ImportSelection) { case (int)ImportSelections.Systems: {//Systems int version = reader.ReadInt(); int count = reader.ReadInt(); List<PGCategory> list = new List<PGCategory>(); for (int i = 0; i < count; i++) list.Add(new PGCategory(reader)); state.Mobile.CloseGump(typeof(SysChoiceGump)); state.Mobile.SendGump(new SysChoiceGump(this.ToString(), Params, list)); reader.Close(); return; } case (int)ImportSelections.Categories: {//Categories if (m_CategoryList == null) m_CategoryList = new List<PGCategory>(); m_CategoryList.Add(new PGCategory(reader)); state.Mobile.SendMessage("Added the Category."); break; } case (int)ImportSelections.Locations: {//Locations state.Mobile.CloseGump(typeof(CatSelGump)); state.Mobile.SendMessage("Please choose a Category to put this Location in."); state.Mobile.SendGump(new CatSelGump(this.ToString(), Params, new PGLocation(reader))); reader.Close(); return; } } reader.Close(); } } } catch { } } #endregion //Imports #endregion //Imports/Exports else if (info.ButtonID >= 150 && info.ButtonID < m_CategoryList.Count + 150) newParams.SelectedCategory = new KeyValuePair<PGCategory, int>(m_CategoryList[info.ButtonID - 150], info.ButtonID - 150); else if (info.ButtonID >= 200 && info.ButtonID < 200 + Params.SelectedCategory.Key.Locations.Count) { newParams.SelectedCategory = Params.SelectedCategory; newParams.SelectedLocation = new KeyValuePair<PGLocation, int>(Params.SelectedCategory.Key.Locations[info.ButtonID - 200], info.ButtonID - 200); } state.Mobile.SendGump(new ACCGump(state.Mobile, this.ToString(), newParams)); }
public static void Save(WorldSaveEventArgs e) { if (EntityAttachments == null) { return; } CleanUp(); if (!Directory.Exists("Saves/Attachments")) { Directory.CreateDirectory("Saves/Attachments"); } string filePath = Path.Combine("Saves/Attachments", "Attachments.bin"); // the attachment serializations string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima"); // the item/mob attachment tables string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi"); // the file position indices BinaryFileWriter writer = null; BinaryFileWriter imawriter = null; BinaryFileWriter fpiwriter = null; try { writer = new BinaryFileWriter(filePath, true); imawriter = new BinaryFileWriter(imaPath, true); fpiwriter = new BinaryFileWriter(fpiPath, true); } catch (Exception err) { ErrorReporter.GenerateErrorReport(err.ToString()); return; } if (writer != null && imawriter != null && fpiwriter != null) { // save the current global attachment serial state ASerial.GlobalSerialize(writer); // remove all deleted attachments FullDefrag(); // save the attachments themselves if (AllAttachments != null) { writer.Write(AllAttachments.Count); var valuearray = new XmlAttachment[AllAttachments.Count]; AllAttachments.Values.CopyTo(valuearray, 0); var keyarray = new int[AllAttachments.Count]; AllAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key writer.Write(keyarray[i]); XmlAttachment a = valuearray[i]; // write the value type writer.Write(a.GetType().ToString()); // serialize the attachment itself a.Serialize(writer); // save the fileposition index fpiwriter.Write(writer.Position); } } else { writer.Write(0); } writer.Close(); /* // Collapsed into a single IEntity Hash // save the hash table info for items and mobiles // mobile attachments if (XmlAttach.MobileAttachments != null) { imawriter.Write(XmlAttach.MobileAttachments.Count); object[] valuearray = new object[XmlAttach.MobileAttachments.Count]; XmlAttach.MobileAttachments.Values.CopyTo(valuearray, 0); object[] keyarray = new object[XmlAttach.MobileAttachments.Count]; XmlAttach.MobileAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Mobile)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write((int)alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write((int)a.Serial.Value); // write the value type imawriter.Write((string)a.GetType().ToString()); // save the fileposition index fpiwriter.Write((long)imawriter.Position); } } } else { // no mobile attachments imawriter.Write((int)0); } // item attachments if (XmlAttach.ItemAttachments != null) { imawriter.Write(XmlAttach.ItemAttachments.Count); object[] valuearray = new object[XmlAttach.ItemAttachments.Count]; XmlAttach.ItemAttachments.Values.CopyTo(valuearray, 0); object[] keyarray = new object[XmlAttach.ItemAttachments.Count]; XmlAttach.ItemAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write((Item)keyarray[i]); // write out the attachments ArrayList alist = (ArrayList)valuearray[i]; imawriter.Write((int)alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write((int)a.Serial.Value); // write the value type imawriter.Write((string)a.GetType().ToString()); // save the fileposition index fpiwriter.Write((long)imawriter.Position); } } } else { // no item attachments imawriter.Write((int)0); }*/ // Alan MOD // save the hash table info for items and mobiles // mobile attachments if (EntityAttachments != null) { imawriter.Write(EntityAttachments.Count); var valuearray = new ArrayList[EntityAttachments.Count]; EntityAttachments.Values.CopyTo(valuearray, 0); var keyarray = new int[EntityAttachments.Count]; EntityAttachments.Keys.CopyTo(keyarray, 0); for (int i = 0; i < keyarray.Length; i++) { // write the key imawriter.Write(keyarray[i]); // write out the attachments ArrayList alist = valuearray[i]; imawriter.Write(alist.Count); foreach (XmlAttachment a in alist) { // write the attachment serial imawriter.Write(a.Serial.Value); // write the value type imawriter.Write(a.GetType().ToString()); // save the fileposition index fpiwriter.Write(imawriter.Position); } } } else { // no mobile attachments imawriter.Write(0); } imawriter.Write(0); // pretend no item attachments and leave the deserialization as-is -- this way deserialization will still work with older saves -Alan // END ALAN MOD imawriter.Close(); fpiwriter.Close(); } }