diff --git a/Assets/Scripts/Layers/Adapters/DataTypeAdapters/FileTypeAdapter.cs b/Assets/Scripts/Layers/Adapters/DataTypeAdapters/FileTypeAdapter.cs index 1440a009..47266b6a 100644 --- a/Assets/Scripts/Layers/Adapters/DataTypeAdapters/FileTypeAdapter.cs +++ b/Assets/Scripts/Layers/Adapters/DataTypeAdapters/FileTypeAdapter.cs @@ -13,7 +13,7 @@ public class FileTypeEvent public string Extension; public UnityEvent FileReceived; } - + [CreateAssetMenu(menuName = "Netherlands3D/Adapters/FileTypeAdapter", fileName = "FileTypeAdapter", order = 0)] public class FileTypeAdapter : ScriptableObject { @@ -33,27 +33,40 @@ public void ProcessFile(string file) { if (file.EndsWith(',')) file = file.Remove(file.Length - 1); - + var absoluteFilePath = Path.Combine(Application.persistentDataPath, file); - + var fileName = Path.GetFileNameWithoutExtension(file); var extension = Path.GetExtension(file).ToLower(); var guid = Guid.NewGuid(); var newFilePathRelative = guid + extension; var newFilePathAbsolute = Path.Combine(Application.persistentDataPath, guid + extension); - - Debug.Log(absoluteFilePath + " will be copied to: " + newFilePathAbsolute); - File.Copy(absoluteFilePath, newFilePathAbsolute); + + // var newFilePathRelative = Path.Combine(fileName + extension); + using (FileStream fileStream = File.Create(newFilePathAbsolute)) + { + // byte[] bytes = new byte[] { 0, 1, 2, 3, 5 }; + // fileStream.Write(bytes); + Debug.Log(absoluteFilePath + " will be copied to: " + newFilePathAbsolute); + var fileBytes = File.ReadAllBytes(absoluteFilePath); + // var fileStream = File.Create(newFilePathAbsolute); + Debug.Log("read: " + fileBytes.Length + " bytes"); + fileStream.Write(fileBytes, 0, fileBytes.Length); + Debug.Log("writing: " + fileBytes.Length + " bytes"); + File.WriteAllBytes(newFilePathAbsolute, fileBytes); + // File.Copy(absoluteFilePath, newFilePathAbsolute); + } + if (extension.StartsWith('.')) extension = extension.Substring(1); - + var fileTypeEvent = fileTypeEvents.FirstOrDefault(fte => fte.Extension.ToLower() == extension); - + Debug.Log("processing file: " + newFilePathRelative); - - if(fileTypeEvent != null) + + if (fileTypeEvent != null) { var localFile = new LocalFile() { @@ -62,6 +75,7 @@ public void ProcessFile(string file) OriginalFileName = fileName }; + fileTypeEvent.FileReceived.Invoke(localFile); } else @@ -70,4 +84,4 @@ public void ProcessFile(string file) } } } -} +} \ No newline at end of file