2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework.Storage;
6 using Microsoft.Xna.Framework.GamerServices;
14 delegate
void AssertCallback(
string fileName );
16 StorageDevice device = null;
17 StorageContainer container = null;
21 StorageDevice.DeviceChanged +=
new EventHandler<EventArgs>( StorageDevice_DeviceChanged );
24 void StorageDevice_DeviceChanged(
object sender, EventArgs e )
26 if ( device == null || device.IsConnected )
33 void AssertDevice( AssertCallback callback,
string fileName )
37 AsyncCallback asCallback = delegate( IAsyncResult result )
39 StorageDevice.EndShowSelector( result );
43 StorageDevice.BeginShowSelector( asCallback, null );
49 void AssertContainer( AssertCallback callback,
string fileName )
51 if ( container == null )
53 AsyncCallback asCallback = delegate( IAsyncResult result )
55 device.EndOpenContainer( result );
59 device.BeginOpenContainer(
Game.
Name, asCallback, null );
65 void AssertDevContainer( AssertCallback callback,
string fileName )
67 if ( container != null )
69 else if ( device != null )
70 AssertContainer( callback, fileName );
72 AssertDevice( delegate { AssertContainer( callback, fileName ); }, fileName );
75 void AssertDevContainerWait()
79 IAsyncResult result = StorageDevice.BeginShowSelector( null, null );
80 result.AsyncWaitHandle.WaitOne();
83 if ( container == null )
85 IAsyncResult result = device.BeginOpenContainer(
Game.
Name, null, null );
86 result.AsyncWaitHandle.WaitOne();
90 public override bool Exists(
string fileName )
92 MakeAbsolute(ref fileName);
93 AssertDevContainerWait();
94 return container.FileExists( fileName );
99 MakeAbsolute( ref fileName );
100 AssertDevContainerWait();
102 FileMode fileMode = write ? FileMode.Create : FileMode.Open;
103 FileAccess fileAccess = write ? FileAccess.ReadWrite : FileAccess.Read;
104 return new StorageFile( fileName, container.OpenFile( fileName, fileMode, fileAccess ) );
107 public override void Delete(
string fileName )
109 MakeAbsolute( ref fileName );
110 AssertDevContainer( doDeleteFile, fileName );
113 public override bool ChDir(
string path )
115 MakeAbsolute( ref path );
116 AssertDevContainer( doChangeDir, path );
120 public override void MkDir(
string path )
122 MakeAbsolute( ref path );
123 AssertDevContainer( doMakeDir, path );
126 public override void RmDir(
string path )
128 MakeAbsolute( ref path );
129 AssertDevContainer( doRmDir, path );
135 string[] fileList = container.GetFileNames(
_currentDir +
"\\*" );
136 return fileList.ToList<
string>().AsReadOnly();
139 private void doDeleteFile(
string fileName )
141 MakeAbsolute( ref fileName );
142 container.DeleteFile( fileName );
145 private void doChangeDir(
string path )
147 MakeAbsolute( ref path );
149 if ( !container.DirectoryExists( path ) )
150 throw new DirectoryNotFoundException(
"Directory " + path +
" was not found." );
155 private void doMakeDir(
string path )
157 MakeAbsolute( ref path );
158 container.CreateDirectory( path );
161 private void doRmDir(
string path )
163 MakeAbsolute( ref path );
164 container.DeleteDirectory( path );
override void MkDir(string path)
Luo uuden hakemiston.
override void RmDir(string path)
Poistaa hakemiston.
override bool Exists(string fileName)
override bool ChDir(string path)
Vaihtaa nykyistä hakemistoa.
Peliluokka reaaliaikaisille peleille.
override StorageFile Open(string fileName, bool write)
static string Name
Pelin nimi.
override IList< string > GetFileList()
override void Delete(string fileName)