1- using log4net ;
1+ using HandyControl . Controls ;
2+ using log4net ;
23using System . IO ;
34using VNGod . Data ;
45using VNGod . Models ;
@@ -36,12 +37,12 @@ public static async Task<bool> SyncMetadataAsync(Repo repo)
3637 var localMetaPath = Path . Combine ( repo . LocalPath , game . DirectoryName , ".vngod" ) ;
3738 var remoteMetaPath = $ "{ game . DirectoryName } /.vngod";
3839 var timeComparison = WebDAVClient . CompareFileDate ( remoteMetaPath , localMetaPath ) ;
39- Logger . Info ( $ "Comparing metadata for game { game . DirectoryName } : Time comparison result = { timeComparison } ") ;
40+ Logger . Debug ( $ "Comparing metadata for game { game . DirectoryName } : Time comparison result = { timeComparison } ") ;
4041 if ( timeComparison == - 1 || timeComparison == 404 )
4142 {
4243 if ( await WebDAVClient . UploadFileAsync ( localMetaPath , remoteMetaPath ) )
4344 {
44- Logger . Info ( $ "Uploaded metadata for game { game . DirectoryName } .") ;
45+ Logger . Debug ( $ "Uploaded metadata for game { game . DirectoryName } .") ;
4546 }
4647 else
4748 throw new Exception ( "Upload metadata failed." ) ;
@@ -50,14 +51,14 @@ public static async Task<bool> SyncMetadataAsync(Repo repo)
5051 {
5152 if ( await WebDAVClient . DownloadFileAsync ( remoteMetaPath , localMetaPath ) )
5253 {
53- Logger . Info ( $ "Downloaded metadata for game { game . DirectoryName } .") ;
54+ Logger . Debug ( $ "Downloaded metadata for game { game . DirectoryName } .") ;
5455 }
5556 else
5657 throw new Exception ( "Download metadata failed." ) ;
5758 }
5859 else
5960 {
60- Logger . Info ( $ "Metadata for game { game . DirectoryName } is up to date.") ;
61+ Logger . Debug ( $ "Metadata for game { game . DirectoryName } is up to date.") ;
6162 }
6263 }
6364 catch ( Exception ex )
@@ -92,7 +93,7 @@ public static async Task<bool> SyncGameAsync(Game game)
9293 }
9394 if ( timeComparison == - 1 || timeComparison == 404 )
9495 {
95- Logger . Info ( "Local save is newer or remote not found. Uploading..." ) ;
96+ Logger . Debug ( "Local save is newer or remote not found. Uploading..." ) ;
9697 // Upload the zip file to WebDAV server
9798 var uploadSuccess = await WebDAVClient . UploadFileAsync ( tempZipPath , remoteSavePath ) ;
9899 if ( ! uploadSuccess )
@@ -103,7 +104,7 @@ public static async Task<bool> SyncGameAsync(Game game)
103104 }
104105 else
105106 {
106- Logger . Info ( "Remote save is newer or same. Downloading..." ) ;
107+ Logger . Debug ( "Remote save is newer or same. Downloading..." ) ;
107108 var downloadSuccess = await WebDAVClient . DownloadFileAsync ( remoteSavePath , tempZipPath ) ;
108109 if ( ! downloadSuccess )
109110 {
@@ -133,7 +134,7 @@ public static async Task<bool> UploadGameAsync(Repo repo, Game game, IProgress<S
133134 {
134135 try
135136 {
136- string tmpPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "Temp" , game . DirectoryName ) ;
137+ string tmpPath = Path . Combine ( FileHelper . tmpPath , game . DirectoryName ) ;
137138 if ( Directory . Exists ( tmpPath ) )
138139 Directory . Delete ( tmpPath , true ) ;
139140 if ( ! await WebDAVClient . DeleteRemoteAsync ( $ "{ game . DirectoryName } /game") )
@@ -158,5 +159,31 @@ public static async Task<bool> UploadGameAsync(Repo repo, Game game, IProgress<S
158159 return false ;
159160 }
160161 }
162+ public static async Task < Repo > GetRemoteGamesAsync ( )
163+ {
164+ Repo games = new ( ) { LocalPath = "WebDAV" } ;
165+ List < string > remotePaths = new ( ) ;
166+ // Get remote directories under root dir, containg games
167+ await WebDAVClient . ListRemoteAsync ( "" , remotePaths ) ;
168+ string tmpPath = Path . Combine ( FileHelper . tmpPath , ".vngodtmp" ) ;
169+ // Get remote games
170+ foreach ( var remotePath in remotePaths )
171+ {
172+ // Skip if no remote game folder
173+ if ( await WebDAVClient . ListRemoteAsync ( $ "{ remotePath } /game", new ( ) ) )
174+ {
175+ if ( await WebDAVClient . DownloadFileAsync ( $ "{ remotePath } /.vngod", tmpPath ) )
176+ {
177+ Game game = FileHelper . ReadGameMetadata ( tmpPath ) ;
178+ games . Add ( game ) ;
179+ }
180+ else
181+ {
182+ Growl . Warning ( "Error getting remote games" ) ;
183+ }
184+ }
185+ }
186+ return games ;
187+ }
161188 }
162189}
0 commit comments