Skip to content

Commit

Permalink
use separate file saver
Browse files Browse the repository at this point in the history
  • Loading branch information
moonheart committed Dec 31, 2023
1 parent 77f0067 commit bc75060
Show file tree
Hide file tree
Showing 59 changed files with 55 additions and 4,453 deletions.
6 changes: 6 additions & 0 deletions MementoMori.BlazorShared/IFileSaver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MementoMori.BlazorShared;

public interface IFileSaver
{
Task SaveFile(string content, string filename);
}
6 changes: 1 addition & 5 deletions MementoMori.BlazorShared/MementoMori.BlazorShared.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down Expand Up @@ -44,10 +44,6 @@
<PackageReference Include="Injectio" Version="3.1.0" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MementoMori\MementoMori.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions MementoMori.BlazorShared/Pages/BattleLog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@page "/battlelog"
@inject IJSRuntime JS
@inject IDialogService DialogService
@inject IFileSaver FileSaver

<MudText Typo="Typo.h6">
@ResourceStrings.You_can_download_the_battle_log_and_parse_it_here: <MudLink Href="https://mentemori.icu/battle_log.html" Target="_blank">Battle Log Viewer</MudLink>
Expand Down
18 changes: 2 additions & 16 deletions MementoMori.BlazorShared/Pages/BattleLog.razor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System.Text;
using AutoCtor;
#if ANDROID
using Microsoft.Maui.ApplicationModel.DataTransfer;
using Microsoft.Maui.Storage;
#endif
using MementoMori.Ortega.Share.Data.Battle.Result;
using MementoMori.Ortega.Share.Data.Battle.Result;
using Microsoft.JSInterop;
using Newtonsoft.Json;

Expand Down Expand Up @@ -55,22 +49,14 @@ private async Task DownloadBattleLog(string filename)
{
if (string.IsNullOrEmpty(filename)) return;
if (!ReadLogContent(filename, out var json)) return;
#if ANDROID
try
{
var tempPath = Path.Combine(FileSystem.CacheDirectory, filename);
await File.WriteAllTextAsync(tempPath, json);
await Share.Default.RequestAsync(new ShareFileRequest() { File = new ShareFile(tempPath) });
await FileSaver.SaveFile(json, filename);
}
catch (Exception e)
{
await DialogService.ShowMessageBox("错误", e.ToString());
}
#else
var bytes = Encoding.UTF8.GetBytes(json);
using var streamRef = new DotNetStreamReference(new MemoryStream(bytes));
await JS.InvokeVoidAsync("downloadFileFromStream", filename, streamRef);
#endif
}

private bool ReadLogContent(string filename, out string json)
Expand Down
2 changes: 1 addition & 1 deletion MementoMori.Common/MementoMori.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
12 changes: 0 additions & 12 deletions MementoMori.Maui/InitializeService.cs

This file was deleted.

4 changes: 2 additions & 2 deletions MementoMori.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private void UpdateInfo(string msg)

private async Task InitializeMemento()
{
var accountManager = Services.Get<AccountManager>();
var networkManager = Services.Get<MementoNetworkManager>();
var accountManager = Common.Services.Get<AccountManager>();
var networkManager = Common.Services.Get<MementoNetworkManager>();
UpdateInfo("Initializing...");
accountManager.MigrateToAccountArray();
accountManager.CurrentCulture = CultureInfo.CurrentCulture;
Expand Down
3 changes: 2 additions & 1 deletion MementoMori.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static MauiApp CreateMauiApp()

builder.Services.AddMementoMori();
builder.Services.AddMementoMoriBlazorShared();
builder.Services.AddMementoMoriMaui();
builder.Services.AddHttpClient();

builder.Services.AddOptions();
Expand All @@ -63,7 +64,7 @@ public static MauiApp CreateMauiApp()
#endif

var app = builder.Build();
Services.Setup(app.Services);
Common.Services.Setup(app.Services);

return app;
}
Expand Down
1 change: 1 addition & 0 deletions MementoMori.Maui/MementoMori.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<PackageReference Include="Quartz" Version="3.7.0" />
<PackageReference Include="Quartz.AspNetCore" Version="3.7.0" />
<PackageReference Include="Sentry.Maui" Version="3.41.3" />
<PackageReference Include="Injectio" Version="3.1.0" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions MementoMori.Maui/Services/FileSaver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Injectio.Attributes;
using MementoMori.BlazorShared;

namespace MementoMori.Maui.Services;

[RegisterSingleton]
public class FileSaver: IFileSaver
{
public async Task SaveFile(string content, string filename)
{
var tempPath = Path.Combine(FileSystem.CacheDirectory, filename);
await File.WriteAllTextAsync(tempPath, content);
await Share.Default.RequestAsync(new ShareFileRequest() { File = new ShareFile(tempPath) });
}
}
11 changes: 0 additions & 11 deletions MementoMori.WebUI/Extensions/GameExtensions.cs

This file was deleted.

8 changes: 0 additions & 8 deletions MementoMori.WebUI/Extensions/JsonExtensions.cs

This file was deleted.

10 changes: 0 additions & 10 deletions MementoMori.WebUI/Extensions/TimeExtensions.cs

This file was deleted.

198 changes: 0 additions & 198 deletions MementoMori.WebUI/Extensions/UserItemExtensions.cs

This file was deleted.

1 change: 1 addition & 0 deletions MementoMori.WebUI/MementoMori.WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="Quartz.AspNetCore" Version="3.7.0" />
<PackageReference Include="ReactiveUI.Blazor" Version="19.5.1" />
<PackageReference Include="Sentry.AspNetCore" Version="3.40.1" />
<PackageReference Include="Injectio" Version="3.1.0" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit bc75060

Please sign in to comment.