BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
BrawlLib.BrawlManagerLib.TempFiles Class Reference

Static Public Member Functions

static string Create (string extension)
 Creates a temporary file in the BrawlManagerLib subdirectory of the system temporary folder. This function can be used for image files. For files that can be opened as a ResourceNode, consider using the MakeTempNode function instead. More...
 
static void DeleteAll ()
 Deletes all files created by the Create function (but not those created by MakeTempNode.) More...
 
static ResourceNode MakeTempNode (string path)
 Creates a ResourceNode from a temporary file using FileMap.FromTempFile. The file will be deleted when the underlying FileMap's stream is closed. More...
 

Static Public Attributes

static readonly string SUBDIR = "BrawlManagerLib-" + Guid.NewGuid()
 

Member Function Documentation

◆ Create()

static string BrawlLib.BrawlManagerLib.TempFiles.Create ( string  extension)
inlinestatic

Creates a temporary file in the BrawlManagerLib subdirectory of the system temporary folder. This function can be used for image files. For files that can be opened as a ResourceNode, consider using the MakeTempNode function instead.

46 {
47 if (!extension.StartsWith("."))
48 {
49 extension = "." + extension;
50 }
51
52 return Path.Combine(Path.GetTempPath(), SUBDIR, Guid.NewGuid() + extension);
53 }
static readonly string SUBDIR
Definition: TempFiles.cs:21

◆ DeleteAll()

static void BrawlLib.BrawlManagerLib.TempFiles.DeleteAll ( )
inlinestatic

Deletes all files created by the Create function (but not those created by MakeTempNode.)

59 {
60 List<Exception> exceptions = new List<Exception>();
61 try
62 {
63 foreach (string s in Directory.EnumerateFiles(Path.Combine(Path.GetTempPath(), SUBDIR)))
64 {
65 try
66 {
67 File.Delete(s);
68 }
69 catch (Exception e)
70 {
71 exceptions.Add(e);
72 }
73 }
74 }
75 catch (Exception e)
76 {
77 exceptions.Add(e);
78 }
79
80 if (exceptions.Count == 0)
81 {
82 try
83 {
84 Directory.Delete(Path.Combine(Path.GetTempPath(), SUBDIR));
85 }
86 catch (Exception e)
87 {
88 exceptions.Add(e);
89 }
90 }
91
92 //if (exceptions.Count > 0)
93 //{
94 // throw new TempFileCleanupException(exceptions);
95 //}
96 }

◆ MakeTempNode()

static ResourceNode BrawlLib.BrawlManagerLib.TempFiles.MakeTempNode ( string  path)
inlinestatic

Creates a ResourceNode from a temporary file using FileMap.FromTempFile. The file will be deleted when the underlying FileMap's stream is closed.

102 {
103 byte[] data = File.ReadAllBytes(path);
104
105 FileMap map = FileMap.FromTempFile(data.Length);
106 Console.WriteLine(path + " -> FromTempFile -> " + map.FilePath);
107 Marshal.Copy(data, 0, map.Address, data.Length);
108 return NodeFactory.FromSource(null, new DataSource(map));
109 }
Definition: FileMap.cs:10
static FileMap FromTempFile(int length)
Definition: FileMap.cs:96
string FilePath
Definition: FileMap.cs:24
VoidPtr Address
Definition: FileMap.cs:16
Definition: NodeFactory.cs:18
static ResourceNode FromSource(ResourceNode parent, DataSource source)
Definition: NodeFactory.cs:140
Definition: ResourceNode.cs:28

Member Data Documentation

◆ SUBDIR

readonly string BrawlLib.BrawlManagerLib.TempFiles.SUBDIR = "BrawlManagerLib-" + Guid.NewGuid()
static

The documentation for this class was generated from the following file: