Skip to content

Commit

Permalink
add: upgrade to .NET SDK 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsShamed committed Jun 13, 2022
1 parent b19956a commit 38656b0
Show file tree
Hide file tree
Showing 23 changed files with 7,368 additions and 836 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release on push

on:
push:
branches:
- master

jobs:
Release:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.x'
- name: Install dependencies
run: dotnet restore
- name: Publish solution
run: dotnet publish -c Release -o publish
- name: Create release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: publish/OsuPackImporter.exe
body_path: ${{ github.workspace }}/CHANGELOG.md
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Current features

* Import an archive and dump the beatmap list into `collection.db`
and auto import the beatmaps in osu!
* Import an archive and convert the beatmap list into a `.osdb` file usable
with [Piotrekol's Collection Manager](https://github.com/Piotrekol/CollectionManager).
* Prevent auto-import with `--no-import` flag

### Supported archive types
* RAR
* Zip
* 7Zip
* GZip
* Tar
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright 2022 Kirutsu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

6 changes: 5 additions & 1 deletion OsuPackImporter.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABeatmap_002Ecs_002Fl_003AC_0021_003FUsers_003FCubicFace_003FAppData_003FRoaming_003FJetBrains_003FRider2022_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F636b3e5dc45c46c3912e16d43ed5e9d91e600_003F80_003F630686aa_003FBeatmap_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABeatmap_002Ecs_002Fl_003AC_0021_003FUsers_003FCubicFace_003FAppData_003FRoaming_003FJetBrains_003FRider2022_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F636b3e5dc45c46c3912e16d43ed5e9d91e600_003F80_003F630686aa_003FBeatmap_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.5\ref\net6.0\Microsoft.VisualBasic.dll" /&gt;&#xD;
&lt;Assembly Path="C:\Users\CubicFace\.nuget\packages\commandlineparser\2.9.1\lib\netstandard2.0\CommandLine.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
36 changes: 19 additions & 17 deletions OsuPackImporter/App.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?><configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
141 changes: 70 additions & 71 deletions OsuPackImporter/Beatmaps/BeatmapSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,106 @@
using OsuPackImporter.Beatmaps.LibExtensions;
using OsuPackImporter.Interfaces.Parsers;
using OsuPackImporter.Interfaces.Serializers;
using SharpCompress.Archives.Rar;
using SharpCompress.Archives.Zip;
using SharpCompress.Common;
using Spectre.Console;

namespace OsuPackImporter.Beatmaps
namespace OsuPackImporter.Beatmaps;

public class BeatmapSet : IParsable, IOSDBSerializable
{
public class BeatmapSet : IParsable, IOSDBSerializable
private Stream _fileStream;

public BeatmapSet(Stream fileStream, ProgressContext? context = null)
{
private Stream _fileStream;
public List<ExtendedBeatmap> Beatmaps { get; }
Beatmaps = new List<ExtendedBeatmap>();
_fileStream = fileStream;
Parse(context);
}

public BeatmapSet(Stream fileStream, ProgressContext context = null)
{
Beatmaps = new List<ExtendedBeatmap>();
_fileStream = fileStream;
Parse(context);
}
public BeatmapSet(string path, ProgressContext? context = null) : this(File.OpenRead(path), context)
{
}

public BeatmapSet(string path, ProgressContext context = null) : this(File.OpenRead(path), context)
{
}
public List<ExtendedBeatmap> Beatmaps { get; }

public IParsable Parse(ProgressContext context = null)
public byte[] Serialize(ProgressContext? context = null)
{
Logging.Log("[BeatmapSet] Serializing...", LogLevel.Debug);
using (var memstream = new MemoryStream())
{
try
using (var writer = new BinaryWriter(memstream))
{
using (ZipArchive archive = ZipArchive.Open(_fileStream))
var task = Program.Verbose ? context?.AddTask("Serializing beatmapset") : null;
task?.MaxValue(Beatmaps.Count);
foreach (var beatmap in Beatmaps)
{
var task = Program.Verbose
? context?.AddTask("Importing beatmapset (" + archive.Entries.Count + ")")
: null;
task?.MaxValue(archive.Entries.Count);
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.Key.EndsWith(".osu"))
{
Logging.Log("[Beatmapset] Detected " + entry.Key, LogLevel.Debug);
MemoryStream memstream = new MemoryStream();
entry.OpenEntryStream().CopyTo(memstream);
Beatmaps.Add(ExtendedBeatmapDecoder.Decode(memstream));
memstream.Dispose();
}
task?.Increment(1);
}
writer.Write(beatmap.Serialize());
task?.Increment(1);
}

return this;
}
catch (Exception e)
{
Logging.Log("An unknown error occured while parsing a beatmapset:", LogLevel.Error);
AnsiConsole.WriteException(e);
return this;
}
}

public IParsable Parse(Stream stream, ProgressContext context = null)
{
_fileStream = stream;
return Parse(context);
return memstream.ToArray();
}
}

