210 lines
7.7 KiB
Dart
210 lines
7.7 KiB
Dart
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<StatefulWidget> createState() {
|
|
return SnapshotsState();
|
|
}
|
|
}
|
|
|
|
class SnapshotsState extends State<SnapshotsPage> {
|
|
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!
|
|
await Navigator.pushNamed(
|
|
context, "/server/snapshots/restore");
|
|
|
|
SessionData.IE_SNAPSHOTS.clear();
|
|
}
|
|
},
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SnapshotListPage extends StatefulWidget {
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return SnapshotListState();
|
|
}
|
|
}
|
|
|
|
class SnapshotListState extends State<SnapshotListPage> {
|
|
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: ListView.builder(
|
|
itemBuilder: (ctx, index) {
|
|
String filename = SessionData.IE_SNAPSHOTS[index];
|
|
|
|
return ListTile(
|
|
title: Text(filename),
|
|
subtitle: Text(
|
|
"No information is known about this snapshot at this time"),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
onPressed: () async {
|
|
// Send restore packet
|
|
var result = await showCupertinoDialog(
|
|
context: context,
|
|
builder: (builder) {
|
|
return CupertinoAlertDialog(
|
|
title: Text("DANGER"),
|
|
content: Text(
|
|
"This action cannot be reversed, are you sure you want to restore $filename?"),
|
|
actions: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context, true);
|
|
},
|
|
child: Text("YES")),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
child: Text("ABORT"))
|
|
],
|
|
);
|
|
});
|
|
|
|
if (result == null) return;
|
|
C2SRequestWorldRestore rwr = C2SRequestWorldRestore();
|
|
rwr.snapshot = filename;
|
|
|
|
settings.client!.send(rwr, true);
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
content: Text(
|
|
"Restore has been requested, follow Discord for further updates")));
|
|
},
|
|
icon: Icon(Icons.restore),
|
|
),
|
|
IconButton(
|
|
onPressed: () async {
|
|
// Send deletion packet
|
|
var result = await showCupertinoDialog(
|
|
context: context,
|
|
builder: (builder) {
|
|
return AlertDialog(
|
|
icon: Icon(Icons.delete_forever),
|
|
title: Text("DANGER"),
|
|
content: Text(
|
|
"This action is not reversible. Are you sure?"),
|
|
actions: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context, true);
|
|
},
|
|
child: Text("Yes")),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context, null);
|
|
},
|
|
child: Text("ABORT"))
|
|
],
|
|
);
|
|
});
|
|
|
|
if (result == null) return;
|
|
|
|
C2SRequestSnapshotDeletion rsd =
|
|
C2SRequestSnapshotDeletion();
|
|
rsd.snapshotName = filename;
|
|
settings.client!.send(rsd, true);
|
|
},
|
|
icon: Icon(Icons.delete),
|
|
),
|
|
],
|
|
),
|
|
onTap: () {
|
|
// Handle tap on the list tile if needed
|
|
},
|
|
);
|
|
},
|
|
itemCount: SessionData.IE_SNAPSHOTS.length,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|