Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 957d80c

Browse files
committed
Fix IOUtility creating folders for file paths
1 parent d530d10 commit 957d80c

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

src/CacheObject/IValues/InteractiveString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void OnSaveFileClicked()
8080
return;
8181
}
8282

83-
var path = IOUtility.EnsureValidDirectory(SaveFilePath.Text);
83+
var path = IOUtility.EnsureValidFilePath(SaveFilePath.Text);
8484

8585
if (File.Exists(path))
8686
File.Delete(path);

src/Core/Utility/IOUtility.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ public static class IOUtility
1111
private static readonly char[] invalidDirectoryCharacters = Path.GetInvalidPathChars();
1212
private static readonly char[] invalidFilenameCharacters = Path.GetInvalidFileNameChars();
1313

14-
public static string EnsureValidDirectory(string path)
14+
public static string EnsureValidFilePath(string fullPathWithFile)
1515
{
16-
path = string.Concat(path.Split(invalidDirectoryCharacters));
16+
// Remove invalid path characters
17+
fullPathWithFile = string.Concat(fullPathWithFile.Split(invalidDirectoryCharacters));
1718

18-
if (!Directory.Exists(path))
19-
Directory.CreateDirectory(path);
19+
// Create directory (does nothing if it exists)
20+
Directory.CreateDirectory(Path.GetDirectoryName(fullPathWithFile));
2021

21-
return path;
22+
return fullPathWithFile;
2223
}
2324

2425
public static string EnsureValidFilename(string filename)

src/Inspectors/ReflectionInspector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ private void ConstructTextureHelper()
644644
var fitter = imageObj.AddComponent<ContentSizeFitter>();
645645
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
646646
textureImage = imageObj.AddComponent<Image>();
647-
textureImageLayout = UIFactory.SetLayoutElement(imageObj, flexibleWidth: 9999, flexibleHeight: 9999);
647+
textureImageLayout = UIFactory.SetLayoutElement(imageObj, flexibleWidth: 1, flexibleHeight: 1);
648648

649649
textureViewer.SetActive(false);
650650
}
@@ -664,6 +664,7 @@ private void SetTextureViewer()
664664
textureImage.sprite = sprite;
665665

666666
textureImageLayout.preferredHeight = sprite.rect.height;
667+
// not really working, its always stretched horizontally for some reason.
667668
textureImageLayout.preferredWidth = sprite.rect.width;
668669
}
669670

@@ -688,7 +689,7 @@ private void OnSaveTextureClicked()
688689
return;
689690
}
690691

691-
path = IOUtility.EnsureValidDirectory(path);
692+
path = IOUtility.EnsureValidFilePath(path);
692693

693694
if (File.Exists(path))
694695
File.Delete(path);
@@ -699,7 +700,6 @@ private void OnSaveTextureClicked()
699700
tex = TextureUtilProvider.ForceReadTexture(tex);
700701

701702
byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);
702-
703703
File.WriteAllBytes(path, data);
704704

705705
if (tex != TextureRef)

src/Loader/MelonLoader/MelonLoaderConfigHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void LoadConfig()
3434
}
3535
}
3636

37-
// This wrapper exists to handle the arbitrary "LemonAction" delegates which ML now uses in 0.4.4+.
37+
// This wrapper exists to handle the "LemonAction" delegates which ML now uses in 0.4.4+.
3838
// Reflection is required since the delegate type changed between 0.4.3 and 0.4.4.
3939
// A wrapper class is required to link the MelonPreferences_Entry and the delegate instance.
4040
public class EntryDelegateWrapper<T>

src/UI/Panels/LogPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override void SetActive(bool active)
6262
private void SetupIO()
6363
{
6464
var path = Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Logs");
65-
path = IOUtility.EnsureValidDirectory(path);
65+
path = IOUtility.EnsureValidFilePath(path);
6666

6767
// clean old log(s)
6868
var files = Directory.GetFiles(path);

0 commit comments

Comments
 (0)