@@ -1493,48 +1493,64 @@ private static string ExtractPlasticBranch(string plasticSelectorPath)
1493
1493
return null ;
1494
1494
}
1495
1495
1496
-
1497
- //public static Platform GetTargetPlatform(string projectPath)
1498
1496
static string GetTargetPlatformRaw ( string projectPath )
1499
1497
{
1500
1498
string results = null ;
1501
- //Platform results = Platform.Unknown;
1502
1499
1503
1500
// get buildtarget from .csproj
1504
1501
// <UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
1505
1502
// get main csproj file
1506
1503
var csproj = Path . Combine ( projectPath , "Assembly-CSharp.csproj" ) ;
1504
+
1507
1505
// 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
+
1509
1508
if ( File . Exists ( csproj ) )
1510
1509
{
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 ) )
1514
1512
{
1515
- var endrow = csprojsplit [ 1 ] . IndexOf ( ":" ) ;
1516
- if ( endrow > - 1 )
1513
+ string line ;
1514
+ while ( ( line = reader . ReadLine ( ) ) != null )
1517
1515
{
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
+ }
1527
1542
}
1528
1543
}
1529
1544
}
1530
1545
else
1531
1546
{
1532
- //Console.WriteLine("Missing csproj, cannot parse target platform: "+ projectPath);
1547
+ //Console.WriteLine("Missing csproj, cannot parse target platform: " + projectPath);
1533
1548
}
1534
1549
1535
1550
return results ;
1536
1551
}
1537
1552
1553
+
1538
1554
public static string GetTargetPlatform ( string projectPath )
1539
1555
{
1540
1556
var rawPlatformName = GetTargetPlatformRaw ( projectPath ) ;
0 commit comments