@@ -1493,48 +1493,64 @@ private static string ExtractPlasticBranch(string plasticSelectorPath)
14931493 return null ;
14941494 }
14951495
1496-
1497- //public static Platform GetTargetPlatform(string projectPath)
14981496 static string GetTargetPlatformRaw ( string projectPath )
14991497 {
15001498 string results = null ;
1501- //Platform results = Platform.Unknown;
15021499
15031500 // get buildtarget from .csproj
15041501 // <UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
15051502 // get main csproj file
15061503 var csproj = Path . Combine ( projectPath , "Assembly-CSharp.csproj" ) ;
1504+
15071505 // TODO check projname also, if no assembly-.., NOTE already checked above
1508- //var csproj = Path.Combine(projectPath, projectName + ".csproj");
1506+ // var csproj = Path.Combine(projectPath, projectName + ".csproj");
1507+
15091508 if ( File . Exists ( csproj ) )
15101509 {
1511- var csprojtxt = File . ReadAllText ( csproj ) ;
1512- var csprojsplit = csprojtxt . Split ( new [ ] { "<UnityBuildTarget>" } , StringSplitOptions . None ) ;
1513- if ( csprojsplit != null && csprojsplit . Length > 1 )
1510+ // Read the file line by line for performance
1511+ using ( var reader = new StreamReader ( csproj ) )
15141512 {
1515- var endrow = csprojsplit [ 1 ] . IndexOf ( ":" ) ;
1516- if ( endrow > - 1 )
1513+ string line ;
1514+ while ( ( line = reader . ReadLine ( ) ) != null )
15171515 {
1518- //Console.WriteLine("build target: " + csprojsplit[1].Substring(0, endrow));
1519- // 5.6 : win32, win64, osx, linux, linux64, ios, android, web, webstreamed, webgl, xboxone, ps4, psp2, wsaplayer, tizen, samsungtv
1520- // 2017: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, PSP2, WindowsStoreApps, Switch, WiiU, N3DS, tvOS, PSM
1521- // 2018: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, N3DS, tvOS
1522- // 2019: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1523- // 2020: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1524- // 2021: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1525- results = csprojsplit [ 1 ] . Substring ( 0 , endrow ) ;
1526- //results = (Platform)Enum.Parse(typeof(Platform), csprojsplit[1].Substring(0, endrow));
1516+ const string tagStart = "<UnityBuildTarget>" ;
1517+ const string tagEnd = "</UnityBuildTarget>" ;
1518+
1519+ int startIdx = line . IndexOf ( tagStart ) ;
1520+ if ( startIdx >= 0 )
1521+ {
1522+ int endIdx = line . IndexOf ( tagEnd , startIdx ) ;
1523+ if ( endIdx > startIdx )
1524+ {
1525+ string inner = line . Substring ( startIdx + tagStart . Length , endIdx - startIdx - tagStart . Length ) ;
1526+ int colonIndex = inner . IndexOf ( ':' ) ;
1527+ if ( colonIndex > - 1 )
1528+ {
1529+ //Console.WriteLine("build target: " + inner.Substring(0, colonIndex));
1530+ // 5.6 : win32, win64, osx, linux, linux64, ios, android, web, webstreamed, webgl, xboxone, ps4, psp2, wsaplayer, tizen, samsungtv
1531+ // 2017: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, PSP2, WindowsStoreApps, Switch, WiiU, N3DS, tvOS, PSM
1532+ // 2018: standalone, Win, Win64, OSXUniversal, Linux, Linux64, LinuxUniversal, iOS, Android, Web, WebStreamed, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, N3DS, tvOS
1533+ // 2019: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1534+ // 2020: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1535+ // 2021: Standalone, Win, Win64, OSXUniversal, Linux64, iOS, Android, WebGL, XboxOne, PS4, WindowsStoreApps, Switch, tvOS
1536+ results = inner . Substring ( 0 , colonIndex ) ;
1537+ //results = (Platform)Enum.Parse(typeof(Platform), inner.Substring(0, colonIndex));
1538+ break ; // we found it, exit early
1539+ }
1540+ }
1541+ }
15271542 }
15281543 }
15291544 }
15301545 else
15311546 {
1532- //Console.WriteLine("Missing csproj, cannot parse target platform: "+ projectPath);
1547+ //Console.WriteLine("Missing csproj, cannot parse target platform: " + projectPath);
15331548 }
15341549
15351550 return results ;
15361551 }
15371552
1553+
15381554 public static string GetTargetPlatform ( string projectPath )
15391555 {
15401556 var rawPlatformName = GetTargetPlatformRaw ( projectPath ) ;
0 commit comments