import 'dart:convert'; 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:mhunt_launcher/login.dart'; class UpdateCheckScreen extends StatefulWidget { const UpdateCheckScreen({super.key}); @override State createState() => _UpdateCheckScreenState(); } class _UpdateCheckScreenState extends State { int localVersion = 4; String otaPath = Directory.current.path + "\\ota_wrapper_silent.vbs"; @override void initState() { // TODO: implement initState super.initState(); CheckForUpdates(); } void CheckForUpdates() async{ http.Response remoteVersionResponse = await http.get(Uri.parse("https://vps.playpoolstudios.com/metahunt/data/bin/launcher_win/get_version_code.php")); int remoteVersion = int.parse(remoteVersionResponse.body); print("local version:${localVersion}, remote version:${remoteVersion}"); if(remoteVersion>localVersion){ updateStatus = 1; }else{ updateStatus=2; Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=> LoginPage())); } // 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)=> LoginPage())); // }else{ // updateStatus = 1; // } // } catch (e) { // print('Error running the executable: $e'); // } setState(() { }); } void update() async{ // await Process.start(otaPath,[], runInShell: true); // final process = await Process.start('wscript',[otaPath], runInShell: true); updateStatus = 2; process.stdout.transform(utf8.decoder).listen((data) { }); process.stderr.transform(utf8.decoder).listen((data) { print(data); }); await Future.delayed(const Duration(seconds: 1)); 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"); } }