Skip to content

Commit 35aa39c

Browse files
committed
Fixed possible crash trying to find Gum location if FRB is added to too-shallow of a path
fixes #1714
1 parent d9ed176 commit 35aa39c

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

Engines/FlatRedBallXNA/FlatRedBall/IO/FilePath.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,25 @@ public override int GetHashCode()
176176

177177
public bool Exists()
178178
{
179-
var standardized = this.StandardizedCaseSensitive;
180-
if(standardized.EndsWith("/"))
179+
try
181180
{
182-
return System.IO.Directory.Exists(this.StandardizedCaseSensitive);
181+
var standardized = this.StandardizedCaseSensitive;
182+
if(standardized.EndsWith("/"))
183+
{
184+
return System.IO.Directory.Exists(this.StandardizedCaseSensitive);
185+
}
186+
else
187+
{
188+
// Update - this may be a directory like "c:/SomeDirectory/" or "c:/SomeDirectory/". We don't know, so we have to check both directory and file:
189+
return System.IO.File.Exists(this.StandardizedCaseSensitive) ||
190+
System.IO.Directory.Exists(this.StandardizedCaseSensitive);
191+
}
183192
}
184-
else
193+
catch(InvalidOperationException)
185194
{
186-
// Update - this may be a directory like "c:/SomeDirectory/" or "c:/SomeDirectory/". We don't know, so we have to check both directory and file:
187-
return System.IO.File.Exists(this.StandardizedCaseSensitive) ||
188-
System.IO.Directory.Exists(this.StandardizedCaseSensitive);
195+
// This can happen if we have a file path with too many ../'s, going past the root
196+
// In that case, the file does not exist
197+
return false;
189198
}
190199
}
191200

FRBDK/Glue/Glue/Plugins/ExportedImplementations/CommandInterfaces/FileCommands.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -563,26 +563,7 @@ public void OpenFileInDefaultProgram(string fileName, string OpensWith = null)
563563
if (string.IsNullOrEmpty(executable) && !WindowsFileAssociation.NativelyHandledExtensions.Contains(effectiveExtension))
564564
{
565565
//Attempt to get relative projects
566-
FilePath? absoluteExe = null;
567-
if (GumFileExtensions.Contains(textExtension.ToLower()))
568-
{
569-
absoluteExe = GlueState.Self.GlueExeDirectory + "../../../../../../Gum/Gum/bin/Debug/Data/Gum.exe";
570-
571-
if(absoluteExe?.Exists() == false)
572-
{
573-
absoluteExe = GlueState.Self.GlueExeDirectory + "Gum/Data/Gum.exe";
574-
}
575-
}
576-
if (String.Equals(textExtension, "achx", StringComparison.OrdinalIgnoreCase))
577-
{
578-
absoluteExe = GlueState.Self.GlueExeDirectory + "../../../../AnimationEditor/PreviewProject/bin/Debug/AnimationEditor.exe";
579-
var foundAnimationEditor = absoluteExe?.Exists() == true;
580-
if(!foundAnimationEditor)
581-
{
582-
// check if it's in the default built location if the user is running from prebuilt:
583-
absoluteExe = GlueState.Self.GlueExeDirectory + "AnimationEditor/AnimationEditor.exe";
584-
}
585-
}
566+
FilePath absoluteExe = TryToGetFilePathFromExtension(textExtension);
586567
if ((absoluteExe != "") && absoluteExe?.Exists() == true)
587568
{
588569
Process.Start(new ProcessStartInfo(absoluteExe.FullPath, fileName));
@@ -655,6 +636,32 @@ void OpenProcess()
655636
}
656637
}
657638

639+
private FilePath TryToGetFilePathFromExtension(string textExtension)
640+
{
641+
FilePath? absoluteExe = null;
642+
if (GumFileExtensions.Contains(textExtension.ToLower()))
643+
{
644+
absoluteExe = GlueState.Self.GlueExeDirectory + "../../../../../../Gum/Gum/bin/Debug/Data/Gum.exe";
645+
646+
if (absoluteExe?.Exists() == false)
647+
{
648+
absoluteExe = GlueState.Self.GlueExeDirectory + "Gum/Data/Gum.exe";
649+
}
650+
}
651+
if (String.Equals(textExtension, "achx", StringComparison.OrdinalIgnoreCase))
652+
{
653+
absoluteExe = GlueState.Self.GlueExeDirectory + "../../../../AnimationEditor/PreviewProject/bin/Debug/AnimationEditor.exe";
654+
var foundAnimationEditor = absoluteExe?.Exists() == true;
655+
if (!foundAnimationEditor)
656+
{
657+
// check if it's in the default built location if the user is running from prebuilt:
658+
absoluteExe = GlueState.Self.GlueExeDirectory + "AnimationEditor/AnimationEditor.exe";
659+
}
660+
}
661+
662+
return absoluteExe;
663+
}
664+
658665
private static string GetFileName(ReferencedFileSave currentReferencedFileSave)
659666
{
660667
string fileName = null;

0 commit comments

Comments
 (0)