@@ -43,7 +43,34 @@ public void Invoke(Action a) {
4343 public void RunDownloader ( ) {
4444 Console . WriteLine ( "Downloader thread running" ) ;
4545
46- Thread . Sleep ( 2000 ) ;
46+ if ( Directory . Exists ( Program . InstallDir ) && Directory . GetFiles ( Program . InstallDir ) . Length != 0 ) {
47+ Invoke ( ( ) => {
48+ MessageBox . Show (
49+ @"
50+ A previous version of Olympus was already downloaded.
51+ Sadly, some important files went missing or are corrupted.
52+
53+ The Olympus downloader will now try to redownload them.
54+ If Olympus is still crashing or if this happens often:
55+ please ping the Everest team on the Celeste Discord server.
56+ " . Trim ( ) . Replace ( "\r \n " , "\n " ) ,
57+ "Olympus Downloader" ,
58+ MessageBoxButtons . OK
59+ ) ;
60+ } ) ;
61+ }
62+
63+ Console . WriteLine ( $ "Wiping { Program . InstallDir } ") ;
64+ try {
65+ Directory . Delete ( Program . InstallDir , true ) ;
66+ } catch ( Exception e ) {
67+ Console . WriteLine ( e ) ;
68+ }
69+ try {
70+ Directory . CreateDirectory ( Program . InstallDir ) ;
71+ } catch ( Exception e ) {
72+ Console . WriteLine ( e ) ;
73+ }
4774
4875 const string artifactFormat = "https://dev.azure.com/EverestAPI/Olympus/_apis/build/builds/{0}/artifacts?artifactName=windows.main&$format=zip" ;
4976 const string index = "https://dev.azure.com/EverestAPI/Olympus/_apis/build/builds" ;
@@ -55,6 +82,7 @@ public void RunDownloader() {
5582 using ( JsonTextReader jsonReader = new JsonTextReader ( reader ) )
5683 root = ( JObject ) JToken . ReadFrom ( jsonReader ) ;
5784
85+ string urlWindowsInit = null ;
5886 string urlStable = null ;
5987 string urlMain = null ;
6088
@@ -69,6 +97,8 @@ public void RunDownloader() {
6997
7098 int id = build . Value < int > ( "id" ) ;
7199 string branch = build . Value < string > ( "sourceBranch" ) . Replace ( "refs/heads/" , "" ) ;
100+ if ( string . IsNullOrEmpty ( urlWindowsInit ) && branch == "windows-init" )
101+ urlWindowsInit = string . Format ( artifactFormat , id ) ;
72102 if ( string . IsNullOrEmpty ( urlStable ) && branch == "stable" )
73103 urlStable = string . Format ( artifactFormat , id ) ;
74104 if ( string . IsNullOrEmpty ( urlMain ) && ( branch == "main" || branch == "dev" ) )
@@ -78,7 +108,7 @@ public void RunDownloader() {
78108 break ;
79109 }
80110
81- string url = ! string . IsNullOrEmpty ( urlStable ) ? urlStable : urlMain ;
111+ string url = ! string . IsNullOrEmpty ( urlWindowsInit ) ? urlWindowsInit : ! string . IsNullOrEmpty ( urlStable ) ? urlStable : urlMain ;
82112 if ( string . IsNullOrEmpty ( url ) )
83113 throw new Exception ( "Couldn't find valid latest build entry." ) ;
84114
@@ -96,13 +126,6 @@ public void RunDownloader() {
96126 Console . WriteLine ( "Opening dist .zip" ) ;
97127 using ( Stream stream = wrapper . GetEntry ( "windows.main/dist.zip" ) . Open ( ) )
98128 using ( ZipArchive zip = new ZipArchive ( stream , ZipArchiveMode . Read ) ) {
99- Console . WriteLine ( $ "Wiping { Program . InstallDir } ") ;
100- try {
101- Directory . Delete ( Program . InstallDir ) ;
102- Directory . CreateDirectory ( Program . InstallDir ) ;
103- } catch ( Exception e ) {
104- Console . WriteLine ( e ) ;
105- }
106129 Console . WriteLine ( $ "Extracting to { Program . InstallDir } ") ;
107130 zip . ExtractToDirectory ( Program . InstallDir ) ;
108131 }
0 commit comments