private static UnbufferedFileStream GetUniqueFileStream(string path)
{
if (!File.Exists(path))
{
try
{
return new UnbufferedFileStream(path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None, BufferManager.Instance);
}
catch (DirectoryNotFoundException)
{
throw;
}
catch (IOException)
{
}
}
for (int index = 1; ; index++)
{
string text = string.Format(@"{0}\{1} ({2}){3}",
Path.GetDirectoryName(path),
Path.GetFileNameWithoutExtension(path),
index,
Path.GetExtension(path));
if (!File.Exists(text))
{
try
{
return new UnbufferedFileStream(text, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None, BufferManager.Instance);
}
catch (DirectoryNotFoundException)
{
throw;
}
catch (IOException)
{
if (index > 1024) throw;
}
}
}
}