1
0
forked from MeloNX/MeloNX

Compare commits

..

No commits in common. "cb71eadb53200b0c8d4307f15b5154d79c273a8d" and "5d5f6c330f0fa2e437f7bc1b8b2aacb8e0c9cb3c" have entirely different histories.

4 changed files with 163 additions and 175 deletions

View File

@ -14,51 +14,45 @@ struct GameInfoSheet: View {
var body: some View { var body: some View {
iOSNav { iOSNav {
List { VStack {
Section {} if let icon = game.icon {
header: { Image(uiImage: icon)
VStack(alignment: .center) { .resizable()
if let icon = game.icon { .aspectRatio(contentMode: .fit)
Image(uiImage: icon) .frame(width: 250, height: 250)
.resizable() .cornerRadius(10)
.aspectRatio(contentMode: .fit) .padding()
.frame(width: 250, height: 250) .contextMenu {
.cornerRadius(10) Button {
.padding() UIImageWriteToSavedPhotosAlbum(icon, nil, nil, nil)
.contextMenu { } label: {
Button { Label("Save to Photos", systemImage: "square.and.arrow.down")
UIImageWriteToSavedPhotosAlbum(icon, nil, nil, nil) }
} label: {
Label("Save to Photos", systemImage: "square.and.arrow.down")
}
}
} else {
Image(systemName: "questionmark.circle")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 150, height: 150)
.padding()
} }
VStack(alignment: .center) { } else {
Text("**\(game.titleName)** | \(game.titleId.capitalized)") Image(systemName: "questionmark.circle")
Text(game.developer) .resizable()
.font(.caption) .aspectRatio(contentMode: .fit)
.foregroundStyle(.secondary) .frame(width: 150, height: 150)
} .padding()
.padding(.vertical, 3)
}
.frame(maxWidth: .infinity)
} }
Section { VStack(alignment: .leading) {
HStack { VStack(alignment: .leading) {
Text("**Version**") Text("**\(game.titleName)** | \(game.titleId.capitalized)")
Spacer() Text(game.developer)
Text(game.version) .font(.caption)
.foregroundStyle(Color.secondary) .foregroundStyle(.secondary)
} }
HStack { .padding(.vertical, 3)
Text("**Title ID**")
VStack(alignment: .leading, spacing: 5) {
Text("Information")
.font(.title2)
.bold()
Text("**Version:** \(game.version)")
Text("**Title ID:** \(game.titleId)")
.contextMenu { .contextMenu {
Button { Button {
UIPasteboard.general.string = game.titleId UIPasteboard.general.string = game.titleId
@ -66,32 +60,15 @@ struct GameInfoSheet: View {
Text("Copy Title ID") Text("Copy Title ID")
} }
} }
Spacer() Text("**Game Size:** \(fetchFileSize(for: game.fileURL) ?? 0) bytes")
Text(game.titleId) Text("**File Type:** .\(getFileType(game.fileURL))")
.foregroundStyle(Color.secondary) Text("**Game URL:** \(trimGameURL(game.fileURL))")
} }
HStack {
Text("**Game Size**")
Spacer()
Text("\(fetchFileSize(for: game.fileURL) ?? 0) bytes")
.foregroundStyle(Color.secondary)
}
HStack {
Text("**File Type**")
Spacer()
Text(getFileType(game.fileURL))
.foregroundStyle(Color.secondary)
}
VStack(alignment: .leading, spacing: 4) {
Text("**Game URL**")
Text(trimGameURL(game.fileURL))
.foregroundStyle(Color.secondary)
}
} header: {
Text("Information")
} }
.headerProminence(.increased)
Spacer()
} }
.padding(.horizontal, 5)
.navigationTitle(game.titleName) .navigationTitle(game.titleName)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
@ -126,6 +103,10 @@ struct GameInfoSheet: View {
} }
func getFileType(_ url: URL) -> String { func getFileType(_ url: URL) -> String {
url.pathExtension let path = url.path
if let range = path.range(of: ".") {
return String(path[range.upperBound...])
}
return "Unknown"
} }
} }

View File

@ -42,54 +42,72 @@ struct GameLibraryView: View {
} }
return Ryujinx.shared.games.filter { return Ryujinx.shared.games.filter {
$0.titleName.localizedCaseInsensitiveContains(searchText) || $0.titleName.localizedCaseInsensitiveContains(searchText) ||
$0.developer.localizedCaseInsensitiveContains(searchText) $0.developer.localizedCaseInsensitiveContains(searchText)
} }
} }
var body: some View { var body: some View {
iOSNav { iOSNav {
List { ScrollView {
if Ryujinx.shared.games.isEmpty { LazyVStack(alignment: .leading, spacing: 20) {
VStack(spacing: 16) { if !isSearching {
Image(systemName: "gamecontroller.fill") Text("Games")
.font(.system(size: 64)) .font(.system(size: 34, weight: .bold))
.foregroundColor(.secondary.opacity(0.7)) .padding(.horizontal)
.padding(.top, 60) .padding(.top, 12)
Text("No Games Found")
.font(.title2.bold())
.foregroundColor(.primary)
Text("Add ROM, Keys and Firmware to get started")
.font(.subheadline)
.foregroundColor(.secondary)
} }
.frame(maxWidth: .infinity)
.padding(.top, 40)
} else {
if !isSearching && !recentGames.isEmpty {
VStack(alignment: .leading, spacing: 12) {
Text("Recent")
.font(.title2.bold())
.padding(.horizontal)
ScrollView(.horizontal, showsIndicators: false) { if Ryujinx.shared.games.isEmpty {
LazyHStack(spacing: 16) { VStack(spacing: 16) {
ForEach(recentGames) { game in Image(systemName: "gamecontroller.fill")
RecentGameCard(game: game, startemu: $startemu) .font(.system(size: 64))
.foregroundColor(.secondary.opacity(0.7))
.padding(.top, 60)
Text("No Games Found")
.font(.title2.bold())
.foregroundColor(.primary)
Text("Add ROM, Keys and Firmware to get started")
.font(.subheadline)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity)
.padding(.top, 40)
} else {
if !isSearching && !recentGames.isEmpty {
VStack(alignment: .leading, spacing: 12) {
Text("Recent")
.font(.title2.bold())
.padding(.horizontal)
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 16) {
ForEach(recentGames) { game in
RecentGameCard(game: game, startemu: $startemu)
.onTapGesture {
addToRecentGames(game)
startemu = game
}
}
}
.padding(.horizontal)
}
}
VStack(alignment: .leading, spacing: 12) {
Text("All Games")
.font(.title2.bold())
.padding(.horizontal)
LazyVStack(spacing: 2) {
ForEach(filteredGames) { game in
GameListRow(game: game, startemu: $startemu, games: games, isViewingGameInfo: $isViewingGameInfo, isSelectingGameUpdate: $isSelectingGameUpdate, gameInfo: $gameInfo)
.onTapGesture { .onTapGesture {
addToRecentGames(game) addToRecentGames(game)
startemu = game
} }
} }
} }
.padding(.horizontal)
} }
} } else {
VStack(alignment: .leading, spacing: 12) {
Text("All Games")
.font(.title2.bold())
.padding(.horizontal)
LazyVStack(spacing: 2) { LazyVStack(spacing: 2) {
ForEach(filteredGames) { game in ForEach(filteredGames) { game in
GameListRow(game: game, startemu: $startemu, games: games, isViewingGameInfo: $isViewingGameInfo, isSelectingGameUpdate: $isSelectingGameUpdate, gameInfo: $gameInfo) GameListRow(game: game, startemu: $startemu, games: games, isViewingGameInfo: $isViewingGameInfo, isSelectingGameUpdate: $isSelectingGameUpdate, gameInfo: $gameInfo)
@ -99,44 +117,35 @@ struct GameLibraryView: View {
} }
} }
} }
} else {
ForEach(filteredGames) { game in
GameListRow(game: game, startemu: $startemu, games: games, isViewingGameInfo: $isViewingGameInfo, isSelectingGameUpdate: $isSelectingGameUpdate, gameInfo: $gameInfo)
.onTapGesture {
addToRecentGames(game)
}
}
} }
} }
} .onAppear {
.navigationTitle("Games") loadRecentGames()
.navigationBarTitleDisplayMode(.large)
.onAppear {
loadRecentGames()
let firmware = Ryujinx.shared.fetchFirmwareVersion() let firmware = Ryujinx.shared.fetchFirmwareVersion()
firmwareversion = (firmware == "" ? "0" : firmware) firmwareversion = (firmware == "" ? "0" : firmware)
} }
.fileImporter(isPresented: $firmwareInstaller, allowedContentTypes: [.item]) { result in .fileImporter(isPresented: $firmwareInstaller, allowedContentTypes: [.item]) { result in
switch result { switch result {
case .success(let url): case .success(let url):
do { do {
let fun = url.startAccessingSecurityScopedResource() let fun = url.startAccessingSecurityScopedResource()
let path = url.path let path = url.path
Ryujinx.shared.installFirmware(firmwarePath: path) Ryujinx.shared.installFirmware(firmwarePath: path)
firmwareversion = (Ryujinx.shared.fetchFirmwareVersion() == "" ? "0" : Ryujinx.shared.fetchFirmwareVersion()) firmwareversion = (Ryujinx.shared.fetchFirmwareVersion() == "" ? "0" : Ryujinx.shared.fetchFirmwareVersion())
if fun { if fun {
url.stopAccessingSecurityScopedResource() url.stopAccessingSecurityScopedResource()
}
} }
case .failure(let error):
print(error)
} }
case .failure(let error):
print(error)
} }
} }
.toolbar { .toolbar {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarLeading) {
Button { Button {
isSelectingGameFile.toggle() isSelectingGameFile.toggle()
} label: { } label: {
@ -206,6 +215,7 @@ struct GameLibraryView: View {
} }
} }
} }
.background(Color(.systemGroupedBackground))
.searchable(text: $searchText) .searchable(text: $searchText)
.onChange(of: searchText) { _ in .onChange(of: searchText) { _ in
isSearching = !searchText.isEmpty isSearching = !searchText.isEmpty
@ -286,6 +296,7 @@ struct GameLibraryView: View {
} }
} }
private func addToRecentGames(_ game: Game) { private func addToRecentGames(_ game: Game) {
recentGames.removeAll { $0.id == game.id } recentGames.removeAll { $0.id == game.id }
@ -318,7 +329,8 @@ struct GameLibraryView: View {
} }
} }
// MARK: - Delete Game Function
// MARK: - Delete Game Function
func deleteGame(game: Game) { func deleteGame(game: Game) {
let fileManager = FileManager.default let fileManager = FileManager.default
do { do {
@ -331,7 +343,7 @@ struct GameLibraryView: View {
} }
} }
// MARK: - Game Model // MARK: -Game Model
extension Game: Codable { extension Game: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case titleName, titleId, developer, version, fileURL case titleName, titleId, developer, version, fileURL
@ -360,7 +372,7 @@ extension Game: Codable {
} }
} }
// MARK: - Recent Game Card // MARK: -Recent Game Card
struct RecentGameCard: View { struct RecentGameCard: View {
let game: Game let game: Game
@Binding var startemu: Game? @Binding var startemu: Game?
@ -381,7 +393,7 @@ struct RecentGameCard: View {
ZStack { ZStack {
RoundedRectangle(cornerRadius: 12) RoundedRectangle(cornerRadius: 12)
.fill(colorScheme == .dark ? .fill(colorScheme == .dark ?
Color(.systemGray5) : Color(.systemGray6)) Color(.systemGray5) : Color(.systemGray6))
.frame(width: 140, height: 140) .frame(width: 140, height: 140)
Image(systemName: "gamecontroller.fill") Image(systemName: "gamecontroller.fill")
@ -407,7 +419,7 @@ struct RecentGameCard: View {
} }
} }
// MARK: - Game List Item // MARK: -Game List Item
struct GameListRow: View { struct GameListRow: View {
let game: Game let game: Game
@Binding var startemu: Game? @Binding var startemu: Game?
@ -435,7 +447,7 @@ struct GameListRow: View {
ZStack { ZStack {
RoundedRectangle(cornerRadius: 8) RoundedRectangle(cornerRadius: 8)
.fill(colorScheme == .dark ? .fill(colorScheme == .dark ?
Color(.systemGray5) : Color(.systemGray6)) Color(.systemGray5) : Color(.systemGray6))
.frame(width: 45, height: 45) .frame(width: 45, height: 45)
Image(systemName: "gamecontroller.fill") Image(systemName: "gamecontroller.fill")
@ -462,6 +474,9 @@ struct GameListRow: View {
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
.opacity(0.8) .opacity(0.8)
} }
.padding(.horizontal)
.padding(.vertical, 8)
.background(Color(.systemBackground))
.contextMenu { .contextMenu {
Section { Section {
Button { Button {
@ -518,3 +533,4 @@ struct GameListRow: View {
} }
} }
} }

View File

@ -18,42 +18,36 @@ struct UpdateManagerSheet: View {
var body: some View { var body: some View {
NavigationView { NavigationView {
List(paths, id: \..self, selection: $selectedItem) { item in VStack {
Button(action: { List(paths, id: \..self) { item in
selectItem(item.lastPathComponent) Button(action: {
}) { selectItem(item.lastPathComponent)
HStack { }) {
Text(item.lastPathComponent) HStack {
.foregroundStyle(Color(uiColor: .label)) Text(item.lastPathComponent)
Spacer() if selectedItem == "\(game!.titleId)/\(item.lastPathComponent)" {
if selectedItem == "\(game!.titleId)/\(item.lastPathComponent)" { Spacer()
Image(systemName: "checkmark.circle.fill") Image(systemName: "checkmark")
.foregroundStyle(Color.accentColor) }
.font(.system(size: 24)) }
} else { }
Image(systemName: "circle") .contextMenu {
.foregroundStyle(Color(uiColor: .secondaryLabel)) Button {
.font(.system(size: 24)) removeUpdate(item)
} label: {
Text("Remove Update")
} }
} }
} }
.contextMenu {
Button {
removeUpdate(item)
} label: {
Text("Remove Update")
}
}
} }
.onAppear { .onAppear() {
print(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json")) print(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
loadJSON(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json")) loadJSON(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
} }
.navigationTitle("\(game!.titleName) Updates") .navigationTitle("\(game!.titleName) Updates")
.navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
Button("Add", systemImage: "plus") { Button("+") {
isSelectingGameUpdate = true isSelectingGameUpdate = true
} }
} }
@ -86,8 +80,7 @@ struct UpdateManagerSheet: View {
let destinationURL = romUpdatedDirectory.appendingPathComponent(url.lastPathComponent) let destinationURL = romUpdatedDirectory.appendingPathComponent(url.lastPathComponent)
try? fileManager.copyItem(at: url, to: destinationURL) try? fileManager.copyItem(at: url, to: destinationURL)
items.append(gameInfo.titleId + "/" + url.lastPathComponent) Ryujinx.shared.setTitleUpdate(titleId: gameInfo.titleId, updatePath: "\(gameInfo.titleId)/" + url.lastPathComponent)
selectItem(url.lastPathComponent)
Ryujinx.shared.games = Ryujinx.shared.loadGames() Ryujinx.shared.games = Ryujinx.shared.loadGames()
loadJSON(jsonURL!) loadJSON(jsonURL!)
} catch { } catch {
@ -115,7 +108,6 @@ struct UpdateManagerSheet: View {
} }
saveJSON(selectedItem: selectedItem ?? "") saveJSON(selectedItem: selectedItem ?? "")
Ryujinx.shared.games = Ryujinx.shared.loadGames()
} }
func saveJSON(selectedItem: String) { func saveJSON(selectedItem: String) {
@ -130,6 +122,7 @@ struct UpdateManagerSheet: View {
} }
func loadJSON(_ json: URL) { func loadJSON(_ json: URL) {
self.jsonURL = json self.jsonURL = json
print("Failed to read JSO") print("Failed to read JSO")
@ -139,17 +132,16 @@ struct UpdateManagerSheet: View {
do { do {
let data = try Data(contentsOf: jsonURL) let data = try Data(contentsOf: jsonURL)
if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let list = jsonDict["paths"] as? [String] let list = jsonDict["paths"] as? [String] {
{
var urls: [URL] = [] var urls: [URL] = []
for path in list { for path in list {
urls.append(URL.documentsDirectory.appendingPathComponent("updates").appendingPathComponent(path)) urls.append(URL.documentsDirectory.appendingPathComponent("updates").appendingPathComponent(path))
} }
items = list self.items = list
paths = urls self.paths = urls
selectedItem = jsonDict["selected"] as? String self.selectedItem = jsonDict["selected"] as? String
} }
} catch { } catch {
print("Failed to read JSON: \(error)") print("Failed to read JSON: \(error)")
@ -163,8 +155,8 @@ struct UpdateManagerSheet: View {
do { do {
let newData = try JSONSerialization.data(withJSONObject: defaultData, options: .prettyPrinted) let newData = try JSONSerialization.data(withJSONObject: defaultData, options: .prettyPrinted)
try newData.write(to: jsonURL) try newData.write(to: jsonURL)
items = [] self.items = []
selectedItem = "" self.selectedItem = ""
} catch { } catch {
print("Failed to create default JSON: \(error)") print("Failed to create default JSON: \(error)")
} }
@ -191,9 +183,9 @@ struct UpdateManagerSheet: View {
let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted) let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
try newData.write(to: jsonURL) try newData.write(to: jsonURL)
Ryujinx.shared.games = Ryujinx.shared.loadGames()
} catch { } catch {
print("Failed to update JSON: \(error)") print("Failed to update JSON: \(error)")
} }
} }
} }

View File

@ -751,8 +751,7 @@ namespace Ryujinx.Headless.SDL2
if (File.Exists(titleUpdateMetadataPath)) if (File.Exists(titleUpdateMetadataPath))
{ {
string updatePathRelative = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, _titleSerializerContext.TitleUpdateMetadata).Selected; updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, _titleSerializerContext.TitleUpdateMetadata).Selected;
updatePath = Path.Combine(AppDataManager.BaseDirPath, "updates", updatePathRelative);
if (File.Exists(updatePath)) if (File.Exists(updatePath))
{ {