Skip to content

Commit 20a5f34

Browse files
committed
added template support (in new project dialog), fix scrollbar colors upgrade and new project windows, add TarGz handler code
1 parent a2b8d59 commit 20a5f34

File tree

7 files changed

+159
-16
lines changed

7 files changed

+159
-16
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// source https://gist.github.com/Su-s/438be493ae692318c73e30367cbc5c2a
2+
3+
using System;
4+
using System.IO;
5+
using System.IO.Compression;
6+
using System.Text;
7+
8+
namespace TarLib
9+
{
10+
public class Tar
11+
{
12+
/// <summary>
13+
/// Extracts a <i>.tar.gz</i> archive to the specified directory.
14+
/// </summary>
15+
/// <param name="filename">The <i>.tar.gz</i> to decompress and extract.</param>
16+
/// <param name="outputDir">Output directory to write the files.</param>
17+
public static void ExtractTarGz(string filename, string outputDir)
18+
{
19+
using (var stream = File.OpenRead(filename)) ExtractTarGz(stream, outputDir);
20+
}
21+
22+
/// <summary>
23+
/// Extracts a <i>.tar.gz</i> archive stream to the specified directory.
24+
/// </summary>
25+
/// <param name="stream">The <i>.tar.gz</i> to decompress and extract.</param>
26+
/// <param name="outputDir">Output directory to write the files.</param>
27+
public static void ExtractTarGz(Stream stream, string outputDir)
28+
{
29+
using (var gzip = new GZipStream(stream, CompressionMode.Decompress))
30+
{
31+
ExtractTar(gzip, outputDir);
32+
}
33+
}
34+
35+
/// <summary>
36+
/// Extractes a <c>tar</c> archive to the specified directory.
37+
/// </summary>
38+
/// <param name="filename">The <i>.tar</i> to extract.</param>
39+
/// <param name="outputDir">Output directory to write the files.</param>
40+
public static void ExtractTar(string filename, string outputDir)
41+
{
42+
using (var stream = File.OpenRead(filename))
43+
ExtractTar(stream, outputDir);
44+
}
45+
46+
/// <summary>
47+
/// Extractes a <c>tar</c> archive to the specified directory.
48+
/// </summary>
49+
/// <param name="stream">The <i>.tar</i> to extract.</param>
50+
/// <param name="outputDir">Output directory to write the files.</param>
51+
public static void ExtractTar(Stream stream, string outputDir)
52+
{
53+
var buffer = new byte[100];
54+
// store current position here
55+
long pos = 0;
56+
while (true)
57+
{
58+
pos += stream.Read(buffer, 0, 100);
59+
var name = Encoding.ASCII.GetString(buffer).Trim('\0');
60+
if (String.IsNullOrWhiteSpace(name)) break;
61+
FakeSeekForward(stream, 24);
62+
pos += 24;
63+
64+
pos += stream.Read(buffer, 0, 12);
65+
var size = Convert.ToInt64(Encoding.UTF8.GetString(buffer, 0, 12).Trim('\0').Trim(), 8);
66+
FakeSeekForward(stream, 376);
67+
pos += 376;
68+
69+
var output = Path.Combine(outputDir, name);
70+
71+
// only include these folders
72+
var include = (output.IndexOf("package/ProjectData~/Assets/") > -1);
73+
include |= (output.IndexOf("package/ProjectData~/ProjectSettings/") > -1);
74+
include |= (output.IndexOf("package/ProjectData~/Packages/") > -1);
75+
76+
// rename output path from "package/ProjectData~/Assets/" into "Assets/"
77+
output = output.Replace("package/ProjectData~/", "");
78+
79+
if (include == true && !Directory.Exists(Path.GetDirectoryName(output))) Directory.CreateDirectory(Path.GetDirectoryName(output));
80+
81+
if (!name.Equals("./", StringComparison.InvariantCulture))
82+
{
83+
if (include == true)
84+
{
85+
//Console.WriteLine("output=" + output);
86+
using (var str = File.Open(output, FileMode.OpenOrCreate, FileAccess.Write))
87+
{
88+
var buf = new byte[size];
89+
pos += stream.Read(buf, 0, buf.Length);
90+
// take only data from this folder
91+
str.Write(buf, 0, buf.Length);
92+
}
93+
}
94+
else
95+
{
96+
//pos += size;
97+
var buf = new byte[size];
98+
pos += stream.Read(buf, 0, buf.Length);
99+
//FakeSeekForward(stream, (int)size);
100+
}
101+
}
102+
103+
var offset = (int)(512 - (pos % 512));
104+
if (offset == 512) offset = 0;
105+
FakeSeekForward(stream, offset);
106+
pos += offset;
107+
}
108+
}
109+
110+
private static void FakeSeekForward(Stream stream, int offset)
111+
{
112+
if (stream.CanSeek)
113+
stream.Seek(offset, SeekOrigin.Current);
114+
else
115+
{
116+
int bytesRead = 0;
117+
var buffer = new byte[offset];
118+
while (bytesRead < offset)
119+
{
120+
int read = stream.Read(buffer, bytesRead, offset - bytesRead);
121+
if (read == 0)
122+
throw new EndOfStreamException();
123+
bytesRead += read;
124+
}
125+
}
126+
}
127+
}
128+
}

