Skip to content

Commit

Permalink
attempted to force a copy of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSimons committed Oct 22, 2024
1 parent 52a54f5 commit 654cbc8
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions Assets/Scripts/Layers/Adapters/DataTypeAdapters/FileTypeAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FileTypeEvent
public string Extension;
public UnityEvent<LocalFile> FileReceived;
}

[CreateAssetMenu(menuName = "Netherlands3D/Adapters/FileTypeAdapter", fileName = "FileTypeAdapter", order = 0)]
public class FileTypeAdapter : ScriptableObject
{
Expand All @@ -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()
{
Expand All @@ -62,6 +75,7 @@ public void ProcessFile(string file)
OriginalFileName = fileName
};


fileTypeEvent.FileReceived.Invoke(localFile);
}
else
Expand All @@ -70,4 +84,4 @@ public void ProcessFile(string file)
}
}
}
}
}

0 comments on commit 654cbc8

Please sign in to comment.