1
1
using Newtonsoft . Json . Linq ;
2
2
using System ;
3
3
using System . Collections . Async ;
4
- using System . Collections . Generic ;
5
4
using System . Diagnostics ;
6
5
using System . IO ;
6
+ using System . IO . Compression ;
7
7
using System . Linq ;
8
8
using System . Net ;
9
9
using System . Windows ;
10
- using System . Xml . Linq ;
11
10
12
11
namespace Steam_Library_Manager . Definitions
13
12
{
@@ -23,146 +22,47 @@ public override async void UpdateAppListAsync()
23
22
{
24
23
try
25
24
{
26
- Apps . Clear ( ) ;
27
-
28
- if ( ! Directory . Exists ( FullPath ) ) return ;
25
+ if ( IsUpdatingAppList )
26
+ return ;
29
27
30
- var appIds = new List < KeyValuePair < string , string > > ( ) ;
28
+ IsUpdatingAppList = true ;
31
29
32
- if ( Directory . Exists ( Directories . Origin . LocalContentDirectoy ) )
33
- {
34
- //foreach (var originApp in Directory.EnumerateFiles(Directories.Origin.LocalContentDirectoy, "*.mfst", SearchOption.AllDirectories))
35
- await Directory . EnumerateFiles ( Directories . Origin . LocalContentDirectoy , "*.mfst" ,
36
- SearchOption . AllDirectories ) . ParallelForEachAsync (
37
- async originApp =>
38
- {
39
- var appId = Path . GetFileNameWithoutExtension ( originApp ) ;
40
-
41
- if ( ! appId . StartsWith ( "Origin" ) )
42
- {
43
- // Get game id by fixing file via adding : before integer part of the name
44
- // for example OFB-EAST52017 converts to OFB-EAST:52017
45
- var match = System . Text . RegularExpressions . Regex . Match ( appId , @"^(.*?)(\d+)$" ) ;
46
- if ( ! match . Success )
47
- {
48
- return ;
49
- }
50
-
51
- appId = match . Groups [ 1 ] . Value + ":" + match . Groups [ 2 ] . Value ;
52
- }
30
+ Apps . Clear ( ) ;
53
31
54
- appIds . Add ( new KeyValuePair < string , string > ( new FileInfo ( originApp ) . Directory . Name , appId ) ) ;
55
- } ) ;
56
- }
32
+ if ( ! Directory . Exists ( FullPath ) ) return ;
57
33
58
34
await Directory . EnumerateFiles ( FullPath , "installerdata.xml" , SearchOption . AllDirectories )
59
35
. ParallelForEachAsync (
60
36
async originApp =>
61
37
{
62
- if ( new FileInfo ( originApp ) . Directory . Parent . Parent . Name !=
63
- new DirectoryInfo ( FullPath ) . Name )
64
- return ;
65
-
66
- var installerLog = Path . Combine ( Directory . GetParent ( originApp ) . FullName , "InstallLog.txt" ) ;
67
- var installedLocale = "en_US" ;
68
-
69
- if ( File . Exists ( installerLog ) )
70
- {
71
- foreach ( var line in File . ReadAllLines ( installerLog ) )
72
- {
73
- if ( ! line . Contains ( "Install Locale:" ) ) continue ;
74
-
75
- installedLocale = line . Split ( new string [ ] { "Install Locale:" } ,
76
- StringSplitOptions . None ) [ 1 ] ;
77
- break ;
78
- }
79
-
80
- installedLocale = installedLocale . Replace ( " " , "" ) ;
81
- }
82
-
83
- var xml = XDocument . Load ( originApp ) ;
84
- var manifestVersion = new Version ( ( xml . Root . Name . LocalName == "game" )
85
- ? xml . Root . Attribute ( "manifestVersion" ) . Value
86
- : ( ( xml . Root . Name . LocalName == "DiPManifest" )
87
- ? xml . Root . Attribute ( "version" ) . Value
88
- : "1.0" ) ) ;
89
-
90
- OriginAppInfo originAppInfo = null ;
91
-
92
- if ( manifestVersion == new Version ( "4.0" ) )
93
- {
94
- originAppInfo = new OriginAppInfo ( this ,
95
- xml . Root . Element ( "gameTitles" ) ? . Elements ( "gameTitle" )
96
- ? . First ( x => x . Attribute ( "locale" ) . Value == "en_US" ) ? . Value ,
97
- Convert . ToInt32 ( xml . Root . Element ( "contentIDs" ) ? . Elements ( )
98
- . FirstOrDefault ( x => int . TryParse ( x . Value , out int appId ) ) ? . Value ) ,
99
- new FileInfo ( originApp ) . Directory . Parent ,
100
- new Version ( xml . Root . Element ( "buildMetaData" ) ? . Element ( "gameVersion" )
101
- ? . Attribute ( "version" ) ? . Value ) ,
102
- xml . Root . Element ( "installMetaData" ) ? . Element ( "locales" ) ? . Value . Split ( ',' ) ,
103
- installedLocale ,
104
- xml . Root . Element ( "touchup" ) ? . Element ( "filePath" ) ? . Value ,
105
- xml . Root . Element ( "touchup" ) ? . Element ( "parameters" ) ? . Value ,
106
- xml . Root . Element ( "touchup" ) ? . Element ( "updateParameters" ) ? . Value ,
107
- xml . Root . Element ( "touchup" ) ? . Element ( "repairParameters" ) ? . Value ) ;
108
- }
109
- else if ( manifestVersion >= new Version ( "1.1" ) && manifestVersion <= new Version ( "3.0" ) )
110
- {
111
- var locales = new List < string > ( ) ;
112
- foreach ( var locale in xml . Root . Element ( "metadata" ) ? . Elements ( "localeInfo" )
113
- ? . Attributes ( ) ? . Where ( x => x . Name == "locale" ) )
114
- {
115
- locales . Add ( locale . Value ) ;
116
- }
117
-
118
- originAppInfo = new OriginAppInfo ( this ,
119
- xml . Root . Element ( "metadata" ) ? . Elements ( "localeInfo" )
120
- ? . First ( x => x . Attribute ( "locale" ) . Value == "en_US" ) ? . Element ( "title" ) . Value ,
121
- Convert . ToInt32 ( xml . Root . Element ( "contentIDs" ) ? . Element ( "contentID" ) ? . Value
122
- . Replace ( "EAX" , "" ) ) ,
123
- new FileInfo ( originApp ) . Directory . Parent ,
124
- new Version ( xml . Root . Attribute ( "gameVersion" ) . Value ) ,
125
- locales . ToArray ( ) ,
126
- installedLocale ,
127
- xml . Root . Element ( "executable" ) ? . Element ( "filePath" ) ? . Value ,
128
- xml . Root . Element ( "executable" ) ? . Element ( "parameters" ) ? . Value ) ;
129
- }
130
- else
131
- {
132
- MessageBox . Show ( Framework . StringFormat . Format (
133
- Functions . SLM . Translate ( nameof ( Properties . Resources . OriginUnknownManifestFile ) ) ,
134
- new { ManifestVersion = manifestVersion , OriginApp = originApp } ) ) ;
135
- return ;
136
- }
38
+ await Functions . Origin . ParseAppDetailsAsync ( new StreamReader ( originApp ) . BaseStream , originApp , this ) ;
39
+ } ) ;
137
40
138
- if ( appIds . Count ( x => x . Key == originAppInfo . InstallationDirectory . Name ) > 0 )
41
+ await Directory . EnumerateFiles ( FullPath , "*.zip" , SearchOption . TopDirectoryOnly ) . ParallelForEachAsync ( async originCompressedArchive =>
42
+ {
43
+ using ( var archive = ZipFile . OpenRead ( originCompressedArchive ) )
44
+ {
45
+ if ( archive . Entries . Count > 0 )
46
+ {
47
+ foreach ( var archiveEntry in archive . Entries . Where ( x => x . Name . Contains ( "installerdata.xml" ) ) )
139
48
{
140
- var appId = appIds . First ( x => x . Key == originAppInfo . InstallationDirectory . Name ) ;
141
-
142
- var appLocalData = GetGameLocalData ( appId . Value ) ;
143
-
144
- if ( appLocalData != null )
145
- {
146
- await Framework . CachedImage . FileCache . HitAsync ( string . Concat ( appLocalData [ "customAttributes" ] [ "imageServer" ] ,
147
- appLocalData [ "localizableAttributes" ] [ "packArtLarge" ] )
148
- , $ "{ originAppInfo . AppId } _o")
149
- . ConfigureAwait ( false ) ;
150
- }
49
+ await Functions . Origin . ParseAppDetailsAsync ( archiveEntry . Open ( ) , originCompressedArchive , this , true ) ;
151
50
}
152
-
153
- originAppInfo . GameHeaderImage = $ "{ Directories . SLM . Cache } \\ { originAppInfo . AppId } _o.jpg";
154
-
155
- Apps . Add ( originAppInfo ) ;
156
- } ) ;
51
+ }
52
+ }
53
+ } ) ;
157
54
158
55
if ( SLM . CurrentSelectedLibrary != null && SLM . CurrentSelectedLibrary == this )
159
56
{
160
57
Functions . App . UpdateAppPanel ( this ) ;
161
58
}
59
+
60
+ IsUpdatingAppList = false ;
162
61
}
163
62
catch ( Exception ex )
164
63
{
165
- MessageBox . Show ( ex . ToString ( ) ) ;
64
+ MessageBox . Show ( $ "An error happened while updating game list for Origin library: { FullPath } \n { ex } ") ;
65
+ Logger . Fatal ( ex ) ;
166
66
}
167
67
}
168
68
@@ -195,7 +95,7 @@ public override void RemoveLibraryAsync(bool withFiles)
195
95
}
196
96
}
197
97
198
- private JObject GetGameLocalData ( string gameId )
98
+ public JObject GetGameLocalData ( string gameId )
199
99
{
200
100
try
201
101
{
0 commit comments