UnityLauncherPro/MainWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<Setter Property="VerticalContentAlignment" Value="Center" />
6060
<Setter Property="HorizontalAlignment" Value="Stretch" />
6161
<Setter Property="VerticalAlignment" Value="Center" />
62-
62+
6363
<Setter Property="Template">
6464
<Setter.Value>
6565
<ControlTemplate TargetType="{x:Type ComboBox}">
@@ -141,7 +141,7 @@
141141
<Setter Property="VerticalContentAlignment" Value="Center" />
142142
<Setter Property="HorizontalAlignment" Value="Stretch" />
143143
<Setter Property="VerticalAlignment" Value="Center" />-->
144-
144+
145145
<Setter Property="Template">
146146
<Setter.Value>
147147
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
@@ -887,7 +887,7 @@
887887
<Label Content="Webgl Relative Build Path (inside Builds/)" Foreground="{DynamicResource ThemeButtonForeground}" />
888888
</StackPanel>
889889
</StackPanel>
890-
890+
891891
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
892892
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" Margin="0,0,0,4" ToolTip="" HorizontalAlignment="Left"/>
893893
<CheckBox x:Name="chkRunAutomatically" Content="Run this app automatically on startup" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="" HorizontalAlignment="Left" Checked="ChkRunAutomatically_Checked" Unchecked="ChkRunAutomatically_Checked"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ void CreateNewEmptyProject()
13961396
Console.WriteLine("Create project " + NewProject.newVersion + " : " + projectPath);
13971397
if (string.IsNullOrEmpty(projectPath)) return;
13981398

1399-
Tools.FastCreateProject(NewProject.newVersion, projectPath, NewProject.newProjectName);
1399+
Tools.FastCreateProject(NewProject.newVersion, projectPath, NewProject.newProjectName, NewProject.templateZipPath);
14001400
}
14011401
else // false, cancel
14021402
{

UnityLauncherPro/NewProject.xaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
<Setter.Value>
7272
<ControlTemplate TargetType="{x:Type RepeatButton}">
7373
<!-- button background -->
74-
<Border Name="Border" Margin="1" CornerRadius="0" BorderThickness="0" Background="{DynamicResource ButtonBackground}" BorderBrush="{x:Null}">
74+
<Border Name="Border" Margin="1" CornerRadius="0" BorderThickness="0" Background="{DynamicResource ThemeButtonBackground}" BorderBrush="{x:Null}">
7575
<!-- arrow sign -->
76-
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ScrollArrowForeground}" Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
76+
<Path HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{DynamicResource ThemeScrollArrowForeground}" Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />
7777
</Border>
7878
<ControlTemplate.Triggers>
7979
<!-- NOTE order matters, if pressed is before mouseover, then it gets overwritten -->
@@ -134,7 +134,7 @@
134134
<RowDefinition MaxHeight="18"/>
135135
</Grid.RowDefinitions>
136136
<!-- scrollbar background -->
137-
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ScrollBarBackground}" />
137+
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ThemeScrollBarBackground}" />
138138
<!-- scrollbar top button -->
139139
<RepeatButton Grid.Row="0" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
140140
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true">
@@ -143,7 +143,7 @@
143143
</Track.DecreaseRepeatButton>
144144
<Track.Thumb>
145145
<!-- scrollbar foreground -->
146-
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ScrollBarFill}" BorderBrush="{x:Null}"/>
146+
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ThemeScrollBarFill}" BorderBrush="{x:Null}"/>
147147
</Track.Thumb>
148148
<Track.IncreaseRepeatButton>
149149
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
@@ -171,10 +171,18 @@
171171
<Grid>
172172
<StackPanel Margin="10,3">
173173
<Label Content="Unity Version " Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
174-
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" Height="120" Margin="3,0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" SelectionChanged="GridAvailableVersions_SelectionChanged" IsTabStop="True" TabIndex="1" KeyboardNavigation.TabNavigation = "None" Loaded="GridAvailableVersions_Loaded" EnableRowVirtualization="False">
174+
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" Height="120" Margin="3,0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" SelectionChanged="GridAvailableVersions_SelectionChanged" IsTabStop="True" TabIndex="1" KeyboardNavigation.TabNavigation = "None" Loaded="GridAvailableVersions_Loaded" EnableRowVirtualization="False" VerticalScrollBarVisibility="Visible">
175175
<DataGrid.Columns>
176176
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" CanUserResize="False" MinWidth="300" />
177177
</DataGrid.Columns>
178+
<!--<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
179+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
180+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
181+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
182+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
183+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
184+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
185+
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2018.3.13f1"/>-->
178186
</DataGrid>
179187