public byte[] Serialize(ProgressContext context = null)
public byte[] SerializeOSDB(ProgressContext? context = null)
{
Logging.Log("[BeatmapSet] Serializing...", LogLevel.Debug);
using (var memstream = new MemoryStream())
{
Logging.Log("[BeatmapSet] Serializing...", LogLevel.Debug);
using (MemoryStream memstream = new MemoryStream())
using (var writer = new BinaryWriter(memstream))
{
using (BinaryWriter writer = new BinaryWriter(memstream))
var task = Program.Verbose ? context?.AddTask("Serializing beatmapset") : null;
task?.MaxValue(Beatmaps.Count);
foreach (var beatmap in Beatmaps)
{
var task = Program.Verbose ? context?.AddTask("Serializing beatmapset") : null;
task?.MaxValue(Beatmaps.Count);
foreach (ExtendedBeatmap beatmap in Beatmaps)
{
writer.Write(beatmap.Serialize());
task?.Increment(1);
}
writer.Write(beatmap.SerializeOSDB());
task?.Increment(1);
}

return memstream.ToArray();
}

return memstream.ToArray();
}
}

public byte[] SerializeOSDB(ProgressContext context = null)
public IParsable Parse(ProgressContext? context = null)
{
try
{
Logging.Log("[BeatmapSet] Serializing...", LogLevel.Debug);
using (MemoryStream memstream = new MemoryStream())
using (var archive = ZipArchive.Open(_fileStream))
{
using (BinaryWriter writer = new BinaryWriter(memstream))
var task = Program.Verbose
? context?.AddTask("Importing beatmapset (" + archive.Entries.Count + ")")
: null;
task?.MaxValue(archive.Entries.Count);
foreach (var entry in archive.Entries)
{
var task = Program.Verbose ? context?.AddTask("Serializing beatmapset") : null;
task?.MaxValue(Beatmaps.Count);
foreach (ExtendedBeatmap beatmap in Beatmaps)
if (entry.Key.EndsWith(".osu"))
{
writer.Write(beatmap.SerializeOSDB());
task?.Increment(1);
Logging.Log("[Beatmapset] Detected " + entry.Key, LogLevel.Debug);
var memstream = new MemoryStream();
entry.OpenEntryStream().CopyTo(memstream);
Beatmaps.Add(ExtendedBeatmapDecoder.Decode(memstream));
memstream.Dispose();
}
}

return memstream.ToArray();
task?.Increment(1);
}
}

return this;
}
catch (Exception e)
{
Logging.Log("An unknown error occured while parsing a beatmapset:", LogLevel.Error);
AnsiConsole.WriteException(e);
return this;
}
}

public IParsable Parse(Stream stream, ProgressContext? context = null)
{
_fileStream = stream;
return Parse(context);
}
}
83 changes: 40 additions & 43 deletions OsuPackImporter/Beatmaps/LibExtensions/ExtendedBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,54 @@
using OsuParsers.Beatmaps;
using Spectre.Console;

