Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TemporaryFile.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.IO;
5 
6 namespace SiliconStudio.Core.IO
7 {
8  internal partial class TemporaryFile : IDisposable
9  {
10  private bool isDisposed;
11  private string path;
12 
13  public TemporaryFile()
14  {
15  path = VirtualFileSystem.GetTempFileName();
16  }
17 
18 
19  public string Path
20  {
21  get { return path; }
22  }
23 
24 #if !NETFX_CORE
25  ~TemporaryFile()
26  {
27  Dispose(false);
28  }
29 #endif
30 
31  public void Dispose()
32  {
33  Dispose(false);
34 #if !NETFX_CORE
35  GC.SuppressFinalize(this);
36 #endif
37  }
38 
39  private void Dispose(bool disposing)
40  {
41  if (!isDisposed)
42  {
43  isDisposed = true;
44  TryDelete();
45  }
46  }
47 
48  private void TryDelete()
49  {
50  try
51  {
52  VirtualFileSystem.FileDelete(path);
53  }
54  catch (IOException)
55  {
56  }
57  catch (UnauthorizedAccessException)
58  {
59  }
60  }
61  }
62 }