180188

@@ -187,7 +195,7 @@
187195
<Label Grid.Column="0" Content="Project Name:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="5,5,5,0" />
188196
<Label Grid.Column="2" Content="Template:" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0" Padding="5,5,5,0" />
189197
</Grid>
190-
198+
191199
<Grid HorizontalAlignment="Stretch" Margin="0,3,0,0">
192200
<Grid.ColumnDefinitions>
193201
<ColumnDefinition Width="60*"/>

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public partial class NewProject : Window
1111
public static string newProjectName = null;
1212
public static string newVersion = null;
1313
public static string newName = null;
14+
public static string templateZipPath = null;
1415

1516
public NewProject(string unityVersion, string suggestedName, string targetFolder)
1617
{
@@ -45,6 +46,7 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
4546

4647
private void BtnCreateNewProject_Click(object sender, RoutedEventArgs e)
4748
{
49+
templateZipPath = ((KeyValuePair<string, string>)cmbNewProjectTemplate.SelectedValue).Value;
4850
UpdateSelectedVersion();
4951
DialogResult = true;
5052
}

UnityLauncherPro/Tools.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ public static string BrowseForOutputFolder(string title)
877877
return null;
878878
}
879879

880-
public static void FastCreateProject(string version, string baseFolder, string projectName = null)
880+
public static void FastCreateProject(string version, string baseFolder, string projectName = null, string templateZipPath = null)
881881
{
882882
// check for base folders in settings tab
883883
if (string.IsNullOrEmpty(baseFolder) == true)
@@ -915,6 +915,12 @@ public static void FastCreateProject(string version, string baseFolder, string p
915915
// create folder
916916
CreateEmptyProjectFolder(newPath, version);
917917

918+
// unzip template, if any
919+
if (templateZipPath != null)
920+
{
921+
TarLib.Tar.ExtractTarGz(templateZipPath, newPath);
922+
}
923+
918924
// launch empty project
919925
var proj = new Project();
920926
proj.Path = Path.Combine(baseFolder, newPath);
@@ -1010,7 +1016,7 @@ public static Dictionary<string, string> ScanTemplates(string unityInstallPath)
10101016
if (Directory.Exists(templateFolder) == false) return items;
10111017

10121018
var fileEntries = Directory.GetFiles(templateFolder).ToList();
1013-
1019+
10141020
// process found files
10151021
for (int i = fileEntries.Count - 1; i > -1; i--)
10161022
{
@@ -1023,7 +1029,6 @@ public static Dictionary<string, string> ScanTemplates(string unityInstallPath)
10231029
{
10241030
// cleanup name
10251031
var name = Path.GetFileName(fileEntries[i]).Replace("com.unity.template.", "").Replace(".tgz", "");
1026-
10271032
items.Add(name, fileEntries[i]);
10281033
}
10291034
}

UnityLauncherPro/UpgradeWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<RowDefinition MaxHeight="18"/>
137137
</Grid.RowDefinitions>
138138
<!-- scrollbar background -->
139-
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ScrollBarBackground}" />
139+
<Border Grid.RowSpan="3" CornerRadius="0" Background="{DynamicResource ThemeScrollBarBackground}" />
140140
<!-- scrollbar top button -->
141141
<RepeatButton Grid.Row="0" Style="{StaticResource ScrollBarLineButton}" Height="18" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
142142
<Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true">
@@ -145,7 +145,7 @@
145145
</Track.DecreaseRepeatButton>
146146
<Track.Thumb>
147147
<!-- scrollbar foreground -->
148-
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ScrollBarFill}" BorderBrush="{x:Null}"/>
148+
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0" Background="{DynamicResource ThemeScrollBarFill}" BorderBrush="{x:Null}"/>
149149
</Track.Thumb>
150150
<Track.IncreaseRepeatButton>
151151
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
@@ -189,7 +189,7 @@
189189
<Button Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="0,434,8,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" Width="159" VerticalAlignment="Top" Height="51" Click="BtnUpgradeProject_Click" >
190190
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Upgrade Project"/>
191191
</Button>
192-
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" HorizontalAlignment="Left" Height="304" Margin="10,121,0,0" VerticalAlignment="Top" Width="393" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick">
192+
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" HorizontalAlignment="Left" Height="304" Margin="10,121,0,0" VerticalAlignment="Top" Width="393" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick" VerticalScrollBarVisibility="Visible">
193193
<DataGrid.Columns>
194194
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" />
195195
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" />

0 commit comments

Comments
 (0)