本文整理汇总了C#中Server.BinaryFileWriter类的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileWriter类的具体用法?C# BinaryFileWriter怎么用?C# BinaryFileWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryFileWriter类属于Server命名空间,在下文中一共展示了BinaryFileWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public static void Serialize(FileInfo file, Action<GenericWriter> serializer)
{
file.Refresh();
if (file.Directory != null && !file.Directory.Exists)
{
file.Directory.Create();
}
if (!file.Exists)
{
file.Create().Close();
}
file.Refresh();
using (var fs = file.OpenWrite())
{
var writer = new BinaryFileWriter(fs, true);
try
{
serializer(writer);
}
finally
{
writer.Flush();
writer.Close();
}
}
}
示例2: SerializeMessages
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();
}
示例3: CustomSeperateSave
public static void CustomSeperateSave(SeperateSaveData data)
{
GenericWriter writer = new BinaryFileWriter(Path.Combine(data.SaveLocation, data.SaveName + ".bin"), true);
DirectoryCheck(data.SaveLocation);
data.SaveMethod(writer);
writer.Write(writer.Position);
writer.Close();
}
示例4: Save
public static void Save()
{
try
{
if (!Directory.Exists(General.SavePath))
Directory.CreateDirectory(General.SavePath);
GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "Gumps.bin"), true);
writer.Write(0); // version
writer.Write(s_ForceMenu);
writer.Write(s_ForceInfos.Count);
foreach (GumpInfo ginfo in s_ForceInfos.Values)
ginfo.Save(writer);
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 (Exception e)
{
Errors.Report(General.Local(199));
Console.WriteLine(e.Message);
Console.WriteLine(e.Source);
Console.WriteLine(e.StackTrace);
}
}
示例5: SaveMobiles
protected void SaveMobiles(SaveMetrics metrics)
{
Dictionary<Serial, Mobile> mobiles = World.Mobiles;
GenericWriter idx;
GenericWriter tdb;
GenericWriter bin;
if (UseSequentialWriters)
{
idx = new BinaryFileWriter(World.MobileIndexPath, false);
tdb = new BinaryFileWriter(World.MobileTypesPath, false);
bin = new BinaryFileWriter(World.MobileDataPath, true);
}
else
{
idx = new AsyncWriter(World.MobileIndexPath, false);
tdb = new AsyncWriter(World.MobileTypesPath, false);
bin = new AsyncWriter(World.MobileDataPath, true);
}
idx.Write(mobiles.Count);
foreach (Mobile m in mobiles.Values)
{
long start = bin.Position;
idx.Write(m._TypeRef);
idx.Write(m.Serial);
idx.Write(start);
m.Serialize(bin);
if (metrics != null)
{
metrics.OnMobileSaved((int)(bin.Position - start));
}
idx.Write((int)(bin.Position - start));
m.FreeCache();
}
tdb.Write(World.m_MobileTypes.Count);
foreach (Type t in World.m_MobileTypes)
{
tdb.Write(t.FullName);
}
idx.Close();
tdb.Close();
bin.Close();
}
示例6: SaveMobiles
protected void SaveMobiles( SaveMetrics metrics ) {
Dictionary<Serial, Mobile> mobiles = World.Mobiles;
GenericWriter idx;
GenericWriter tdb;
GenericWriter bin;
if ( World.SaveType == World.SaveOption.Normal ) {
idx = new BinaryFileWriter( World.MobileIndexPath, false );
tdb = new BinaryFileWriter( World.MobileTypesPath, false );
bin = new BinaryFileWriter( World.MobileDataPath, true );
} else {
idx = new AsyncWriter( World.MobileIndexPath, false );
tdb = new AsyncWriter( World.MobileTypesPath, false );
bin = new AsyncWriter( 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 );
if ( metrics != null ) {
metrics.OnMobileSaved( ( int ) ( bin.Position - start ) );
}
idx.Write( ( int ) ( bin.Position - start ) );
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();
}
示例7: OnSave
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 gumpi;
foreach( object obj in new ArrayList( s_Infos.Values ) )
{
if ( !(obj is Hashtable) )
continue;
foreach( object obje in new ArrayList( ((Hashtable)obj).Values ) )
{
if ( !(obje is GumpInfo ) )
continue;
gumpi = (GumpInfo)obje;
if ( gumpi.Mobile != null
&& gumpi.Mobile.Player
&& !gumpi.Mobile.Deleted
&& gumpi.Mobile.Account != null
&& ((Account)gumpi.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays( 30 ) )
list.Add( obje );
}
}
writer.Write( list.Count );
foreach( GumpInfo info in list )
info.Save( writer );
writer.Close();
}catch{ Errors.Report( "GumpInfo-> OnSave" ); } }
示例8: SaveGlobalOptions
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();
}
示例9: SaveGuilds
private static void SaveGuilds(string guildBase)
{
string guildIdxPath = Path.Combine(guildBase, "Guilds.idx");
string guildBinPath = Path.Combine(guildBase, "Guilds.bin");
GenericWriter idx;
GenericWriter bin;
if (!Directory.Exists(guildBase))
Directory.CreateDirectory(guildBase);
if ( SaveType == SaveOption.Normal )
{
idx = new BinaryFileWriter( guildIdxPath, false );
bin = new BinaryFileWriter( guildBinPath, true );
}
else
{
idx = new AsyncWriter( guildIdxPath, false );
bin = new AsyncWriter( guildBinPath, true );
}
idx.Write( (int) BaseGuild.List.Count );
foreach ( BaseGuild guild in BaseGuild.List.Values )
{
long start = bin.Position;
idx.Write( (int)0 );//guilds have no typeid
idx.Write( (int)guild.Id );
idx.Write( (long)start );
guild.Serialize( bin );
idx.Write( (int) (bin.Position - start) );
}
idx.Close();
bin.Close();
}
示例10: SaveMobiles
private static void SaveMobiles(string mobileBase)
{
ArrayList restock = new ArrayList();
GenericWriter idx;
GenericWriter tdb;
GenericWriter bin;
if (!Directory.Exists(mobileBase))
Directory.CreateDirectory(mobileBase);
string mobIdxPath = Path.Combine(mobileBase, "Mobiles.idx");
string mobTdbPath = Path.Combine(mobileBase, "Mobiles.tdb");
string mobBinPath = Path.Combine(mobileBase, "Mobiles.bin");
if ( SaveType == SaveOption.Normal )
{
idx = new BinaryFileWriter( mobIdxPath, false );
tdb = new BinaryFileWriter( mobTdbPath, false );
bin = new BinaryFileWriter( mobBinPath, true );
}
else
{
idx = new AsyncWriter( mobIdxPath, false );
tdb = new AsyncWriter( mobTdbPath, false );
bin = new AsyncWriter( mobBinPath, true );
}
idx.Write( (int) m_Mobiles.Count );
foreach ( Mobile m in m_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 )
{
if ( ((IVendor)m).LastRestock + ((IVendor)m).RestockDelay < DateTime.Now )
restock.Add( m );
}
m.FreeCache();
}
tdb.Write( (int) m_MobileTypes.Count );
for ( int i = 0; i < m_MobileTypes.Count; ++i )
tdb.Write( ((Type)m_MobileTypes[i]).FullName );
for (int i=0;i<restock.Count;i++)
{
IVendor vend = (IVendor)restock[i];
vend.Restock();
vend.LastRestock = DateTime.Now;
}
idx.Close();
tdb.Close();
bin.Close();
}
示例11: SaveBackup
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 ) );
}
示例12: Save
public static void Save( WorldSaveEventArgs args )
{
if( !Directory.Exists( "Saves/ACC" ) )
Directory.CreateDirectory( "Saves/ACC" );
string filename = "acc.sav";
string path [email protected]"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( DictionaryEntry de in m_RegSystems )
{
Type t = ScriptCompiler.FindTypeByFullName( (string)de.Key );
if( t != null )
{
writer.Write( (string)de.Key );
writer.Write( (bool)de.Value );
if( (bool)m_RegSystems[(string)de.Key] )
{
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 );
}
}
示例13: SaveItems
protected void SaveItems(SaveMetrics metrics)
{
Dictionary<Serial, Item> items = World.Items;
GenericWriter idx;
GenericWriter tdb;
GenericWriter bin;
if (UseSequentialWriters)
{
idx = new BinaryFileWriter( World.ItemIndexPath, false );
tdb = new BinaryFileWriter( World.ItemTypesPath, false );
bin = new BinaryFileWriter( World.ItemDataPath, true );
} else {
idx = new AsyncWriter( World.ItemIndexPath, false );
tdb = new AsyncWriter( World.ItemTypesPath, false );
bin = new AsyncWriter( 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 ) {
_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 );
if ( metrics != null ) {
metrics.OnItemSaved( ( int ) ( bin.Position - start ) );
}
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();
}
示例14: HandleError
private static void HandleError(Exception error, string name, object[] loadinfo)
{
bool sep = loadinfo == null;
bool nerr = error == null;
string type = sep ? "seperate savefile" : "save module";
string placename = sep ? "the file can be found at" : "this module was indexed under the name";
Console.WriteLine();
if (nerr)
{
Console.WriteLine("The loading and saving methods of a {0} are inconsistent, {1} \"{2}\".", type, placename, name);
if (!sep && (bool)loadinfo[3])
Console.WriteLine("More data was read than written.");
else
Console.WriteLine("More data was written than read.");
}
else
{
Console.WriteLine("During the loading of a {0} an exception was caught, {1} \"{2}\".", type, placename, name);
Console.WriteLine("The following error was caught:");
Console.WriteLine(error.ToString());
}
Console.WriteLine("Please Review your Save/Load methods for this {0}", sep ? "file" : "module");
if (!m_IgnoreErrors)
{
string str = sep ? "Do you wish to continue loading with faulty data(Y), or stop the program(N)?" : "Do you wish to remove this module and restart(Y), or continue loading with faulty data(N)?";
Console.WriteLine(str);
if (Console.ReadKey(true).Key == ConsoleKey.Y)
{
if (!sep)
{
int oldcount = (int)loadinfo[0];
int location = (int)loadinfo[1];
BinaryFileReader idxreader = (BinaryFileReader)loadinfo[2];
int newcount = oldcount - 1;
string[] indexarray = new string[newcount];
long[] binposarray = new long[newcount];
long[] finposarray = new long[newcount];
idxreader.Seek(0, SeekOrigin.Begin);
idxreader.ReadInt();
int loc = 0;
for (int j = 0; j < oldcount; j++)
{
if (j != location)
{
indexarray[loc] = idxreader.ReadString();
binposarray[loc] = idxreader.ReadLong();
finposarray[loc] = idxreader.ReadLong();
loc++;
}
else
{
idxreader.ReadString();
idxreader.ReadLong();
idxreader.ReadLong();
}
}
idxreader.Close();
GenericWriter idxwriter = new BinaryFileWriter(m_FullPath + ".idx", true);
idxwriter.Write(newcount);
for (int j = 0; j < newcount; j++)
{
idxwriter.Write(indexarray[j]);
idxwriter.Write(binposarray[j]);
idxwriter.Write(finposarray[j]);
}
idxwriter.Close();
Process.Start(Core.ExePath, Core.Arguments);
Core.Process.Kill();
}
}
else if (sep)
Core.Process.Kill();
}
}
示例15: CustomSave
private static void CustomSave()
{
DirectoryCheck(m_FilePath);
GenericWriter idx = new BinaryFileWriter(m_FullPath + ".idx", true);
GenericWriter bin = new BinaryFileWriter(m_FullPath + ".bin", true);
idx.Write(m_DataDictionary.Count);
foreach (KeyValuePair<string, SaveData> kv in m_DataDictionary)
{
idx.Write(kv.Key);
idx.Write(bin.Position);
kv.Value.SaveMethod(bin);
idx.Write(bin.Position);
}
idx.Close();
bin.Close();
}