Jypeli 10
The simple game programming library
Files.cs
Siirry tämän tiedoston dokumentaatioon.
1using System.Collections.Generic;
2using System.IO;
3
4namespace Jypeli
5{
6 public partial class FileManager
7 {
13 public StorageFile Create( string fileName )
14 {
15 return Open( fileName, true );
16 }
17
23 public virtual bool Exists( string fileName )
24 {
25 Initialize();
26 MakeAbsolute( ref fileName );
27 return FMAssert( File.Exists, false, false, fileName ) || FMAssert( Directory.Exists, false, false, fileName );
28 }
29
36 public virtual StorageFile Open( string fileName, bool write )
37 {
38 Initialize();
39 MakeAbsolute( ref fileName );
40 Stream stream = FMAssert<string, bool, Stream?>( openFileStream, write, null, fileName, write );
41 return new StorageFile( fileName, stream );
42 }
43
44 private Stream openFileStream(string fileName, bool write)
45 {
46 FileMode mode = write ? FileMode.Create : FileMode.Open;
47 FileAccess access = write ? FileAccess.ReadWrite : FileAccess.Read;
48 return new FileStream( fileName, mode, access );
49 }
50
56 public virtual void Delete( string fileName )
57 {
58 Initialize();
59 MakeAbsolute( ref fileName );
60 FMAssert( File.Delete, true, fileName );
61 }
62 }
63}
Stream openFileStream(string fileName, bool write)
Definition: Files.cs:44
virtual void Delete(string fileName)
Poistaa tiedoston. Ei heitä poikkeusta, jos tiedostoa ei ole olemassa.
Definition: Files.cs:56
void FMAssert(Action func, bool write)
Definition: Assert.cs:18
StorageFile Create(string fileName)
Luo uuden tiedoston
Definition: Files.cs:13
virtual StorageFile Open(string fileName, bool write)
Avaa tiedoston.
Definition: Files.cs:36
virtual bool Exists(string fileName)
Kertoo onko tiedosto tai hakemisto olemassa.
Definition: Files.cs:23
void MakeAbsolute(ref string path)
Definition: NameHelpers.cs:24