3 protected static const string DELIMITER =
"/";
9 static bool CreateDirectory(
string absoluteDirectory)
14 if (FileIO.FileExists(absoluteDirectory))
17 absoluteDirectory.Replace(
"\\", DELIMITER);
18 absoluteDirectory =
SCR_StringHelper.ReplaceRecursive(absoluteDirectory, DELIMITER + DELIMITER, DELIMITER);
20 if (FileIO.FileExists(absoluteDirectory))
23 array<string> pieces = {};
24 absoluteDirectory.Split(DELIMITER, pieces,
true);
26 if (pieces.Count() < 2)
28 Print(
"Cannot create directory " + absoluteDirectory +
"; not enough directories", LogLevel.DEBUG);
32 string path = pieces[0];
33 for (
int i = 1, count = pieces.Count(); i < count; i++)
35 path += DELIMITER + pieces[i];
37 if (FileIO.FileExists(path))
40 if (!FileIO.MakeDirectory(path))
42 Print(
"Cannot create directory " + absoluteDirectory +
"; blocked at " + path, LogLevel.DEBUG);
56 static bool Copy(
string source,
string destination,
bool overwrite =
true)
58 array<string> content = ReadFileContent(source);
61 Print(
"Cannot get file content - " + source, LogLevel.ERROR);
67 if (!FilePath.IsAbsolutePath(destination))
69 if (!Workbench.GetAbsolutePath(destination, absolutePath,
false))
71 Print(
"Cannot get destination's absolute file path - " + destination, LogLevel.WARNING);
77 if (!overwrite && FileIO.FileExists(destination))
79 Print(
"Not allowed to overwrite file - " + destination, LogLevel.WARNING);
83 if (!WriteFileContent(destination, content))
85 Print(
"Cannot write file - " + destination, LogLevel.ERROR);
96 static array<string> ReadFileContent(
string filePath)
98 FileHandle fileHandle = FileIO.OpenFile(filePath, FileMode.READ);
101 Print(
"Could not open " + filePath, LogLevel.WARNING);
106 array<string> result = {};
107 while (!fileHandle.IsEOF())
109 fileHandle.ReadLine(lineContent);
110 result.Insert(lineContent);
124 static bool WriteFileContent(
string filePath, notnull array<string> lines)
126 FileHandle fileHandle = FileIO.OpenFile(filePath, FileMode.WRITE);
129 Print(
"Could not open " + filePath, LogLevel.WARNING);
133 int linesCountMinusOne = lines.Count() - 1;
134 if (linesCountMinusOne == -1)
136 fileHandle.Write(
string.Empty);
140 foreach (
int lineNumber,
string line : lines)
142 if (lineNumber < linesCountMinusOne)
143 fileHandle.WriteLine(line);
147 fileHandle.Write(lines[linesCountMinusOne]);