Skip to content

Commit 3645760

Browse files
committed
added some additional code to savesystemmethods to allow for deleting folders and creating new, unique directory paths. Modified csvwriter to use these new savesystemmethods
1 parent 9dc7b8a commit 3645760

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

CSVWriter/CSVWriter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEngine;
77
using UnityEditor;
88
using Unity.Mathematics;
9+
using Helpers;
910

1011
[System.Serializable]
1112
public class CSVWriter
@@ -22,11 +23,12 @@ public class CSVWriter
2223
private bool is_active = false;
2324

2425
public bool Initialize() {
25-
string dname = Application.persistentDataPath;
26+
string dname = $"{Application.persistentDataPath}/{Helpers.SaveSystemMethods.GetCurrentDateTime()}";
2627
if (dirName != null && dirName.Length > 0) {
27-
dname = $"Assets/{dirName}";
28-
if (!AssetDatabase.IsValidFolder(dname)) dname = AssetDatabase.GUIDToAssetPath(AssetDatabase.CreateFolder("Assets", dirName));
28+
dname = $"{Application.persistentDataPath}/{dirName}";
2929
}
30+
Helpers.SaveSystemMethods.CheckOrCreateDirectory(dname);
31+
3032
string fname = (fileName != null && fileName.Length > 0) ? fileName : System.DateTime.Now.ToString("HH-mm-ss");
3133
filePath = (append_zero_to_filename) ? Path.Combine(dname, fname+"_0.csv") : Path.Combine(dname, fname+".csv");
3234

Helpers/Helpers.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ public static bool CheckOrCreateDirectory(string dirPath) {
144144
public static bool CheckFileExists(string filePath) {
145145
return File.Exists(filePath);
146146
}
147+
public static string GetUniqueDirectory(string dirPath) {
148+
int counter = 1;
149+
string returnDir = dirPath;
150+
while(CheckDirectoryExists(returnDir)) {
151+
returnDir = $"{dirPath}_{counter}";
152+
counter += 1;
153+
}
154+
return returnDir;
155+
}
156+
public static string CreateUniqueDirectory(string dirPath) {
157+
string returnDir = GetUniqueDirectory(dirPath);
158+
Directory.CreateDirectory(returnDir);
159+
return returnDir;
160+
}
147161
public static bool DeleteDirectory(string dirPath) {
148162
if (CheckDirectoryExists(dirPath)) {
149163
Directory.Delete(dirPath,true);
@@ -158,6 +172,10 @@ public static bool DeleteFile(string filePath) {
158172
}
159173
return false;
160174
}
175+
176+
public static string GetCurrentDateTime(string format = "HH-mm-ss") {
177+
return System.DateTime.Now.ToString(format);
178+
}
161179

162180
public static string ConvertToJSON<T>(T data) {
163181
return JsonUtility.ToJson(data, true);

0 commit comments

Comments
 (0)