3636using Thread = System . Threading . Thread ;
3737using OculusGraphQLApiLib ;
3838using OculusGraphQLApiLib . Results ;
39+ using ComputerUtils . Updating ;
3940
4041namespace QuestAppVersionSwitcher
4142{
@@ -385,7 +386,6 @@ public void Start()
385386 {
386387 QAVSReport report = new QAVSReport ( ) ;
387388 report . version = CoreService . version . ToString ( ) ;
388- report . log = Logger . log ;
389389 report . userIsLoggedIn = GetLoggedInStatus ( ) == LoggedInStatus . LoggedIn ;
390390 report . reportTime = DateTime . Now ;
391391 report . availableSpace = Android . OS . Environment . ExternalStorageDirectory . UsableSpace ;
@@ -411,6 +411,7 @@ public void Start()
411411
412412 }
413413 }
414+ report . log = Logger . log ;
414415 request . SendString ( JsonSerializer . Serialize ( report ) ) ;
415416 return true ;
416417 } ) ) ;
@@ -838,7 +839,32 @@ public void Start()
838839 serverRequest . SendString ( JsonSerializer . Serialize ( progress ) ) ;
839840 return true ;
840841 } ) ) ;
841- server . AddRouteFile ( "/facts.png" , "facts.png" ) ;
842+ server . AddRoute ( "GET" , "/questappversionswitcher/checkupdate" , new Func < ServerRequest , bool > ( request =>
843+ {
844+ Updater u = new Updater ( CoreService . version . ToString ( ) . Substring ( 0 , CoreService . version . ToString ( ) . Length - 2 ) , "https://github.com/ComputerElite/QuestAppVersionSwitcher" , "QuestAppVersionSwitcher" ) ; ;
845+ request . SendString ( JsonSerializer . Serialize ( u . CheckUpdate ( ) ) , "application/json" ) ;
846+ return true ;
847+ } ) ) ;
848+ server . AddRoute ( "GET" , "/questappversionswitcher/update" , new Func < ServerRequest , bool > ( request =>
849+ {
850+ Updater u = new Updater ( CoreService . version . ToString ( ) . Substring ( 0 , CoreService . version . ToString ( ) . Length - 2 ) , "https://github.com/ComputerElite/QuestAppVersionSwitcher" , "QuestAppVersionSwitcher" ) ; ;
851+ request . SendString ( "Downloading apk, one second please" ) ;
852+
853+ TempFile tmpFile = new TempFile ( ) ;
854+ tmpFile . Path += ".apk" ;
855+ u . DownloadLatestAPK ( tmpFile . Path ) ;
856+ string packageName = GetAPKPackageName ( tmpFile . Path ) ;
857+ string version = GetAPKVersion ( tmpFile . Path ) ;
858+ string backupDir = CoreService . coreVars . QAVSBackupDir + packageName + "/" + version + "/" ;
859+ Logger . Log ( "Moving file" ) ;
860+ FileManager . CreateDirectoryIfNotExisting ( backupDir ) ;
861+ FileManager . DeleteFileIfExisting ( backupDir + "app.apk" ) ;
862+ File . Move ( tmpFile . Path , backupDir + "app.apk" ) ;
863+
864+ AndroidService . InitiateInstallApk ( backupDir + "app.apk" ) ;
865+ return true ;
866+ } ) ) ;
867+ server . AddRouteFile ( "/facts.png" , "facts.png" ) ;
842868 server . StartServer ( CoreService . coreVars . serverPort ) ;
843869 Thread . Sleep ( 1500 ) ;
844870 if ( CoreService . coreVars . loginStep == 1 )
0 commit comments