import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:http/http.dart' as http; import 'package:mhunt_launcher/home.dart'; import 'package:process_run/shell.dart'; class UpdateCheckScreen extends StatefulWidget { const UpdateCheckScreen({super.key}); @override State createState() => _UpdateCheckScreenState(); } class _UpdateCheckScreenState extends State { int localVersion = 0; String otaPath = Directory.current.path + "\\ota_wrapper_v2.exe"; @override void initState() { // TODO: implement initState super.initState(); CheckForUpdates(); } Future> runExecutable(String executable) async { return await run(executable); } void CheckForUpdates() async{ // http.Response remoteVersionResponse = await http.get(Uri.parse("https://vps.playpoolstudios.com/metahunt/api/launcher/get_version.php")); // int remoteVersion = int.parse(remoteVersionResponse.body); if(!await File(otaPath).exists()){ print("otapath not existing"); setState(() { updateStatus=2; }); return; } try { final result = await runExecutable(otaPath + " noupdate"); if (result[0].stdout.trim() == '0') { updateStatus = 2; Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=> HomePage())); }else{ updateStatus = 1; } } catch (e) { print('Error running the executable: $e'); } setState(() { }); } void update() async{ await Process.start(otaPath,[], runInShell: true); // await Future.delayed(const Duration(seconds: 5)); updateStatus = 2; exit(0); setState(() { }); } /// ///0 = checking updates ///1 = update available ///2 = clear int updateStatus = 0; @override Widget build(BuildContext context) { return Scaffold( body: Padding( padding: const EdgeInsets.all(100.0), child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text("W3B Games Launcher",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 45),), ], ), GetContent(), SizedBox(height: 70,), ], ) ), ); } Widget GetContent(){ switch(updateStatus){ case 0: return CheckingWidget(); case 1: return UpdateAvailableWidget(); case 2: return ClearWidget(); } return CheckingWidget(); } Widget CheckingWidget(){ return Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: [ Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: [ SpinKitWave(color:Colors.grey), SizedBox(height: 20,), Text("Checking for updates..."), ], ), ], ); } Widget UpdateAvailableWidget(){ return Column( children: [ SizedBox(height: 50,), Icon(Icons.browser_updated,size: 120, color: Colors.grey,), SizedBox(height: 10,), Text("New update available",style: TextStyle(fontSize: 20),), SizedBox(height: 20,), MaterialButton(onPressed: update, child: Padding( padding: const EdgeInsets.all(8.0), child: Text("Update now"), ), color: Colors.blue,) ], ); } Widget ClearWidget(){ return Text("Good to go"); } }