Skip to content

Commit 60369ea

Browse files
Fix update/clone project to work cross platform
1 parent 582e6b0 commit 60369ea

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

MSUScripter/Services/ControlServices/CopyProjectWindowService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public void SetProject(MsuProject project, bool isCopy)
3636

3737
_model.IsCopy = isCopy;
3838
_model.ButtonText = isCopy ? "Copy Project" : "Open Project";
39+
40+
var title = string.IsNullOrEmpty(project.BasicInfo.PackName) ? "Project" : project.BasicInfo.PackName;
41+
_model.Title = isCopy ? $"Copy {title}" : $"Update {title}";
3942

4043
var paths = new List<CopyProjectViewModel>();
4144

MSUScripter/ViewModels/CopyProjectWindowViewModel.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public class CopyProjectWindowViewModel : TranslatedViewModelBase
2020

2121
[Reactive] public string ButtonText { get; set; } = "Update Project";
2222

23+
[Reactive] public string Title { get; set; } = "Update Project";
24+
25+
public string TopText =>
26+
IsCopy
27+
? "Update the paths below as desired for the new project."
28+
: "One or more input files are missing. Update them below or continue opening the project.";
29+
2330
public bool IsCopy { get; set; }
2431

2532
public override ViewModelBase DesignerExample()
@@ -48,9 +55,8 @@ public CopyProjectViewModel(string? path)
4855
NewPath = path ?? "";
4956
if (!string.IsNullOrEmpty(PreviousPath))
5057
{
51-
var file = new FileInfo(PreviousPath);
52-
BaseFileName = file.Name;
53-
Extension = file.Extension;
58+
BaseFileName = GetFileNameFromAnyPath(PreviousPath);
59+
Extension = Path.GetExtension(PreviousPath);
5460
}
5561
}
5662

@@ -73,4 +79,21 @@ public override ViewModelBase DesignerExample()
7379
{
7480
return this;
7581
}
82+
83+
static string GetFileNameFromAnyPath(string path)
84+
{
85+
if (string.IsNullOrEmpty(path))
86+
return string.Empty;
87+
88+
// Normalize to system-independent form
89+
path = path.Replace('\\', '/');
90+
91+
// Extract after last '/'
92+
int lastSlash = path.LastIndexOf('/');
93+
if (lastSlash >= 0 && lastSlash < path.Length - 1)
94+
return path.Substring(lastSlash + 1);
95+
96+
// Fall back to entire string if no slash
97+
return path;
98+
}
7699
}

MSUScripter/Views/CopyProjectWindow.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ xmlns:controls="using:AvaloniaControls.Controls"
1010
Height="768"
1111
x:Class="MSUScripter.Views.CopyProjectWindow"
1212
Icon="/Assets/MSUScripterIcon.ico"
13-
Title="Clone Project"
13+
Title="{Binding Title}"
1414
x:DataType="viewModels:CopyProjectWindowViewModel">
1515
<LayoutTransformControl Name="MainLayout">
1616
<DockPanel>
17-
17+
<TextBlock DockPanel.Dock="Top" Margin="5" Text="{Binding TopText}" />
1818
<controls:HeaderFooter DockPanel.Dock="Bottom">
1919
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
2020
<Button

0 commit comments

Comments
 (0)