Skip to content

Commit

Permalink
fix: read command does not work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Dec 21, 2023
1 parent 2160f17 commit cbe827a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ void FindTheFile() {
if (fileDirectory != null) {
// Path.Combine can handle the case when filePath is an absolute path
string absoluteOrRelativePath = Path.Combine(fileDirectory, filePath);
if (!absoluteOrRelativePath.EndsWith(".tas", StringComparison.InvariantCulture)) {
absoluteOrRelativePath += ".tas";
}
if (File.Exists(absoluteOrRelativePath)) {
filePath = absoluteOrRelativePath;
} else if (Directory.GetParent(absoluteOrRelativePath) is { } directoryInfo && Directory.Exists(directoryInfo.ToString())) {
List<string> files = Directory.GetFiles(directoryInfo.ToString(), $"{Path.GetFileName(filePath)}*.tas").ToList();
List<string> files = Directory.GetFiles(directoryInfo.ToString(), $"{Path.GetFileNameWithoutExtension(filePath)}*.tas").ToList();
files.Sort((s1, s2) => string.Compare(s1, s2, StringComparison.InvariantCulture));
if (files.FirstOrDefault() is { } shortenedFilePath) {
filePath = shortenedFilePath;
Expand Down
6 changes: 5 additions & 1 deletion Studio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,14 @@ string FindTheFile(string fileDirectory, string filePath) {
if (fileDirectory != null) {
// Path.Combine can handle the case when filePath is an absolute path
string absoluteOrRelativePath = Path.Combine(fileDirectory, filePath);
if (!absoluteOrRelativePath.EndsWith(".tas", StringComparison.InvariantCulture)) {
absoluteOrRelativePath += ".tas";
}
if (File.Exists(absoluteOrRelativePath) && absoluteOrRelativePath != CurrentFileName) {
filePath = absoluteOrRelativePath;
} else if (Directory.GetParent(absoluteOrRelativePath) is { } directoryInfo && Directory.Exists(directoryInfo.ToString())) {
string[] files = Directory.GetFiles(directoryInfo.ToString(), $"{Path.GetFileName(filePath)}*.tas");
List<string> files = Directory.GetFiles(directoryInfo.ToString(), $"{Path.GetFileNameWithoutExtension(filePath)}*.tas").ToList();
files.Sort((s1, s2) => string.Compare(s1, s2, StringComparison.InvariantCulture));
if (files.FirstOrDefault(path => path != CurrentFileName) is { } shortenedFilePath) {
filePath = shortenedFilePath;
}
Expand Down

0 comments on commit cbe827a

Please sign in to comment.