Skip to content

Commit

Permalink
Reorganize models
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 15, 2024
1 parent c58a8ab commit 0b20720
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 75 deletions.
9 changes: 7 additions & 2 deletions Bloxstrap/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
global using System.Diagnostics;
global using System.Globalization;
global using System.IO;
global using System.IO.Compression;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Serialization;
Expand All @@ -18,10 +17,16 @@
global using Bloxstrap.Exceptions;
global using Bloxstrap.Extensions;
global using Bloxstrap.Models;
global using Bloxstrap.Models.APIs.Config;
global using Bloxstrap.Models.APIs.GitHub;
global using Bloxstrap.Models.APIs.Roblox;
global using Bloxstrap.Models.Attributes;
global using Bloxstrap.Models.BloxstrapRPC;
global using Bloxstrap.Models.RobloxApi;
global using Bloxstrap.Models.Entities;
global using Bloxstrap.Models.Manifest;
global using Bloxstrap.Models.Persistable;
global using Bloxstrap.Models.SettingTasks;
global using Bloxstrap.Models.SettingTasks.Base;
global using Bloxstrap.Resources;
global using Bloxstrap.UI;
global using Bloxstrap.Utility;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.APIs.Config
{
public class Supporter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.APIs.Config
{
public class SupporterData
{
Expand Down
8 changes: 8 additions & 0 deletions Bloxstrap/Models/APIs/GitHub/GitHubReleaseAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class GithubReleaseAsset
{
[JsonPropertyName("browser_download_url")]
public string BrowserDownloadUrl { get; set; } = null!;

[JsonPropertyName("name")]
public string Name { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.APIs.GitHub
{
public class GithubRelease
{
Expand All @@ -7,7 +7,7 @@ public class GithubRelease

[JsonPropertyName("name")]
public string Name { get; set; } = null!;

[JsonPropertyName("body")]
public string Body { get; set; } = null!;

Expand All @@ -17,13 +17,4 @@ public class GithubRelease
[JsonPropertyName("assets")]
public List<GithubReleaseAsset>? Assets { get; set; }
}

public class GithubReleaseAsset
{
[JsonPropertyName("browser_download_url")]
public string BrowserDownloadUrl { get; set; } = null!;

[JsonPropertyName("name")]
public string Name { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Bloxstrap.Models
{
public class IPInfoResponse
{
[JsonPropertyName("city")]
public string City { get; set; } = null!;

[JsonPropertyName("country")]
public string Country { get; set; } = null!;

[JsonPropertyName("region")]
public string Region { get; set; } = null!;
}
}
namespace Bloxstrap.Models.APIs
{
public class IPInfoResponse
{
[JsonPropertyName("city")]
public string City { get; set; } = null!;

[JsonPropertyName("country")]
public string Country { get; set; } = null!;

[JsonPropertyName("region")]
public string Region { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models.RobloxApi
namespace Bloxstrap.Models.APIs.Roblox
{
/// <summary>
/// Roblox.Web.WebAPI.Models.ApiArrayResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.APIs.Roblox
{
public class ClientFlagSettings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.APIs.Roblox
{
public class ClientVersion
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models.RobloxApi
namespace Bloxstrap.Models.APIs.Roblox
{
/// <summary>
/// Roblox.Games.Api.Models.Response.GameCreator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models.RobloxApi
namespace Bloxstrap.Models.APIs.Roblox
{

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models.RobloxApi
namespace Bloxstrap.Models.APIs.Roblox
{
/// <summary>
/// Roblox.Web.Responses.Thumbnails.ThumbnailResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bloxstrap.Models.RobloxApi
namespace Bloxstrap.Models.APIs.Roblox
{
// lmao its just one property
public class UniverseIdResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Web;
using System.Windows;
using System.Windows.Input;

using Bloxstrap.Models.APIs;
using CommunityToolkit.Mvvm.Input;

namespace Bloxstrap.Models
namespace Bloxstrap.Models.Entities
{
public class ActivityData
{
Expand All @@ -16,7 +16,7 @@ public class ActivityData
/// </summary>
public ActivityData? RootActivity;

public long UniverseId
public long UniverseId
{
get => _universeId;
set
Expand All @@ -28,19 +28,19 @@ public long UniverseId

public long PlaceId { get; set; } = 0;

public string JobId { get; set; } = String.Empty;
public string JobId { get; set; } = string.Empty;

/// <summary>
/// This will be empty unless the server joined is a private server
/// </summary>
public string AccessCode { get; set; } = String.Empty;
public string MachineAddress { get; set; } = String.Empty;
public string AccessCode { get; set; } = string.Empty;

public string MachineAddress { get; set; } = string.Empty;

public bool MachineAddressValid => !String.IsNullOrEmpty(MachineAddress) && !MachineAddress.StartsWith("10.");
public bool MachineAddressValid => !string.IsNullOrEmpty(MachineAddress) && !MachineAddress.StartsWith("10.");

public bool IsTeleport { get; set; } = false;

public ServerType ServerType { get; set; } = ServerType.Public;

public DateTime TimeJoined { get; set; }
Expand All @@ -52,15 +52,15 @@ public long UniverseId
/// <summary>
/// This is intended only for other people to use, i.e. context menu invite link, rich presence joining
/// </summary>
public string RPCLaunchData { get; set; } = String.Empty;
public string RPCLaunchData { get; set; } = string.Empty;

public UniverseDetails? UniverseDetails { get; set; }

public string GameHistoryDescription
{
get
{
string desc = String.Format("{0} • {1} - {2}", UniverseDetails?.Data.Creator.Name, TimeJoined.ToString("h:mm tt"), TimeLeft?.ToString("h:mm tt"));
string desc = string.Format("{0} • {1} - {2}", UniverseDetails?.Data.Creator.Name, TimeJoined.ToString("h:mm tt"), TimeLeft?.ToString("h:mm tt"));

if (ServerType != ServerType.Public)
desc += "" + ServerType.ToTranslatedString();
Expand All @@ -82,7 +82,7 @@ public string GetInviteDeeplink(bool launchData = true)
else
deeplink += "&gameInstanceId=" + JobId;

if (launchData && !String.IsNullOrEmpty(RPCLaunchData))
if (launchData && !string.IsNullOrEmpty(RPCLaunchData))
deeplink += "&launchData=" + HttpUtility.UrlEncode(RPCLaunchData);

return deeplink;
Expand All @@ -107,7 +107,7 @@ public string GetInviteDeeplink(bool launchData = true)
{
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{MachineAddress}/json");

if (String.IsNullOrEmpty(ipInfo.City))
if (string.IsNullOrEmpty(ipInfo.City))
throw new InvalidHTTPResponseException("Reported city was blank");

if (ipInfo.City == ipInfo.Region)
Expand All @@ -127,9 +127,9 @@ public string GetInviteDeeplink(bool launchData = true)
serverQuerySemaphore.Release();

Frontend.ShowConnectivityDialog(
String.Format(Strings.Dialog_Connectivity_UnableToConnect, "ipinfo.io"),
Strings.ActivityWatcher_LocationQueryFailed,
MessageBoxImage.Warning,
string.Format(Strings.Dialog_Connectivity_UnableToConnect, "ipinfo.io"),
Strings.ActivityWatcher_LocationQueryFailed,
MessageBoxImage.Warning,
ex
);
}
Expand All @@ -142,7 +142,7 @@ public string GetInviteDeeplink(bool launchData = true)
private void RejoinServer()
{
string playerPath = Path.Combine(Paths.Roblox, "Player", "RobloxPlayerBeta.exe");

Process.Start(playerPath, GetInviteDeeplink(false));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System.Security.Cryptography;
using System.Windows.Markup;

namespace Bloxstrap.Models
namespace Bloxstrap.Models.Entities
{
public class ModPresetFileData
{
public string FilePath { get; private set; }

public string FullFilePath => Path.Combine(Paths.Modifications, FilePath);

public FileStream FileStream => File.OpenRead(FullFilePath);

public string ResourceIdentifier { get; private set; }

public Stream ResourceStream => Resource.GetStream(ResourceIdentifier);

public byte[] ResourceHash { get; private set; }

public ModPresetFileData(string contentPath, string resource)
public ModPresetFileData(string contentPath, string resource)
{
FilePath = contentPath;
ResourceIdentifier = resource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
namespace Bloxstrap.Models
using Bloxstrap.Models.APIs.Roblox;

namespace Bloxstrap.Models.Entities
{
public class UniverseDetails
{
private static List<UniverseDetails> _cache { get; set; } = new();

public GameDetailResponse Data { get; set; } = null!;

/// <summary>
/// Returns data for a 128x128 icon
/// </summary>
public ThumbnailResponse Thumbnail { get; set; } = null!;

public static UniverseDetails? LoadFromCache(long id)
{
var cacheQuery = _cache.Where(x => x.Data?.Id == id);
var cacheQuery = _cache.Where(x => x.Data?.Id == id);

if (cacheQuery.Any())
if (cacheQuery.Any())
return cacheQuery.First();

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.Persistable
{
public class AppState
{
public string VersionGuid { get; set; } = String.Empty;
public string VersionGuid { get; set; } = string.Empty;

public Dictionary<string, string> PackageHashes { get; set; } = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;

namespace Bloxstrap.Models
namespace Bloxstrap.Models.Persistable
{
public class Settings
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.Persistable
{
public class State
{
public bool ShowFFlagEditorWarning { get; set; } = true;

public bool PromptWebView2Install { get; set; } = true;

public AppState Player { get; set; } = new();

public AppState Studio { get; set; } = new();

public WindowState SettingsWindow { get; set; } = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Bloxstrap.Models
namespace Bloxstrap.Models.Persistable
{
public class WindowState
{
public double Width { get; set; }

public double Height { get; set; }

public double Left { get; set; }

public double Top { get; set; }
}
}
3 changes: 2 additions & 1 deletion Bloxstrap/Models/SettingTasks/EnumModPresetTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bloxstrap.Models.SettingTasks.Base;
using Bloxstrap.Models.Entities;
using Bloxstrap.Models.SettingTasks.Base;

namespace Bloxstrap.Models.SettingTasks
{
Expand Down
3 changes: 2 additions & 1 deletion Bloxstrap/Models/SettingTasks/ModPresetTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bloxstrap.Models.SettingTasks.Base;
using Bloxstrap.Models.Entities;
using Bloxstrap.Models.SettingTasks.Base;

namespace Bloxstrap.Models.SettingTasks
{
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Settings/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Bloxstrap.UI.Elements.Settings
/// </summary>
public partial class MainWindow : INavigationWindow
{
private Models.WindowState _state => App.State.Prop.SettingsWindow;
private Models.Persistable.WindowState _state => App.State.Prop.SettingsWindow;

public MainWindow(bool showAlreadyRunningWarning)
{
Expand Down

0 comments on commit 0b20720

Please sign in to comment.