1
1
using Microsoft . Win32 ;
2
2
using System ;
3
3
using System . Collections . Generic ;
4
+ using System . Collections . Specialized ;
4
5
using System . IO ;
5
6
using System . Text ;
6
7
@@ -14,7 +15,7 @@ public static class GetProjects
14
15
// convert target platform name into valid buildtarget platform name, NOTE this depends on unity version, now only 2019 and later are supported
15
16
public static Dictionary < string , string > remapPlatformNames = new Dictionary < string , string > { { "StandaloneWindows64" , "Win64" } , { "StandaloneWindows" , "Win" } , { "Android" , "Android" } , { "WebGL" , "WebGL" } } ;
16
17
17
- public static List < Project > Scan ( bool getGitBranch = false , bool getPlasticBranch = false , bool getArguments = false , bool showMissingFolders = false , bool showTargetPlatform = false )
18
+ public static List < Project > Scan ( bool getGitBranch = false , bool getPlasticBranch = false , bool getArguments = false , bool showMissingFolders = false , bool showTargetPlatform = false , StringCollection AllProjectPaths = null )
18
19
{
19
20
List < Project > projectsFound = new List < Project > ( ) ;
20
21
@@ -39,7 +40,6 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
39
40
{
40
41
if ( valueName . IndexOf ( "RecentlyUsedProjectPaths-" ) == 0 )
41
42
{
42
- bool folderExists = false ;
43
43
string projectPath = "" ;
44
44
// check if binary or not
45
45
var valueKind = key . GetValueKind ( valueName ) ;
@@ -53,109 +53,154 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
53
53
projectPath = ( string ) key . GetValue ( valueName ) ;
54
54
}
55
55
56
- // first check if whole folder exists, if not, skip
57
- folderExists = Directory . Exists ( projectPath ) ;
58
- if ( showMissingFolders == false && folderExists == false )
59
- {
60
- //Console.WriteLine("Recent project directory not found, skipping: " + projectPath);
61
- continue ;
62
- }
56
+ var p = GetProjectInfo ( projectPath , getGitBranch , getPlasticBranch , getArguments , showMissingFolders , showTargetPlatform ) ;
63
57
64
- string projectName = "" ;
58
+ // if want to hide project and folder path for screenshot
59
+ //p.Title = "Example Project ";
60
+ //p.Path = "C:/Projects/ExamplePath/MyProj";
65
61
66
- // get project name from full path
67
- if ( projectPath . IndexOf ( Path . DirectorySeparatorChar ) > - 1 )
68
- {
69
- projectName = projectPath . Substring ( projectPath . LastIndexOf ( Path . DirectorySeparatorChar ) + 1 ) ;
70
- }
71
- else if ( projectPath . IndexOf ( Path . AltDirectorySeparatorChar ) > - 1 )
62
+ if ( p != null )
72
63
{
73
- projectName = projectPath . Substring ( projectPath . LastIndexOf ( Path . AltDirectorySeparatorChar ) + 1 ) ;
64
+ projectsFound . Add ( p ) ;
65
+
66
+ // test adding to history
67
+ Tools . AddProjectToHistory ( p . Path ) ;
74
68
}
75
- else // no path separator found
69
+ } // valid key
70
+ } // each key
71
+ } // for each registry root
72
+
73
+ // NOTE those 40 projects should be added to custom list, otherwise they will disappear (since last item is not yet added to our list, until its launched once, so need to launch many projects, to start collecting history..)
74
+ // but then we would have to loop here again..? or add in the loop above..if doesnt exists on list, and the remove extra items from the end
75
+
76
+ // scan info for custom folders (if not already on the list)
77
+ if ( AllProjectPaths != null )
78
+ {
79
+ // custom full list (may contain duplicates)
80
+ //foreach (var p in projectsFound)
81
+ foreach ( var projectPath in AllProjectPaths )
82
+ {
83
+ // check if registry list contains this path
84
+ bool found = false ;
85
+ for ( int i = 0 , len = projectsFound . Count ; i < len ; i ++ )
86
+ {
87
+ if ( projectsFound [ i ] . Path == projectPath )
76
88
{
77
- projectName = projectPath ;
89
+ found = true ;
90
+ break ;
78
91
}
92
+ }
79
93
80
- //Console.WriteLine("valueName="+ valueName+" , projectName =" + projectName);
81
-
82
- // get last modified date from folder
83
- DateTime ? lastUpdated = folderExists ? Tools . GetLastModifiedTime ( projectPath ) : null ;
94
+ // if not found, add
95
+ if ( found == false )
96
+ {
97
+ var p = GetProjectInfo ( projectPath , getGitBranch , getPlasticBranch , getArguments , showMissingFolders , showTargetPlatform ) ;
98
+ if ( p != null ) projectsFound . Add ( p ) ;
99
+ }
100
+ }
101
+ }
84
102
85
- // get project version
86
- string projectVersion = folderExists ? Tools . GetProjectVersion ( projectPath ) : null ;
103
+ // NOTE sometimes projects are in wrong order, seems to be related to messing up your unity registry, the keys are received in created order (so if you had removed/modified them manually, it might return wrong order instead of 0 - 40)
104
+ // thats why need to sort projects list by modified date
105
+ projectsFound . Sort ( ( x , y ) => y . Modified . Value . CompareTo ( x . Modified . Value ) ) ;
87
106
88
- // get custom launch arguments, only if column in enabled
89
- string customArgs = "" ;
90
- if ( getArguments == true )
91
- {
92
- customArgs = folderExists ? Tools . ReadCustomProjectData ( projectPath , MainWindow . launcherArgumentsFile ) : null ;
93
- }
107
+ // trim list to max amount TODO only if enabled in settings
108
+ if ( projectsFound . Count > MainWindow . maxProjectCount )
109
+ {
110
+ Console . WriteLine ( "Trimming projects list to " + MainWindow . maxProjectCount + " projects" ) ;
111
+ projectsFound . RemoveRange ( MainWindow . maxProjectCount , projectsFound . Count - MainWindow . maxProjectCount ) ;
112
+ }
94
113
95
- // get git branchinfo, only if column in enabled
96
- string gitBranch = "" ;
97
- if ( getGitBranch == true )
98
- {
99
- gitBranch = folderExists ? Tools . ReadGitBranchInfo ( projectPath ) : null ;
100
- // check for plastic, if enabled
101
- if ( getPlasticBranch == true && gitBranch == null )
102
- {
103
- gitBranch = folderExists ? Tools . ReadPlasticBranchInfo ( projectPath ) : null ;
104
- }
105
- }
114
+ return projectsFound ;
115
+ } // Scan()
106
116
107
- string targetPlatform = "" ;
108
- if ( showTargetPlatform == true )
109
- {
110
- targetPlatform = folderExists ? Tools . GetTargetPlatform ( projectPath ) : null ;
111
- }
117
+ static Project GetProjectInfo ( string projectPath , bool getGitBranch = false , bool getPlasticBranch = false , bool getArguments = false , bool showMissingFolders = false , bool showTargetPlatform = false )
118
+ {
119
+ // first check if whole folder exists, if not, skip
120
+ bool folderExists = Directory . Exists ( projectPath ) ;
121
+ if ( showMissingFolders == false && folderExists == false ) return null ;
112
122
113
- var p = new Project ( ) ;
123
+ string projectName = "" ;
114
124
115
- switch ( MainWindow . projectNameSetting )
116
- {
117
- case 0 :
118
- p . Title = Tools . ReadCustomProjectData ( projectPath , MainWindow . projectNameFile ) ;
119
- break ;
120
- case 1 :
121
- p . Title = Tools . ReadProjectName ( projectPath ) ;
122
- break ;
123
- default :
124
- p . Title = projectName ;
125
- break ;
126
- }
125
+ // get project name from full path
126
+ if ( projectPath . IndexOf ( Path . DirectorySeparatorChar ) > - 1 )
127
+ {
128
+ projectName = projectPath . Substring ( projectPath . LastIndexOf ( Path . DirectorySeparatorChar ) + 1 ) ;
129
+ }
130
+ else if ( projectPath . IndexOf ( Path . AltDirectorySeparatorChar ) > - 1 )
131
+ {
132
+ projectName = projectPath . Substring ( projectPath . LastIndexOf ( Path . AltDirectorySeparatorChar ) + 1 ) ;
133
+ }
134
+ else // no path separator found
135
+ {
136
+ projectName = projectPath ;
137
+ }
127
138
128
- // if no custom data or no product name found
129
- if ( string . IsNullOrEmpty ( p . Title ) ) p . Title = projectName ;
139
+ //Console.WriteLine("valueName="+ valueName+" , projectName =" + projectName);
130
140
131
- p . Version = projectVersion ;
132
- p . Path = projectPath ;
133
- p . Modified = lastUpdated ;
134
- p . Arguments = customArgs ;
135
- p . GITBranch = gitBranch ;
136
- //Console.WriteLine("targetPlatform " + targetPlatform + " projectPath:" + projectPath);
137
- p . TargetPlatform = targetPlatform ;
141
+ // get last modified date from folder
142
+ DateTime ? lastUpdated = folderExists ? Tools . GetLastModifiedTime ( projectPath ) : null ;
138
143
139
- // bubblegum(TM) solution, fill available platforms for this unity version, for this project
140
- p . TargetPlatforms = Tools . GetPlatformsForUnityVersion ( projectVersion ) ;
144
+ // get project version
145
+ string projectVersion = folderExists ? Tools . GetProjectVersion ( projectPath ) : null ;
141
146
142
- p . folderExists = folderExists ;
147
+ // get custom launch arguments, only if column in enabled
148
+ string customArgs = "" ;
149
+ if ( getArguments == true )
150
+ {
151
+ customArgs = folderExists ? Tools . ReadCustomProjectData ( projectPath , MainWindow . launcherArgumentsFile ) : null ;
152
+ }
143
153
144
- // if want to hide project and folder path for screenshot
145
- //p.Title = "Example Project ";
146
- //p.Path = "C:/Projects/ExamplePath/MyProj";
154
+ // get git branchinfo, only if column in enabled
155
+ string gitBranch = "" ;
156
+ if ( getGitBranch == true )
157
+ {
158
+ gitBranch = folderExists ? Tools . ReadGitBranchInfo ( projectPath ) : null ;
159
+ // check for plastic, if enabled
160
+ if ( getPlasticBranch == true && gitBranch == null )
161
+ {
162
+ gitBranch = folderExists ? Tools . ReadPlasticBranchInfo ( projectPath ) : null ;
163
+ }
164
+ }
147
165
148
- projectsFound . Add ( p ) ;
149
- } // valid key
150
- } // each key
151
- } // for each registry root
166
+ string targetPlatform = "" ;
167
+ if ( showTargetPlatform == true )
168
+ {
169
+ targetPlatform = folderExists ? Tools . GetTargetPlatform ( projectPath ) : null ;
170
+ }
152
171
153
- // NOTE sometimes projects are in wrong order, seems to be related to messing up your unity registry, the keys are received in created order (so if you had removed/modified them manually, it might return wrong order instead of 0 - 40)
154
- // thats why need to sort projects list by modified date
155
- projectsFound . Sort ( ( x , y ) => y . Modified . Value . CompareTo ( x . Modified . Value ) ) ;
172
+ var p = new Project ( ) ;
156
173
157
- return projectsFound ;
158
- } // Scan()
174
+ switch ( MainWindow . projectNameSetting )
175
+ {
176
+ case 0 :
177
+ p . Title = Tools . ReadCustomProjectData ( projectPath , MainWindow . projectNameFile ) ;
178
+ break ;
179
+ case 1 :
180
+ p . Title = Tools . ReadProjectName ( projectPath ) ;
181
+ break ;
182
+ default :
183
+ p . Title = projectName ;
184
+ break ;
185
+ }
186
+
187
+ // if no custom data or no product name found
188
+ if ( string . IsNullOrEmpty ( p . Title ) ) p . Title = projectName ;
189
+
190
+ p . Version = projectVersion ;
191
+ p . Path = projectPath ;
192
+ p . Modified = lastUpdated ;
193
+ p . Arguments = customArgs ;
194
+ p . GITBranch = gitBranch ;
195
+ //Console.WriteLine("targetPlatform " + targetPlatform + " projectPath:" + projectPath);
196
+ p . TargetPlatform = targetPlatform ;
197
+
198
+ // bubblegum(TM) solution, fill available platforms for this unity version, for this project
199
+ p . TargetPlatforms = Tools . GetPlatformsForUnityVersion ( projectVersion ) ;
200
+
201
+ p . folderExists = folderExists ;
202
+ return p ;
203
+ }
159
204
160
205
public static bool RemoveRecentProject ( string projectPathToRemove )
161
206
{
0 commit comments