Skip to content

Commit c11f256

Browse files
committed
add -cloneFromTemplate, split online template description to 3 rows, make download online template better #147
1 parent ee6df72 commit c11f256

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

UnityLauncherPro/NewProject.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@
117117
HorizontalAlignment="Stretch"/>
118118
<Button x:Name="btnDownloadTemplate"
119119
ToolTip="Download Template"
120-
Content=""
121-
Height="24"
122-
Width="24"
120+
Content="📥"
121+
Height="32"
122+
Width="32"
123123
HorizontalAlignment="Right"
124124
VerticalAlignment="Top"
125-
FontSize="14"
126-
Margin="2"
125+
FontSize="18"
126+
Margin="1"
127127
Padding="0"
128128
BorderBrush="{x:Null}"
129-
Opacity="0.85"
129+
Opacity="0.9"
130130
Click="btnDownloadTemplate_Click"
131131
Tag="{Binding}">
132132
<Button.Style>

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,13 @@ private List<OnlineTemplateItem> ParseTemplatesFromJson(string json)
589589

590590
// Parse individual fields
591591
var tarballUrl = ExtractNestedJsonString(nodeJson, "\"tarball\"", "\"url\"");
592+
var rawDescription = ExtractJsonString(nodeJson, "\"description\"");
593+
var splitDescription = SplitDescriptionIntoThree(rawDescription);
592594

593595
var template = new OnlineTemplateItem
594596
{
595597
Name = ExtractJsonString(nodeJson, "\"name\""),
596-
Description = ExtractJsonString(nodeJson, "\"description\""),
598+
Description = splitDescription,
597599
Type = ExtractJsonString(nodeJson, "\"type\""),
598600
RenderPipeline = ExtractJsonString(nodeJson, "\"renderPipeline\""),
599601
PreviewImageURL = ExtractNestedJsonString(nodeJson, "\"previewImage\"", "\"url\"") ?? "pack://application:,,,/Images/icon.png",
@@ -630,6 +632,25 @@ private List<OnlineTemplateItem> ParseTemplatesFromJson(string json)
630632

631633
return templates;
632634
}
635+
636+
private string SplitDescriptionIntoThree(string description)
637+
{
638+
if (string.IsNullOrEmpty(description)) return description;
639+
640+
int len = description.Length;
641+
if (len <= 2) return description; // too short to split meaningfully
642+
643+
int firstCut = (len / 3);
644+
int secondCut = (len * 2) / 3;
645+
646+
// Raw split strictly by length/3 as requested
647+
string part1 = description.Substring(0, firstCut).Trim();
648+
string part2 = description.Substring(firstCut, secondCut - firstCut).Trim();
649+
string part3 = description.Substring(secondCut).Trim();
650+
651+
return part1 + Environment.NewLine + part2 + Environment.NewLine + part3;
652+
}
653+
633654
private string ExtractJsonString(string json, string key)
634655
{
635656
int keyIndex = json.IndexOf(key + ":");
@@ -742,6 +763,10 @@ private void listOnlineTemplates_SelectionChanged(object sender, SelectionChange
742763
// Disable built-in template dropdown when online template is selected
743764
cmbNewProjectTemplate.IsEnabled = false;
744765
cmbNewProjectTemplate.SelectedIndex = 0; // Reset to default
766+
767+
// disable create button if template not downloaded yet
768+
btnCreateNewProject.IsEnabled = selectedTemplate.IsDownloaded;
769+
btnCreateNewProject.Content = selectedTemplate.IsDownloaded ? "Create Project" : "Download Template First >";
745770
}
746771
else
747772
{
@@ -750,8 +775,13 @@ private void listOnlineTemplates_SelectionChanged(object sender, SelectionChange
750775

751776
// Re-enable built-in template dropdown when no online template is selected
752777
cmbNewProjectTemplate.IsEnabled = true;
778+
779+
// enable create button
780+
btnCreateNewProject.IsEnabled = true;
781+
btnCreateNewProject.Content = "Create Project";
753782
}
754783
}
784+
755785
private async void btnDownloadTemplate_Click(object sender, RoutedEventArgs e)
756786
{
757787
var button = sender as Button;

UnityLauncherPro/Tools.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static void AddProjectToHistory(string projectPath)
226226
}
227227

228228
// NOTE holding alt key (when using alt+o) brings up unity project selector
229-
public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, bool useInitScript = false, bool upgrade = false)
229+
public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, bool useInitScript = false, bool upgrade = false, bool cloneFromTemplate = false)
230230
{
231231
if (proj == null) return null;
232232

@@ -298,7 +298,7 @@ public static Process LaunchProject(Project proj, DataGrid dataGridRef = null, b
298298
var cmd = "\"" + unityExePath + "\"";
299299
newProcess.StartInfo.FileName = cmd;
300300

301-
var unitycommandlineparameters = " -projectPath " + "\"" + proj.Path + "\"";
301+
string unitycommandlineparameters = (cloneFromTemplate ? " -createproject " : " -projectPath ") + "\"" + proj.Path + "\"";
302302

303303
string customArguments = proj.Arguments;
304304
if (string.IsNullOrEmpty(customArguments) == false)
@@ -1760,16 +1760,19 @@ public static Project FastCreateProject(string version, string baseFolder, strin
17601760
// create folder
17611761
CreateEmptyProjectFolder(newPath, version);
17621762

1763+
bool cloneFromTemplate = false;
17631764
// unzip or copy template
17641765
if (templateZipPath != null)
17651766
{
17661767
// Console.WriteLine(templateZipPath);
17671768

17681769
if (File.Exists(templateZipPath))
17691770
{
1771+
cloneFromTemplate = true;
17701772
try
17711773
{
1772-
TarLib.Tar.ExtractTarGz(templateZipPath, newPath);
1774+
// NOTE no need to extract, unity can handle it with -cloneFromTemplate
1775+
//TarLib.Tar.ExtractTarGz(templateZipPath, newPath);
17731776
}
17741777
catch (Exception ex)
17751778
{
@@ -1778,6 +1781,7 @@ public static Project FastCreateProject(string version, string baseFolder, strin
17781781
}
17791782
else if (Directory.Exists(templateZipPath))
17801783
{
1784+
// this is for folder templates, copy files
17811785
try
17821786
{
17831787
CopyDirectory(templateZipPath, newPath);
@@ -1813,7 +1817,11 @@ public static Project FastCreateProject(string version, string baseFolder, strin
18131817
proj.Modified = DateTime.Now;
18141818
proj.folderExists = true; // have to set this value, so item is green on list
18151819
proj.Arguments = version.Contains("6000") ? (forceDX11 ? "-force-d3d11" : null) : null; // this gets erased later, since its not saved? would be nice to not add it at all though
1816-
var proc = LaunchProject(proj, null, useInitScript);
1820+
if (cloneFromTemplate == true)
1821+
{
1822+
proj.Arguments += " -cloneFromTemplate \"" + templateZipPath + "\"";
1823+
}
1824+
var proc = LaunchProject(proj, null, useInitScript, false, cloneFromTemplate);
18171825
ProcessHandler.Add(proj, proc);
18181826

18191827
return proj;

0 commit comments

Comments
 (0)