Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0febfad

Browse files
committed
allow templates to be folders and .tgz files,fixes#197
1 parent5080404 commit0febfad

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

‎UnityLauncherPro/Tools.cs‎

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,10 +1705,27 @@ public static Project FastCreateProject(string version, string baseFolder, strin
17051705
// create folder
17061706
CreateEmptyProjectFolder(newPath,version);
17071707

1708-
// unziptemplate, if any
1708+
// unzipor copy template
17091709
if(templateZipPath!=null)
17101710
{
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+
elseif(Directory.Exists(templateZipPath))
1718+
{
1719+
try
1720+
{
1721+
CopyDirectory(templateZipPath,newPath);
1722+
}
1723+
catch(Exceptionex)
1724+
{
1725+
SetStatus("Error copying template folder: "+ex.Message);
1726+
}
1727+
}
1728+
17121729
}
17131730

17141731
// copy init file into project
@@ -1830,24 +1847,38 @@ public static Dictionary<string, string> ScanTemplates(string unityInstallPath)
18301847
vartemplateFolder=Path.Combine(unityPath,"Data/Resources/PackageManager/ProjectTemplates/");
18311848
if(Directory.Exists(templateFolder)==false)returnitems;
18321849

1850+
// get all files in template folder
18331851
varfileEntries=Directory.GetFiles(templateFolder).ToList();
18341852

18351853
// process found files
1836-
for(inti=fileEntries.Count-1;i>-1;i--)
1854+
for(inti=0;i<fileEntries.Count;i++)
18371855
{
1856+
//Console.WriteLine(fileEntries[i]);
18381857
// 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)
18441859
{
1845-
// cleanup name
1860+
// cleanupdisplayedname
18461861
varname=Path.GetFileName(fileEntries[i]).Replace("com.unity.template.","").Replace(".tgz","");
18471862
items.Add(name,fileEntries[i]);
18481863
}
18491864
}
18501865

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+
vardirEntries=Directory.GetDirectories(templateFolder).ToList();
1869+
for(inti=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+
varname=Path.GetFileName(dirEntries[i]).Replace("com.unity.template.","");
1878+
items.Add(name,dirEntries[i]);
1879+
}
1880+
}
1881+
18511882
returnitems;
18521883
}
18531884

@@ -2792,10 +2823,7 @@ public static string GetSafeFilePath(string subfolder, string fileName)
27922823
// 1) Preferred: under the app folder
27932824
stringpreferredDir=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,subfolder);
27942825
// 2) Fallback: in LocalAppData
2795-
stringfallbackDir=Path.Combine(
2796-
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
2797-
"UnityLauncherPro",
2798-
subfolder);
2826+
stringfallbackDir=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"UnityLauncherPro",subfolder);
27992827

28002828
try
28012829
{
@@ -2818,9 +2846,26 @@ public static string GetSafeFilePath(string subfolder, string fileName)
28182846
returnPath.Combine(fallbackDir,fileName);
28192847
}
28202848

2849+
// copy directory structure (for template folder)
2850+
publicstaticvoidCopyDirectory(stringsourceDir,stringtargetDir)
2851+
{
2852+
// Create the target directory if it doesn't exist
2853+
Directory.CreateDirectory(targetDir);
28212854

2855+
// Copy all files
2856+
foreach(varfileinDirectory.GetFiles(sourceDir))
2857+
{
2858+
vardestFile=Path.Combine(targetDir,Path.GetFileName(file));
2859+
File.Copy(file,destFile,overwrite:false);
2860+
}
28222861

2823-
2862+
// Recursively copy subdirectories
2863+
foreach(vardirectoryinDirectory.GetDirectories(sourceDir))
2864+
{
2865+
vardestDir=Path.Combine(targetDir,Path.GetFileName(directory));
2866+
CopyDirectory(directory,destDir);
2867+
}
2868+
}
28242869

28252870
}// class
28262871

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp