Skip to content

ReStreet: FIFA Street (2012) recompiled for Windows PC, with online play, a launcher with friends, chat and rooms. Bring your own game.

Launcher: review fixes (Brave path, safe save restore, atomic online.json, Linux setup pick)

SamuelitoDaVila2ff6120fd25e
diff --git a/Launcher/FifaStreetLauncher.Linux/Setup.cs b/Launcher/FifaStreetLauncher.Linux/Setup.cs
index 82591ef..03cd31e 100644
--- a/Launcher/FifaStreetLauncher.Linux/Setup.cs
+++ b/Launcher/FifaStreetLauncher.Linux/Setup.cs
@@ -192,27 +192,47 @@ internal sealed partial class Setup : IPageHost
}
}
+ // "ReStreet-2.1.10-Setup.exe" -> 2.1.10 (names sort wrong as text: "2.1.10" < "2.1.9"); anything else is 0.
+ internal static Version SetupVersion(string file)
+ {
+ string name = Path.GetFileName(file);
+ return name.StartsWith("ReStreet-", StringComparison.Ordinal) && name.EndsWith("-Setup.exe", StringComparison.Ordinal) &&
+ Version.TryParse(name["ReStreet-".Length..^"-Setup.exe".Length], out var v) ? v : new Version(0, 0);
+ }
+
+ private static string? NewestSetup(IEnumerable<string> dirs) =>
+ dirs.Where(Directory.Exists).SelectMany(d => Directory.GetFiles(d, "ReStreet-*-Setup.exe")).MaxBy(SetupVersion);
+
// The setup: one beside the launcher (offline installs), or the latest release's, checked against its .sha256.
+ // One the player downloaded is used when it is that release's setup, or (no network) the newest one there.
private async Task<string> GetSetup()
{
- foreach (string dir in new[] { AppContext.BaseDirectory, Path.Combine(AppContext.BaseDirectory, ".."), Path.Combine(Home, "Downloads"), Path.Combine(Home, "Transferências") })
- {
- if (!Directory.Exists(dir)) continue;
- string? local = Directory.GetFiles(dir, "ReStreet-*-Setup.exe").OrderByDescending(f => f, StringComparer.Ordinal).FirstOrDefault();
- if (local != null) { Step("Using " + Path.GetFileName(local), 1); return local; }
- }
+ string? beside = NewestSetup(new[] { AppContext.BaseDirectory, Path.Combine(AppContext.BaseDirectory, "..") });
+ if (beside != null) { Step("Using " + Path.GetFileName(beside), 1); return beside; }
+ string[] downloads = { Path.Combine(Home, "Downloads"), Path.Combine(Home, "Transferências") };
Step("Looking for the latest ReStreet release", 1);
using var http = new HttpClient { Timeout = TimeSpan.FromMinutes(30) };
http.DefaultRequestHeaders.UserAgent.ParseAdd("ReStreet-Linux-Launcher");
- var release = JsonNode.Parse(await http.GetStringAsync($"https://api.github.com/repos/{Repo}/releases/latest"))!;
+ string releaseJson;
+ try { releaseJson = await http.GetStringAsync($"https://api.github.com/repos/{Repo}/releases/latest"); }
+ catch (Exception ex) when ((ex is HttpRequestException or TaskCanceledException) && NewestSetup(downloads) is not null)
+ {
+ string offline = NewestSetup(downloads)!;
+ Step("No connection to GitHub; using " + Path.GetFileName(offline), 1);
+ return offline;
+ }
+ var release = JsonNode.Parse(releaseJson)!;
var assets = release["assets"]!.AsArray();
string Url(string suffix) => assets.Select(a => a!).FirstOrDefault(a => a["name"]!.GetValue<string>().EndsWith(suffix, StringComparison.Ordinal))
?["browser_download_url"]?.GetValue<string>() ?? throw new InvalidOperationException("The latest release has no " + suffix + " file.");
string exeUrl = Url("-Setup.exe"), shaUrl = Url("-Setup.exe.sha256");
string cache = Path.Combine(Home, ".cache", "restreet");
Directory.CreateDirectory(cache);
- string file = Path.Combine(cache, Path.GetFileName(new Uri(exeUrl).LocalPath));
+ string fileName = Path.GetFileName(new Uri(exeUrl).LocalPath);
+ string file = Path.Combine(cache, fileName);
string expected = (await http.GetStringAsync(shaUrl)).Split(' ', '\t', '\n')[0].Trim().ToLowerInvariant();
+ string? downloaded = downloads.Select(d => Path.Combine(d, fileName)).FirstOrDefault(f => File.Exists(f) && Sha256(f) == expected);
+ if (downloaded != null) { Step("Using " + fileName + " from " + Path.GetDirectoryName(downloaded), 15); return downloaded; }
if (!File.Exists(file) || Sha256(file) != expected)
{
using var response = await http.GetAsync(exeUrl, HttpCompletionOption.ResponseHeadersRead);
diff --git a/Launcher/FifaStreetLauncher/BrowserUi.cs b/Launcher/FifaStreetLauncher/BrowserUi.cs
index 0f22e9b..31dac3c 100644
--- a/Launcher/FifaStreetLauncher/BrowserUi.cs
+++ b/Launcher/FifaStreetLauncher/BrowserUi.cs
@@ -251,7 +251,7 @@ public partial class LauncherForm
Path.Combine(pf86, @"Microsoft\Edge\Application\msedge.exe"), Path.Combine(pf, @"Microsoft\Edge\Application\msedge.exe"),
Path.Combine(pf, @"Google\Chrome\Application\chrome.exe"), Path.Combine(pf86, @"Google\Chrome\Application\chrome.exe"),
Path.Combine(local, @"Google\Chrome\Application\chrome.exe"),
- Path.Combine(pf, @"BraveSoftware\Brave-Browser\Applicationrave.exe"),
+ Path.Combine(pf, @"BraveSoftware\Brave-Browser\Application\brave.exe"),
}.FirstOrDefault(File.Exists);
if (exe == null) return false;
Process.Start(new ProcessStartInfo(exe)
diff --git a/Launcher/FifaStreetLauncher/GlassUi.cs b/Launcher/FifaStreetLauncher/GlassUi.cs
index 4d93d0d..8470e76 100644
--- a/Launcher/FifaStreetLauncher/GlassUi.cs
+++ b/Launcher/FifaStreetLauncher/GlassUi.cs
@@ -269,7 +269,9 @@ public partial class LauncherForm
if (!File.Exists(path)) continue;
var node = System.Text.Json.Nodes.JsonNode.Parse(File.ReadAllText(path))!;
node["server"] = address;
- File.WriteAllText(path, node.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
+ // Written beside and then moved over: a crash mid-write must not leave online.json (name, key) broken.
+ File.WriteAllText(path + ".tmp", node.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
+ File.Move(path + ".tmp", path, true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
{
diff --git a/Launcher/FifaStreetLauncher/SaveRestore.cs b/Launcher/FifaStreetLauncher/SaveRestore.cs
index 6cf2b77..92a0e86 100644
--- a/Launcher/FifaStreetLauncher/SaveRestore.cs
+++ b/Launcher/FifaStreetLauncher/SaveRestore.cs
@@ -118,39 +118,42 @@ public partial class LauncherForm
return "Could not make the backup (" + ex.Message + "): nothing was changed";
}
- // 2. The current saves go to _apagados the way the game moves a deleted save (their copies in _copia too).
+ // 2. The current saves go to _apagados the way the game moves a deleted save (their copies in _copia after 3).
string current = Path.Combine(title, SaveType), headers = Path.Combine(title, HeadersDir, SaveType);
long unix = new DateTimeOffset(now).ToUnixTimeSeconds();
var moved = new List<(string Dir, string Header, string To, string Name)>();
- if (Directory.Exists(current))
- foreach (string dir in Directory.GetDirectories(current))
- {
- string curName = Path.GetFileName(dir);
- string to = Path.Combine(trash, unix + "-" + curName);
- if (Directory.Exists(to)) to += "-" + Guid.NewGuid().ToString("N")[..6];
- Directory.CreateDirectory(to);
- Directory.Move(dir, Path.Combine(to, "dados"));
- string curHeader = Path.Combine(headers, curName + ".header");
- if (File.Exists(curHeader)) File.Move(curHeader, Path.Combine(to, curName + ".header"));
- moved.Add((dir, curHeader, to, curName));
- }
-
- // 3. The chosen save, copied back (it stays in _apagados too). A failure puts the current save back.
string target = Path.Combine(current, name), targetHeader = Path.Combine(headers, name + ".header");
+ bool copying = false; // before step 3, |target| can still be a current save of the same name: never delete it
try
{
+ if (Directory.Exists(current))
+ foreach (string dir in Directory.GetDirectories(current))
+ {
+ string curName = Path.GetFileName(dir);
+ string to = Path.Combine(trash, unix + "-" + curName);
+ if (Directory.Exists(to)) to += "-" + Guid.NewGuid().ToString("N")[..6];
+ string curHeader = Path.Combine(headers, curName + ".header");
+ Directory.CreateDirectory(to);
+ moved.Add((dir, curHeader, to, curName));
+ Directory.Move(dir, Path.Combine(to, "dados"));
+ if (File.Exists(curHeader)) File.Move(curHeader, Path.Combine(to, curName + ".header"));
+ }
+
+ // 3. The chosen save, copied back (it stays in _apagados too).
+ copying = true;
CopyFolder(data, target);
Directory.CreateDirectory(headers);
File.Copy(header, targetHeader, true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
- if (Directory.Exists(target)) Directory.Delete(target, true);
- if (File.Exists(targetHeader)) File.Delete(targetHeader);
+ // A failure in step 2 or 3 puts back every current save that already left.
+ if (copying && Directory.Exists(target)) Directory.Delete(target, true);
+ if (copying && File.Exists(targetHeader)) File.Delete(targetHeader);
foreach (var m in moved)
{
- Directory.Move(Path.Combine(m.To, "dados"), m.Dir);
- string h = Path.Combine(m.To, m.Name + ".header");
+ string dados = Path.Combine(m.To, "dados"), h = Path.Combine(m.To, m.Name + ".header");
+ if (Directory.Exists(dados)) Directory.Move(dados, m.Dir);
if (File.Exists(h)) File.Move(h, m.Header);
Directory.Delete(m.To, true);
}