namespace OsuPackImporter.Beatmaps.LibExtensions
namespace OsuPackImporter.Beatmaps.LibExtensions;

public class ExtendedBeatmap : Beatmap, IOSDBSerializable
{
public class ExtendedBeatmap : Beatmap, IOSDBSerializable
public ExtendedBeatmap(Beatmap beatmap)
{
public byte[] Hash { get; set; }
Version = beatmap.Version;
GeneralSection = beatmap.GeneralSection;
EditorSection = beatmap.EditorSection;
MetadataSection = beatmap.MetadataSection;
EventsSection = beatmap.EventsSection;
ColoursSection = beatmap.ColoursSection;
}

public ExtendedBeatmap(Beatmap beatmap)
{
Version = beatmap.Version;
GeneralSection = beatmap.GeneralSection;
EditorSection = beatmap.EditorSection;
MetadataSection = beatmap.MetadataSection;
EventsSection = beatmap.EventsSection;
ColoursSection = beatmap.ColoursSection;
}
public byte[]? Hash { get; set; }

public byte[] Serialize(ProgressContext context = null)
{
Logging.Log(
$"[ExtendedBeatmap] Serializing beatmap {MetadataSection.ArtistUnicode} - {MetadataSection.TitleUnicode} [{MetadataSection.Version}]...",
LogLevel.Debug);
using (MD5 md5 = MD5.Create())
{
return md5.ComputeHash(Hash);
}
}
public byte[] Serialize(ProgressContext? context = null)
{
Logging.Log(
$"[ExtendedBeatmap] Serializing beatmap {MetadataSection.ArtistUnicode} - {MetadataSection.TitleUnicode} [{MetadataSection.Version}]...",
LogLevel.Debug);
using var md5 = MD5.Create();
return md5.ComputeHash(Hash!);
}

public byte[] SerializeOSDB(ProgressContext context = null)
{
// https://gist.github.com/ItsShamed/c3c6c83903653d72d1f499d7059fe185#beatmap-format
public byte[] SerializeOSDB(ProgressContext? context = null)
{
// https://gist.github.com/ItsShamed/c3c6c83903653d72d1f499d7059fe185#beatmap-format

Logging.Log(
$"[ExtendedBeatmap] Serializing beatmap {MetadataSection.ArtistUnicode} - {MetadataSection.TitleUnicode} [{MetadataSection.Version}]...",
LogLevel.Debug);
using (MemoryStream memstream = new MemoryStream())
Logging.Log(
$"[ExtendedBeatmap] Serializing beatmap {MetadataSection.ArtistUnicode} - {MetadataSection.TitleUnicode} [{MetadataSection.Version}]...",
LogLevel.Debug);
using (var memstream = new MemoryStream())
{
using (var writer = new BinaryWriter(memstream))
{
using (BinaryWriter writer = new BinaryWriter(memstream))
{
writer.Write(MetadataSection.BeatmapID);
writer.Write(MetadataSection.BeatmapSetID);
writer.Write(MetadataSection.Artist);
writer.Write(MetadataSection.Title);
writer.Write(MetadataSection.Version);
writer.Write(BitConverter.ToString(Hash).Replace("-", String.Empty).ToLowerInvariant());
writer.Write("");
writer.Write((byte) GeneralSection.ModeId);
writer.Write((double) DifficultySection.OverallDifficulty);
}

return memstream.ToArray();
writer.Write(MetadataSection.BeatmapID);
writer.Write(MetadataSection.BeatmapSetID);
writer.Write(MetadataSection.Artist);
writer.Write(MetadataSection.Title);
writer.Write(MetadataSection.Version);
writer.Write(BitConverter.ToString(Hash!).Replace("-", string.Empty).ToLowerInvariant());
writer.Write("");
writer.Write((byte) GeneralSection.ModeId);
writer.Write((double) DifficultySection.OverallDifficulty);
}

return memstream.ToArray();
}
}
}
Loading

0 comments on commit 38656b0

Please sign in to comment.