@@ -1705,10 +1705,27 @@ public static Project FastCreateProject(string version, string baseFolder, strin
1705
1705
// create folder
1706
1706
CreateEmptyProjectFolder ( newPath , version ) ;
1707
1707
1708
- // unzip template, if any
1708
+ // unzip or copy template
1709
1709
if ( templateZipPath != null )
1710
1710
{
1711
- TarLib . Tar . ExtractTarGz ( templateZipPath , newPath ) ;
1711
+ //Console.WriteLine(templateZipPath);
1712
+
1713
+ if ( File . Exists ( templateZipPath ) )
1714
+ {
1715
+ TarLib . Tar . ExtractTarGz ( templateZipPath , newPath ) ;
1716
+ }
1717
+ else if ( Directory . Exists ( templateZipPath ) )
1718
+ {
1719
+ try
1720
+ {
1721
+ CopyDirectory ( templateZipPath , newPath ) ;
1722
+ }
1723
+ catch ( Exception ex )
1724
+ {
1725
+ SetStatus ( "Error copying template folder: " + ex . Message ) ;
1726
+ }
1727
+ }
1728
+
1712
1729
}
1713
1730
1714
1731
// copy init file into project
@@ -1830,24 +1847,38 @@ public static Dictionary<string, string> ScanTemplates(string unityInstallPath)
1830
1847
var templateFolder = Path . Combine ( unityPath , "Data/Resources/PackageManager/ProjectTemplates/" ) ;
1831
1848
if ( Directory . Exists ( templateFolder ) == false ) return items ;
1832
1849
1850
+ // get all files in template folder
1833
1851
var fileEntries = Directory . GetFiles ( templateFolder ) . ToList ( ) ;
1834
1852
1835
1853
// process found files
1836
- for ( int i = fileEntries . Count - 1 ; i > - 1 ; i -- )
1854
+ for ( int i = 0 ; i < fileEntries . Count ; i ++ )
1837
1855
{
1856
+ //Console.WriteLine(fileEntries[i]);
1838
1857
// check if its tgz
1839
- if ( fileEntries [ i ] . IndexOf ( ".tgz" ) == - 1 )
1840
- {
1841
- fileEntries . RemoveAt ( i ) ;
1842
- }
1843
- else
1858
+ if ( fileEntries [ i ] . ToLower ( ) . IndexOf ( ".tgz" ) > - 1 )
1844
1859
{
1845
- // cleanup name
1860
+ // cleanup displayed name
1846
1861
var name = Path . GetFileName ( fileEntries [ i ] ) . Replace ( "com.unity.template." , "" ) . Replace ( ".tgz" , "" ) ;
1847
1862
items . Add ( name , fileEntries [ i ] ) ;
1848
1863
}
1849
1864
}
1850
1865
1866
+ // 2018.4 has folders instead of tgz files
1867
+ // BUT do this for all versions, in case user has added custom template folders (that contain Assets/ folder)
1868
+ var dirEntries = Directory . GetDirectories ( templateFolder ) . ToList ( ) ;
1869
+ for ( int i = 0 ; i < dirEntries . Count ; i ++ )
1870
+ {
1871
+ //Console.WriteLine(dirEntries[i]);
1872
+ // if it has com.unity.template. prefix, then its a template
1873
+ // if that directory contains Assets/ folder, then its a template
1874
+ if ( Directory . Exists ( Path . Combine ( dirEntries [ i ] , "Assets" ) ) == true )
1875
+ {
1876
+ //Console.WriteLine(dirEntries[i]);
1877
+ var name = Path . GetFileName ( dirEntries [ i ] ) . Replace ( "com.unity.template." , "" ) ;
1878
+ items . Add ( name , dirEntries [ i ] ) ;
1879
+ }
1880
+ }
1881
+
1851
1882
return items ;
1852
1883
}
1853
1884
@@ -2792,10 +2823,7 @@ public static string GetSafeFilePath(string subfolder, string fileName)
2792
2823
// 1) Preferred: under the app folder
2793
2824
string preferredDir = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , subfolder ) ;
2794
2825
// 2) Fallback: in LocalAppData
2795
- string fallbackDir = Path . Combine (
2796
- Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ,
2797
- "UnityLauncherPro" ,
2798
- subfolder ) ;
2826
+ string fallbackDir = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "UnityLauncherPro" , subfolder ) ;
2799
2827
2800
2828
try
2801
2829
{
@@ -2818,9 +2846,26 @@ public static string GetSafeFilePath(string subfolder, string fileName)
2818
2846
return Path . Combine ( fallbackDir , fileName ) ;
2819
2847
}
2820
2848
2849
+ // copy directory structure (for template folder)
2850
+ public static void CopyDirectory ( string sourceDir , string targetDir )
2851
+ {
2852
+ // Create the target directory if it doesn't exist
2853
+ Directory . CreateDirectory ( targetDir ) ;
2821
2854
2855
+ // Copy all files
2856
+ foreach ( var file in Directory . GetFiles ( sourceDir ) )
2857
+ {
2858
+ var destFile = Path . Combine ( targetDir , Path . GetFileName ( file ) ) ;
2859
+ File . Copy ( file , destFile , overwrite : false ) ;
2860
+ }
2822
2861
2823
-
2862
+ // Recursively copy subdirectories
2863
+ foreach ( var directory in Directory . GetDirectories ( sourceDir ) )
2864
+ {
2865
+ var destDir = Path . Combine ( targetDir , Path . GetFileName ( directory ) ) ;
2866
+ CopyDirectory ( directory , destDir ) ;
2867
+ }
2868
+ }
2824
2869
2825
2870
} // class
2826
2871
0 commit comments