Пример #1
0
            public static FileInfo GetFileInfoForCreation(string path, CreateOnFileExistBehaviour behaviour)
            {
                FileInfo file = new FileInfo(path);

                EnsureDirectory(file.DirectoryName);
                if (file.Exists)
                {
                    switch (behaviour)
                    {
                    case CreateOnFileExistBehaviour.Exception:
                        throw new IOException($"file already exists {path}");

                    case CreateOnFileExistBehaviour.Ignore:
                        return(null);

                    case CreateOnFileExistBehaviour.Overwrite:
                        file.Attributes = FileAttributes.Normal;
                        file.Delete();
                        break;

                    case CreateOnFileExistBehaviour.RenameNewFile:
                        return(GetFileInfoForCreationWithIncreasingNumberSuffix(path));
                    }
                }
                return(file);
            }
Пример #2
0
 public static FileStream CreateFileInLogPath(string path, CreateOnFileExistBehaviour behaviour = CreateOnFileExistBehaviour.RenameNewFile)
 {
     return(GetFileInfoForCreationInLogPath(path, behaviour)?.Create());
 }
Пример #3
0
 public static FileStream CreateFileInDataPath(string path, CreateOnFileExistBehaviour behaviour = CreateOnFileExistBehaviour.Exception)
 {
     return(GetFileInfoForCreationInDataPath(path, behaviour)?.Create());
 }
Пример #4
0
 public static FileInfo GetFileInfoForCreationInLogPath(string path, CreateOnFileExistBehaviour behaviour = CreateOnFileExistBehaviour.RenameNewFile)
 {
     path = Path.Combine(Application.consoleLogPath, GetCleanPathStr(path));
     return(GetFileInfoForCreation(path, behaviour));
 }
Пример #5
0
 public static FileInfo GetFileInfoForCreationInDataPath(string path, CreateOnFileExistBehaviour behaviour = CreateOnFileExistBehaviour.Exception)
 {
     path = Path.Combine(Application.dataPath, GetCleanPathStr(path));
     return(GetFileInfoForCreation(path, behaviour));
 }
Пример #6
0
 public static FileStream CreateFile(string path, CreateOnFileExistBehaviour behaviour)
 {
     return(GetFileInfoForCreation(path, behaviour)?.Create());
 }