import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:libac_dart/packets/packets.dart'; import 'package:servermanager/packets/ClientPackets.dart'; import 'package:servermanager/pages/Constants.dart'; import 'package:servermanager/pages/dialogbox.dart'; import 'package:servermanager/structs/SessionData.dart'; import 'package:servermanager/structs/settings.dart'; class SnapshotsPage extends StatefulWidget { SnapshotsPage({super.key}); @override State createState() { return SnapshotsState(); } } class SnapshotsState extends State { SnapshotsState(); Settings settings = Settings(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Server Snapshots Manager"), backgroundColor: Constants.TITLEBAR_COLOR, ), body: Padding( padding: EdgeInsets.all(8), child: SingleChildScrollView( child: Column( children: [ ListTile( title: Text("Server DB File"), subtitle: Text(settings.gameServerDBFile), ), ListTile( title: Text("Create Backup"), subtitle: Text( "This action will prompt for a filename, then contact the server, which will then take a immediate snapshot of the world under that name."), leading: Icon(Icons.backup), onTap: () { String finalValue = ""; InputBox ib = InputBox("", promptText: "Backup Name?", changed: (V) { setState(() { finalValue = V; }); }, onSubmit: () { // Send the filename to the server and request backup creation C2SRequestCreateBackup rcb = C2SRequestCreateBackup(); rcb.fileName = finalValue; settings.client!.send(rcb, true); }, onCancel: () {}, isDefault: true); showCupertinoDialog( context: context, builder: (ctx) { return ib; }); }, ), ListTile( title: Text("Restore"), subtitle: Text("Restore a backup file to active status"), leading: Icon(Icons.restore), onTap: () async { // Request the snapshot list, then present the restore list to the end user C2SRequestSnapshotList rsl = C2SRequestSnapshotList(); S2CResponse reply = await settings.client!.send(rsl, true); S2CSnapshotList snaps = S2CSnapshotList(); snaps.decodeTag(reply.contents); await snaps.handleClientPacket(); if (SessionData.IE_SNAPSHOTS.isNotEmpty) { // Show the list! } }, ) ], ), ), ), ); } } class SnapshotListPage extends StatefulWidget { @override State createState() { return SnapshotListState(); } } class SnapshotListState extends State { Settings settings = Settings(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "Snapshot Manager - Restore - ${SessionData.IE_SNAPSHOTS.length} backups"), backgroundColor: Constants.TITLEBAR_COLOR, ), body: Padding( padding: EdgeInsets.all(8), child: SingleChildScrollView( child: ListView.builder(itemBuilder: (ctx, index) { String filename = SessionData.IE_SNAPSHOTS[index]; return ListTile( title: Text(filename), leading: Icon(Icons.photo), subtitle: Text( "No information is known about this snapshot at this time"), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ IconButton( onPressed: () { // Send restore packet }, icon: Icon(Icons.restore)), IconButton( onPressed: () { // Send deletion packet C2SRequestSnapshotDeletion rsd = C2SRequestSnapshotDeletion(); rsd.snapshotName = filename; settings.client!.send(rsd, true); }, icon: Icon(Icons.delete)), ], ), ); })), ), ); } }