本文整理汇总了C#中Microsoft.Xna.Framework.Storage.StorageDevice.OpenContainer方法的典型用法代码示例。如果您正苦于以下问题:C# StorageDevice.OpenContainer方法的具体用法?C# StorageDevice.OpenContainer怎么用?C# StorageDevice.OpenContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Storage.StorageDevice
的用法示例。
在下文中一共展示了StorageDevice.OpenContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Storage
public Storage()
{
PlayersLoaded = new ArrayList();
result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null);
Device = Guide.EndShowStorageDeviceSelector(result);
// Open a storage container.
StorageContainer container = Device.OpenContainer("Savegames");
// Add the container path to our file name.
string filename = Path.Combine(container.Path, "savegame.sav");
// Create a new file.
if (!File.Exists(filename))
{
FileStream file = File.Create(filename);
file.Close();
}
// Dispose the container, to commit the data.
container.Dispose();
}
示例2: SaveSessionResult
/// <summary>
/// Save the current state of the session, with the given storage device.
/// </summary>
/// <param name="storageDevice">The chosen storage device.</param>
/// <param name="overwriteDescription">
/// The description of the save game to over-write, if any.
/// </param>
private static void SaveSessionResult(StorageDevice storageDevice,
SaveGameDescription overwriteDescription)
{
// check the parameter
if ((storageDevice == null) || !storageDevice.IsConnected)
{
return;
}
// open the container
using (StorageContainer storageContainer =
storageDevice.OpenContainer(Session.SaveGameContainerName))
{
string filename;
string descriptionFilename;
// get the filenames
if (overwriteDescription == null)
{
int saveGameIndex = 0;
string testFilename;
do
{
saveGameIndex++;
testFilename = Path.Combine(storageContainer.Path, "SaveGame" +
saveGameIndex.ToString() + ".xml");
}
while (File.Exists(testFilename));
filename = testFilename;
descriptionFilename = "SaveGameDescription" +
saveGameIndex.ToString() + ".xml";
}
else
{
filename = Path.Combine(storageContainer.Path,
overwriteDescription.FileName);
descriptionFilename = "SaveGameDescription" +
Path.GetFileNameWithoutExtension(
overwriteDescription.FileName).Substring(8) + ".xml";
}
using (FileStream stream = new FileStream(filename, FileMode.Create))
{
using (XmlWriter xmlWriter = XmlWriter.Create(stream))
{
// <rolePlayingGameData>
xmlWriter.WriteStartElement("rolePlayingGameSaveData");
// write the map information
xmlWriter.WriteStartElement("mapData");
xmlWriter.WriteElementString("mapContentName",
TileEngine.Map.AssetName);
new XmlSerializer(typeof(PlayerPosition)).Serialize(
xmlWriter, TileEngine.PartyLeaderPosition);
new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize(
xmlWriter, singleton.removedMapChests);
new XmlSerializer(
typeof(List<WorldEntry<FixedCombat>>)).Serialize(
xmlWriter, singleton.removedMapFixedCombats);
new XmlSerializer(typeof(List<WorldEntry<Player>>)).Serialize(
xmlWriter, singleton.removedMapPlayerNpcs);
new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize(
xmlWriter, singleton.modifiedMapChests);
xmlWriter.WriteEndElement();
// write the quest information
xmlWriter.WriteStartElement("questData");
xmlWriter.WriteElementString("questLineContentName",
singleton.questLine.AssetName);
xmlWriter.WriteElementString("currentQuestIndex",
singleton.currentQuestIndex.ToString());
new XmlSerializer(typeof(List<WorldEntry<Chest>>)).Serialize(
xmlWriter, singleton.removedQuestChests);
new XmlSerializer(
typeof(List<WorldEntry<FixedCombat>>)).Serialize(
xmlWriter, singleton.removedQuestFixedCombats);
new XmlSerializer(typeof(List<ModifiedChestEntry>)).Serialize(
xmlWriter, singleton.modifiedQuestChests);
xmlWriter.WriteElementString("currentQuestStage",
IsQuestLineComplete ?
Quest.QuestStage.NotStarted.ToString() :
singleton.quest.Stage.ToString());
xmlWriter.WriteEndElement();
// write the party data
new XmlSerializer(typeof(PartySaveData)).Serialize(xmlWriter,
new PartySaveData(singleton.party));
// </rolePlayingGameSaveData>
xmlWriter.WriteEndElement();
}
}
// create the save game description
SaveGameDescription description = new SaveGameDescription();
//.........这里部分代码省略.........
示例3: RefreshSaveGameDescriptionsResult
/// <summary>
/// Asynchronous storage-device callback for
/// refreshing the save-game descriptions.
/// </summary>
private static void RefreshSaveGameDescriptionsResult(
StorageDevice storageDevice)
{
// check the parameter
if ((storageDevice == null) || !storageDevice.IsConnected)
{
return;
}
// open the container
using (StorageContainer storageContainer =
storageDevice.OpenContainer(Session.SaveGameContainerName))
{
saveGameDescriptions = new List<SaveGameDescription>();
// get the description list
string[] filenames = Directory.GetFiles(storageContainer.Path,
"SaveGameDescription*.xml");
// add each entry to the list
foreach (string filename in filenames)
{
SaveGameDescription saveGameDescription;
// check the size of the list
if (saveGameDescriptions.Count >= MaximumSaveGameDescriptions)
{
break;
}
// open the file stream
using (FileStream fileStream = File.Open(filename, FileMode.Open))
{
// deserialize the object
saveGameDescription =
saveGameDescriptionSerializer.Deserialize(fileStream)
as SaveGameDescription;
// if it's valid, add it to the list
if (saveGameDescription != null)
{
saveGameDescriptions.Add(saveGameDescription);
}
}
}
}
}
示例4: SaveFile
protected void SaveFile(StorageDevice device, string fi, string teta, string alfa)
{
//Массив байтов для записи в файл
byte[] fia = new byte[fi.Length];
byte[] tetaa = new byte[teta.Length];
byte[] alfaa = new byte[alfa.Length];
byte[] a = new byte[1];
a[0] = Convert.ToByte(0);
for (byte i = 0; i < fi.Length; i++)
{
fia[i] = Convert.ToByte(fi[i]);
}
for (byte i = 0; i < teta.Length; i++)
{
tetaa[i] = Convert.ToByte(teta[i]);
}
for (byte i = 0; i < alfa.Length; i++)
{
alfaa[i] = Convert.ToByte(alfa[i]);
}
//Открываем контейнер для хранения файлов
//В случае с Windows-играми это - папка с соответствующим
//именем в папке Мои документы текущего пользователя
StorageContainer container = device.OpenContainer("Diplom");
//Соединяем имя файла и имя контейнера
string filename = Path.Combine(container.Path, "corner" + countnumber + ".txt");
//Создаем новый файл
countnumber++;
if (!File.Exists(filename))
{
FileStream file = File.Create(filename);
//Записываем в файл массив байтов, сгенерированный выше
file.Write(fia, 0, fi.Length);
file.Write(a, 0, 1);
file.Write(tetaa, 0, teta.Length);
file.Write(a, 0, 1);
file.Write(alfaa, 0, alfa.Length);
//закрываем файл
file.Close();
this.Window.Title = "Файл создан";
}
else
{
this.Window.Title = "Файл уже создан";
}
//Уничтожаем контейнер - только после этого файл будет
//сохранен
container.Dispose();
}
示例5: LoadFile
protected void LoadFile(StorageDevice device, string name)
{
StorageContainer container = device.OpenContainer("Diplom");
long n = 0, m = 0;
if (name.Length == 3)
{
m = Convert.ToInt64(name);
n = Convert.ToInt64(name) / 100;
name = Convert.ToString(m - n * 100);
}
if (name.Length == 6)
{
m = Convert.ToInt64(name);
n = Convert.ToInt64(name) / 1000;
name = Convert.ToString(m - n * 1000);
}
if (name.Length == 10)
{
m = Convert.ToInt64(name);
n = Convert.ToInt64(name) / 10000;
name = Convert.ToString(m - n * 10000);
}
string filename = Path.Combine(container.Path, "Trajectory" + name + ".dat");
int k = -1;
if (File.Exists(filename))
{
FileStream file = File.Open(filename, FileMode.Open);
double[] Trajectory = new double[file.Length];
byte[] bytes = new byte[4];
//Выведем данные, считанные из файла, в заголовок игрового окна
//this.Window.Title = "Содержимое файла: ";
string s;
int d = 14;
double s1 = 0;
double s2 = 0;
double s3 = 0;
length = (int)(file.Length / (14 * 5));
int b;
char c;
for (int i = 1; i < file.Length + 1; i += d)
{
s = "";
for (int j = 0; j < d; j++)
{
b = file.ReadByte();
c = Convert.ToChar(b);
//if (k == 1) s1 += c;
//if (c == 69)k=1;
if (c != 32) s += c;
}
this.Window.Title += s + " ";
string sd = s.Replace(".", ",");
sd = sd.Replace("D", "e");
k++;
if (k == 1)
{
s1 = Convert.ToDouble(sd);
d = 14;
}
if (k == 2)
{
s2 = Convert.ToDouble(sd);
}
if (k == 3)
{
s3 = Convert.ToDouble(sd);
d = 14;
}
if (k == 4)
{
d = 14;
fotonData.AddFatonDataList(s1, s2, s3);
k = -1;
}
//this.Window.Title += Convert.ToString(f) + " ";
}
file.Close();
ScienceMod = true;
readfromfile = true;
}
else
{
this.Window.Title = "Отсутствует файл для чтения";
readfromfile = false;
}
formCollection["LibraryMenu"]["textbox1"].Text = "";
container.Dispose();
}
示例6: LoadData
private void LoadData(StorageDevice storageDevice,ref int numChic, ref int chicQueue, ref int numRooster,
ref int roosterQueue, ref CharacterClass player, ref ChickenClass[] chickens, ref RoosterClass[] roosters,
ref EconomicsClass eco, ref int eggCount, ref int numEgg, ref EggClass[] egg, ref int days, ref float dayTime,
ref bool endOfDay, ref int numBoots, ref RubberBootClass[] boots, ref float bootTime, ref bool bootPresent,
ref bool bootEquipped, ref FoxClass fox)
{
StorageContainer myContainer = storageDevice.OpenContainer("Chicken_Game");
string filename = Path.Combine(myContainer.Path, "ChickenGameSave.sav");
if (!File.Exists(filename))
return;
FileStream fileStream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read);
XmlSerializer serializer = new XmlSerializer(typeof(DataToSave));
DataToSave dataToSave = (DataToSave)serializer.Deserialize(fileStream);
fileStream.Close();
myContainer.Dispose();
//load character
player.position = dataToSave.cPosition;
player.rotation = dataToSave.cRotation;
player.hitPoints = dataToSave.hitpoints;
//load chickens
numChic = dataToSave.numChickens;
chicQueue = dataToSave.ChicQueue;
//load chicken1
if (dataToSave.chic1time != -1)
{
chickens[0] = new ChickenClass(Content, graphics);
chickens[0].InitializeChicken(0);
chickens[0].time = dataToSave.chic1time;
chickens[0].state = dataToSave.chic1state;
chickens[0].ground = dataToSave.chic1ground;
chickens[0].ChickenInitNode = dataToSave.chic1InitNode;
chickens[0].ChickenPreviousNode = dataToSave.chic1PreviousNode;
chickens[0].ChickenCurrentNode = dataToSave.chic1CurrentNode;
chickens[0].chickenNextNode = dataToSave.chic1NextNode;
chickens[0].position = dataToSave.chic1Position;
chickens[0].rotation = dataToSave.chic1Rotation;
chickens[0].riseRun = dataToSave.chic1RiseRun;
chickens[0].eggLaid = dataToSave.chic1EggLaid;
}
//load chicken2
if (dataToSave.chic2time != -1)
{
chickens[1] = new ChickenClass(Content, graphics);
chickens[1].InitializeChicken(0);
chickens[1].time = dataToSave.chic2time;
chickens[1].state = dataToSave.chic2state;
chickens[1].ground = dataToSave.chic2ground;
chickens[1].ChickenInitNode = dataToSave.chic2InitNode;
chickens[1].ChickenPreviousNode = dataToSave.chic2PreviousNode;
chickens[1].ChickenCurrentNode = dataToSave.chic2CurrentNode;
chickens[1].chickenNextNode = dataToSave.chic2NextNode;
chickens[1].position = dataToSave.chic2Position;
chickens[1].rotation = dataToSave.chic2Rotation;
chickens[1].riseRun = dataToSave.chic2RiseRun;
chickens[1].eggLaid = dataToSave.chic2EggLaid;
}
//load chicken3
if (dataToSave.chic3time != -1)
{
chickens[2] = new ChickenClass(Content, graphics);
chickens[2].InitializeChicken(0);
chickens[2].time = dataToSave.chic3time;
chickens[2].state = dataToSave.chic3state;
chickens[2].ground = dataToSave.chic3ground;
chickens[2].ChickenInitNode = dataToSave.chic3InitNode;
chickens[2].ChickenPreviousNode = dataToSave.chic3PreviousNode;
chickens[2].ChickenCurrentNode = dataToSave.chic3CurrentNode;
chickens[2].chickenNextNode = dataToSave.chic3NextNode;
chickens[2].position = dataToSave.chic3Position;
chickens[2].rotation = dataToSave.chic3Rotation;
chickens[2].riseRun = dataToSave.chic3RiseRun;
chickens[2].eggLaid = dataToSave.chic3EggLaid;
}
//load chicken4
if (dataToSave.chic4time != -1)
{
chickens[3] = new ChickenClass(Content, graphics);
chickens[3].InitializeChicken(0);
chickens[3].time = dataToSave.chic4time;
chickens[3].state = dataToSave.chic4state;
chickens[3].ground = dataToSave.chic4ground;
chickens[3].ChickenInitNode = dataToSave.chic4InitNode;
chickens[3].ChickenPreviousNode = dataToSave.chic4PreviousNode;
chickens[3].ChickenCurrentNode = dataToSave.chic4CurrentNode;
chickens[3].chickenNextNode = dataToSave.chic4NextNode;
chickens[3].position = dataToSave.chic4Position;
chickens[3].rotation = dataToSave.chic4Rotation;
chickens[3].riseRun = dataToSave.chic4RiseRun;
chickens[3].eggLaid = dataToSave.chic4EggLaid;
}
//load chicken5
if (dataToSave.chic5time != -1)
{
chickens[4] = new ChickenClass(Content, graphics);
chickens[4].InitializeChicken(0);
chickens[4].time = dataToSave.chic5time;
chickens[4].state = dataToSave.chic5state;
//.........这里部分代码省略.........
示例7: Save
//.........这里部分代码省略.........
dataToSave.egg8 = egg[7].position;
}
if (numEgg > 8)
{
dataToSave.egg9 = egg[8].position;
}
if (numEgg > 9)
{
dataToSave.egg10 = egg[9].position;
}
if (numEgg > 10)
{
dataToSave.egg11 = egg[10].position;
}
if (numEgg > 11)
{
dataToSave.egg12 = egg[11].position;
}
if (numEgg > 12)
{
dataToSave.egg13 = egg[12].position;
}
if (numEgg > 13)
{
dataToSave.egg14 = egg[13].position;
}
if (numEgg > 14)
{
dataToSave.egg15 = egg[14].position;
}
if (numEgg > 15)
{
dataToSave.egg16 = egg[15].position;
}
if (numEgg > 16)
{
dataToSave.egg17 = egg[16].position;
}
if (numEgg > 17)
{
dataToSave.egg18 = egg[17].position;
}
if (numEgg > 18)
{
dataToSave.egg19 = egg[18].position;
}
if (numEgg > 19)
{
dataToSave.egg20 = egg[19].position;
}
dataToSave.days = days; //tracks number of total days
dataToSave.dayTime = dayTime; //tracks number of seconds since day began
dataToSave.endOfDay = endOfDay;
//boots
dataToSave.numBoots = numBoots;
if (numBoots > 0)
{
dataToSave.boot1 = boots[0].position;
}
if (numBoots > 1)
{
dataToSave.boot2 = boots[1].position;
}
dataToSave.bootTime = bootTime;
dataToSave.bootPresent = bootPresent;
dataToSave.bootEquipped = bootEquipped;
//fox
dataToSave.foxWandering = fox.wandering;
dataToSave.foxInitNode = fox.foxInitNode;
dataToSave.foxPreviousNode = fox.foxPreviousNode;
dataToSave.foxCurrentNode = fox.foxCurrentNode;
dataToSave.foxNextNode = fox.foxNextNode;
dataToSave.foxPosition = fox.position;
dataToSave.foxPositionOld = fox.positionOld;
dataToSave.foxRotation = fox.rotation;
dataToSave.foxRiseRun = fox.riseRun;
dataToSave.foxRiseRun2 = fox.riseRun2;
dataToSave.foxChasing = fox.chasing;
dataToSave.foxAvoiding = fox.avoiding;
dataToSave.foxTimer = fox.timer;
dataToSave.foxChaseTime = fox.chaseTime;
dataToSave.foxTimer2 = fox.timer2;
dataToSave.foxHome = fox.home;
dataToSave.foxStart = fox.start;
dataToSave.foxTemp1 = fox.temp1;
StorageContainer myContainer = storageDevice.OpenContainer("Chicken_Game");
// Here is the path to where you want to save your data
string nameOfFile = Path.Combine(myContainer.Path, "ChickenGameSave.sav");
// If the file doesn't exist, it will be created, if it does, it will be replaced
FileStream fileStream = File.Open(nameOfFile, FileMode.Create);
XmlSerializer serializer = new XmlSerializer(typeof(DataToSave));
serializer.Serialize(fileStream, dataToSave);
//close this file
fileStream.Close();
myContainer.Dispose();
}
示例8: Initialize
protected override void Initialize()
{
IAsyncResult syncResult = Guide.BeginShowStorageDeviceSelector(null, null);
storageDevice = Guide.EndShowStorageDeviceSelector(syncResult);
//if (!storageDevice.IsConnected) Exit();
container = storageDevice.OpenContainer("Minesweeper");
skins = new Dictionary<string, Skin>();
bestTimes = new Dictionary<Difficulty, int>(4);
bestTimes.Add(Difficulty.Beginner, 999);
bestTimes.Add(Difficulty.Intermediate, 999);
bestTimes.Add(Difficulty.Expert, 999);
bestTimes.Add(Difficulty.Zune, 999);
GetBestTimes();
options = new Options(true, false, "Blue");
base.Initialize();
}
示例9: LoadSettings
/// <summary>
/// Loads the settings from the specified device.
/// </summary>
/// <param name="device">The device.</param>
private void LoadSettings(StorageDevice device)
{
// Open a storage container.
StorageContainer container = device.OpenContainer("Clock");
// Get the path of the save game.
string filename = Path.Combine(container.Path, "settings.xml");
if (File.Exists(filename))
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
using (TextReader tr = new StreamReader(filename))
{
string xml = tr.ReadToEnd();
System.Diagnostics.Trace.WriteLine(xml);
}
}
#endif
try
{
// Open the file
FileStream stream = File.Open(filename, FileMode.Open);
// Convert the object to XML data and put it in the stream.
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
this.settings = serializer.Deserialize(stream) as Settings;
// Close the file.
stream.Close();
}
catch (Exception exception)
{
// In some cases, XmlSerializer throws exception when loading the data. We try to fix the problem by deleting the file.
// Hopefully this issue should be fixed now.
System.Diagnostics.Trace.WriteLine(exception.ToString());
File.Delete(filename);
// As a preliminary way to signal that we didn't load the settings, for now we go into setting mode.
this.BeginSettingMode();
}
}
// Dispose the container, to commit changes.
container.Dispose();
if (this.settings == null)
{
this.settings = new Settings();
}
}
示例10: SaveSettings
/// <summary>
/// Saves the application settings to the specified device.
/// </summary>
/// <param name="device">The device to use.</param>
private void SaveSettings(StorageDevice device)
{
// Open a storage container.
StorageContainer container = device.OpenContainer("Clock");
// Get the path of the save game.
string filename = Path.Combine(container.Path, "settings.xml");
// Open the file, creating it if necessary.
FileStream stream = File.Open(filename, FileMode.Create);
// Convert the object to XML data and put it in the stream.
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(stream, this.settings);
// Close the file.
stream.Close();
// Dispose the container, to commit changes.
container.Dispose();
}
示例11: SaveNameData
void SaveNameData(string filename, StorageDevice storageDevice, NameWrapper nameWrapper)
{
using (StorageContainer storageContainer = storageDevice.OpenContainer("Content"))
{
string filenamePath = Path.Combine(storageContainer.Path, filename);
using (FileStream fileStream = File.Create(filenamePath))
{
BinaryWriter myBw = new BinaryWriter(fileStream);
try
{
myBw.Write(_nameWrapper.ToByteArray());
}
finally
{
myBw.Flush();
myBw.Close();
fileStream.Close();
_operationPending = false;
storageContainer.Dispose();
}
}
}
}
示例12: LoadNameData
void LoadNameData(string filename, StorageDevice storageDevice)
{
using (StorageContainer storageContainer = storageDevice.OpenContainer("Content"))
{
string filenamePath = Path.Combine(storageContainer.Path, filename);
try
{
using (FileStream fileStream = File.OpenRead(filenamePath))
{
BinaryReader myBr = new BinaryReader(fileStream);
try
{
fileStream.Position = 0;
_nameWrapper = new NameWrapper(myBr.ReadBytes((int)fileStream.Length));
}
catch (Exception e)
{
_nameWrapper = new NameWrapper();
}
finally
{
myBr.Close();
fileStream.Close();
_operationPending = false;
storageContainer.Dispose();
}
}
}
catch (Exception e)
{
_nameWrapper = new NameWrapper();
_operationPending = false;
}
}
}
示例13: LoadBookletData
void LoadBookletData(string filename, StorageDevice storageDevice)
{
using (StorageContainer storageContainer = storageDevice.OpenContainer("Content"))
{
string filenamePath = Path.Combine(storageContainer.Path, filename);
using (FileStream fileStream = File.OpenRead(filenamePath))
{
BinaryReader myBr = new BinaryReader(fileStream);
try
{
fileStream.Position = 0;
_currentBooklet = new Booklet(myBr.ReadBytes((int)fileStream.Length));
}
finally
{
fileStream.Close();
_operationPending = false;
storageContainer.Dispose();
}
}
}
}
示例14: DeleteSaveGameResult
/// <summary>
/// Delete the save game specified by the description.
/// </summary>
/// <param name="storageDevice">The chosen storage device.</param>
/// <param name="saveGameDescription">The description of the save game.</param>
public static void DeleteSaveGameResult(StorageDevice storageDevice,
SaveGameDescription saveGameDescription)
{
// check the parameters
if (saveGameDescription == null)
{
throw new ArgumentNullException("saveGameDescription");
}
// check the parameter
if ((storageDevice == null) || !storageDevice.IsConnected)
{
return;
}
// open the container
using (StorageContainer storageContainer =
storageDevice.OpenContainer(Session.SaveGameContainerName))
{
File.Delete(Path.Combine(storageContainer.Path,
saveGameDescription.FileName));
File.Delete(Path.Combine(storageContainer.Path, "SaveGameDescription" +
Path.GetFileNameWithoutExtension(
saveGameDescription.FileName).Substring(8) +
".xml"));
}
// refresh the save game descriptions
Session.RefreshSaveGameDescriptions();
}
示例15: CheckWhetherExists
public void CheckWhetherExists(StorageDevice storageDevice)
{
StorageContainer myContainer = storageDevice.OpenContainer("Chicken_Game");
string nameOfFile = Path.Combine(myContainer.Path, "ChickenGameSave.sav");
if (File.Exists(nameOfFile))
{
//LoadData(device, ref world.myCharacter.position);
}
myContainer.Dispose();
}