Fix some null check errors

This commit is contained in:
zontreck 2023-11-04 01:37:37 -07:00
parent d03613b0c7
commit fc9dc6f4d3
5 changed files with 26 additions and 32 deletions

View file

@ -61,18 +61,18 @@ class HomePageState extends State<HomePage> {
leading: Icon(CupertinoIcons.gear),
subtitle: Text("Linux Proton"),
onTap: () {
if (settings.inst!.steamcmd_path.isNotEmpty)
if (settings.steamcmd_path.isNotEmpty)
Navigator.pushNamed(context, "/proton");
},
), // Not yet implemented
ListTile(
title: Text("SteamCMD"),
leading: Icon(Icons.comment_rounded),
subtitle: settings.inst!.steamcmd_path.isEmpty
subtitle: settings.steamcmd_path.isEmpty
? Text("Path Not Set")
: Text(settings.inst!.steamcmd_path),
: Text(settings.steamcmd_path),
onTap: () {
if (settings.inst!.steamcmd_path.isNotEmpty) {
if (settings.steamcmd_path.isNotEmpty) {
Navigator.pushNamed(context, "/steamcmd");
}
},
@ -80,18 +80,18 @@ class HomePageState extends State<HomePage> {
ListTile(
title: Text("Server Path"),
leading: Icon(CupertinoIcons.folder),
subtitle: settings.inst!.game_path.isEmpty
subtitle: settings.game_path.isEmpty
? Text("Not Set")
: Text(settings.inst!.game_path),
: Text(settings.game_path),
onTap: () async {
var path = await getDirectoryPath();
setState(() {
if (path != null && path.isNotEmpty) {
settings.inst!.game_path = path;
settings.inst!.steamcmd_path =
settings.game_path = path;
settings.steamcmd_path =
path + Platform.pathSeparator + "scmd";
Directory.current = Directory(settings.inst!.game_path);
Directory.current = Directory(settings.game_path);
}
});

View file

@ -14,7 +14,7 @@ class Proton extends StatefulWidget {
Future<void> runProton(String command, List<String> argx) async {
Settings settings = Settings();
Directory dir =
Directory(settings.inst!.game_path + Platform.pathSeparator + "pfx");
Directory(settings.game_path + Platform.pathSeparator + "pfx");
if (dir.existsSync()) {
await dir.delete(recursive: true);

View file

@ -10,6 +10,9 @@ class Settings {
Settings._();
static final Settings Instance = Settings._();
String steamcmd_path = "";
String game_path = "";
factory Settings() {
return Instance;
}
@ -38,7 +41,7 @@ class Settings {
Future<Box<E>> Open<E>() {
Close();
return Hive.openBox("settings", path: inst!.game_path);
return Hive.openBox("settings", path: game_path);
}
static void Close() {
@ -48,33 +51,32 @@ class Settings {
}
String getServerPath() {
return inst!.game_path + Platform.pathSeparator + "server";
return game_path + Platform.pathSeparator + "server";
}
bool checkInitDone() {
if (File(inst!.steamcmd_path + Platform.pathSeparator + "cxinit")
.existsSync()) {
if (File(steamcmd_path + Platform.pathSeparator + "cxinit").existsSync()) {
return true;
} else
return false;
}
String getSteamCmd() {
return inst!.steamcmd_path +
return steamcmd_path +
Platform.pathSeparator +
"steamcmd" +
(Platform.isWindows ? ".exe" : ".sh");
}
String getSteamCmd2FA() {
return inst!.steamcmd_path +
return steamcmd_path +
Platform.pathSeparator +
"steamcmd-2fa" +
(Platform.isWindows ? ".exe" : "");
}
String getModPath() {
return inst!.game_path + Platform.pathSeparator + "mods";
return game_path + Platform.pathSeparator + "mods";
}
Future<void> createModFolderIfNotExists() async {

View file

@ -9,12 +9,6 @@ class SettingsEntry {
@HiveField(0)
List<Mod> mods = [];
@HiveField(1)
String steamcmd_path = "";
@HiveField(2)
String game_path = "";
@HiveField(3)
Credentials? steam_creds;
}

View file

@ -54,22 +54,21 @@ class SteamCMDState extends State<SteamCMD> {
changed: (X) {},
onSubmit: () async {
// Yes, Proceed
var x = Directory(settings.inst!.steamcmd_path);
var x = Directory(settings.steamcmd_path);
try {
await x.delete(recursive: true);
} catch (e) {}
await x.create(recursive: true);
Directory.current =
Directory(settings.inst!.steamcmd_path);
Directory.current = Directory(settings.steamcmd_path);
final dio = Dio();
Process proc;
if (Platform.isWindows) {
// Download zip file
final path = settings.inst!.steamcmd_path +
final path = settings.steamcmd_path +
Platform.pathSeparator +
"windows.zip";
final reply = await dio.download(windows, path);
@ -95,7 +94,7 @@ class SteamCMDState extends State<SteamCMD> {
await Process.start("steamcmd.exe", ["+quit"]);
} else {
// Download tgz file
final path = settings.inst!.steamcmd_path +
final path = settings.steamcmd_path +
Platform.pathSeparator +
"linux.tgz";
final reply = await dio.download(linux, path);
@ -124,8 +123,7 @@ class SteamCMDState extends State<SteamCMD> {
await Process.start("./steamcmd.sh", ["+quit"]);
}
Directory.current =
Directory(settings.inst!.game_path);
Directory.current = Directory(settings.game_path);
},
onCancel: () {},
isDefault: false,
@ -142,7 +140,7 @@ class SteamCMDState extends State<SteamCMD> {
final dio = Dio();
await dio.download(
Base2FAPath + (Platform.isWindows ? ".exe" : ""),
settings.inst!.steamcmd_path +
settings.steamcmd_path +
Platform.pathSeparator +
(Platform.isWindows
? "steamcmd-2fa.exe"
@ -150,7 +148,7 @@ class SteamCMDState extends State<SteamCMD> {
if (!Platform.isWindows)
var proc = await Process.start("chmod", [
"+x",
settings.inst!.steamcmd_path +
settings.steamcmd_path +
Platform.pathSeparator +
"steamcmd-2fa"
]);