mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Fix IOUtility creating folders for file paths
This commit is contained in:
parent
d530d10798
commit
957d80c7ec
@ -80,7 +80,7 @@ namespace UnityExplorer.CacheObject.IValues
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = IOUtility.EnsureValidDirectory(SaveFilePath.Text);
|
var path = IOUtility.EnsureValidFilePath(SaveFilePath.Text);
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
|
@ -11,14 +11,15 @@ namespace UnityExplorer
|
|||||||
private static readonly char[] invalidDirectoryCharacters = Path.GetInvalidPathChars();
|
private static readonly char[] invalidDirectoryCharacters = Path.GetInvalidPathChars();
|
||||||
private static readonly char[] invalidFilenameCharacters = Path.GetInvalidFileNameChars();
|
private static readonly char[] invalidFilenameCharacters = Path.GetInvalidFileNameChars();
|
||||||
|
|
||||||
public static string EnsureValidDirectory(string path)
|
public static string EnsureValidFilePath(string fullPathWithFile)
|
||||||
{
|
{
|
||||||
path = string.Concat(path.Split(invalidDirectoryCharacters));
|
// Remove invalid path characters
|
||||||
|
fullPathWithFile = string.Concat(fullPathWithFile.Split(invalidDirectoryCharacters));
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
// Create directory (does nothing if it exists)
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(Path.GetDirectoryName(fullPathWithFile));
|
||||||
|
|
||||||
return path;
|
return fullPathWithFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string EnsureValidFilename(string filename)
|
public static string EnsureValidFilename(string filename)
|
||||||
|
@ -644,7 +644,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
var fitter = imageObj.AddComponent<ContentSizeFitter>();
|
var fitter = imageObj.AddComponent<ContentSizeFitter>();
|
||||||
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
textureImage = imageObj.AddComponent<Image>();
|
textureImage = imageObj.AddComponent<Image>();
|
||||||
textureImageLayout = UIFactory.SetLayoutElement(imageObj, flexibleWidth: 9999, flexibleHeight: 9999);
|
textureImageLayout = UIFactory.SetLayoutElement(imageObj, flexibleWidth: 1, flexibleHeight: 1);
|
||||||
|
|
||||||
textureViewer.SetActive(false);
|
textureViewer.SetActive(false);
|
||||||
}
|
}
|
||||||
@ -664,6 +664,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
textureImage.sprite = sprite;
|
textureImage.sprite = sprite;
|
||||||
|
|
||||||
textureImageLayout.preferredHeight = sprite.rect.height;
|
textureImageLayout.preferredHeight = sprite.rect.height;
|
||||||
|
// not really working, its always stretched horizontally for some reason.
|
||||||
textureImageLayout.preferredWidth = sprite.rect.width;
|
textureImageLayout.preferredWidth = sprite.rect.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,7 +689,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = IOUtility.EnsureValidDirectory(path);
|
path = IOUtility.EnsureValidFilePath(path);
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
@ -699,7 +700,6 @@ namespace UnityExplorer.Inspectors
|
|||||||
tex = TextureUtilProvider.ForceReadTexture(tex);
|
tex = TextureUtilProvider.ForceReadTexture(tex);
|
||||||
|
|
||||||
byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);
|
byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);
|
||||||
|
|
||||||
File.WriteAllBytes(path, data);
|
File.WriteAllBytes(path, data);
|
||||||
|
|
||||||
if (tex != TextureRef)
|
if (tex != TextureRef)
|
||||||
|
@ -34,7 +34,7 @@ namespace UnityExplorer.Loader.ML
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This wrapper exists to handle the arbitrary "LemonAction" delegates which ML now uses in 0.4.4+.
|
// This wrapper exists to handle the "LemonAction" delegates which ML now uses in 0.4.4+.
|
||||||
// Reflection is required since the delegate type changed between 0.4.3 and 0.4.4.
|
// Reflection is required since the delegate type changed between 0.4.3 and 0.4.4.
|
||||||
// A wrapper class is required to link the MelonPreferences_Entry and the delegate instance.
|
// A wrapper class is required to link the MelonPreferences_Entry and the delegate instance.
|
||||||
public class EntryDelegateWrapper<T>
|
public class EntryDelegateWrapper<T>
|
||||||
|
@ -62,7 +62,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
private void SetupIO()
|
private void SetupIO()
|
||||||
{
|
{
|
||||||
var path = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Logs");
|
var path = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Logs");
|
||||||
path = IOUtility.EnsureValidDirectory(path);
|
path = IOUtility.EnsureValidFilePath(path);
|
||||||
|
|
||||||
// clean old log(s)
|
// clean old log(s)
|
||||||
var files = Directory.GetFiles(path);
|
var files = Directory.GetFiles(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user