mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 00:53:19 +08:00
Merge branch 'master' into android
This commit is contained in:
commit
6c3bdc4bab
@ -163,18 +163,14 @@ namespace osu.Game.Beatmaps
|
|||||||
downloadNotification.Progress = progress;
|
downloadNotification.Progress = progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
request.Success += data =>
|
request.Success += filename =>
|
||||||
{
|
{
|
||||||
downloadNotification.Text = $"Importing {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}";
|
downloadNotification.Text = $"Importing {beatmapSetInfo.Metadata.Artist} - {beatmapSetInfo.Metadata.Title}";
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
BeatmapSetInfo importedBeatmap;
|
|
||||||
|
|
||||||
// This gets scheduled back to the update thread, but we want the import to run in the background.
|
// This gets scheduled back to the update thread, but we want the import to run in the background.
|
||||||
using (var stream = new MemoryStream(data))
|
var importedBeatmap = Import(filename);
|
||||||
using (var archive = new ZipArchiveReader(stream, beatmapSetInfo.ToString()))
|
|
||||||
importedBeatmap = Import(archive);
|
|
||||||
|
|
||||||
downloadNotification.CompletionClickAction = () =>
|
downloadNotification.CompletionClickAction = () =>
|
||||||
{
|
{
|
||||||
|
@ -150,25 +150,9 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
notification.Text = $"Importing ({++current} of {paths.Length})\n{Path.GetFileName(path)}";
|
notification.Text = $"Importing ({++current} of {paths.Length})\n{Path.GetFileName(path)}";
|
||||||
|
|
||||||
TModel import;
|
imported.Add(Import(path));
|
||||||
using (ArchiveReader reader = getReaderFrom(path))
|
|
||||||
imported.Add(import = Import(reader));
|
|
||||||
|
|
||||||
notification.Progress = (float)current / paths.Length;
|
notification.Progress = (float)current / paths.Length;
|
||||||
|
|
||||||
// We may or may not want to delete the file depending on where it is stored.
|
|
||||||
// e.g. reconstructing/repairing database with items from default storage.
|
|
||||||
// Also, not always a single file, i.e. for LegacyFilesystemReader
|
|
||||||
// TODO: Add a check to prevent files from storage to be deleted.
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (import != null && File.Exists(path))
|
|
||||||
File.Delete(path);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.Error(e, $@"Could not delete original file after import ({Path.GetFileName(path)})");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -195,6 +179,34 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Import one <see cref="TModel"/> from the filesystem and delete the file on success.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The archive location on disk.</param>
|
||||||
|
/// <returns>The imported model, if successful.</returns>
|
||||||
|
public TModel Import(string path)
|
||||||
|
{
|
||||||
|
TModel import;
|
||||||
|
using (ArchiveReader reader = getReaderFrom(path))
|
||||||
|
import = Import(reader);
|
||||||
|
|
||||||
|
// We may or may not want to delete the file depending on where it is stored.
|
||||||
|
// e.g. reconstructing/repairing database with items from default storage.
|
||||||
|
// Also, not always a single file, i.e. for LegacyFilesystemReader
|
||||||
|
// TODO: Add a check to prevent files from storage to be deleted.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (import != null && File.Exists(path))
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, $@"Could not delete original file after import ({Path.GetFileName(path)})");
|
||||||
|
}
|
||||||
|
|
||||||
|
return import;
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void PresentCompletedImport(IEnumerable<TModel> imported)
|
protected virtual void PresentCompletedImport(IEnumerable<TModel> imported)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
|
|
||||||
namespace osu.Game.Online.API
|
namespace osu.Game.Online.API
|
||||||
{
|
{
|
||||||
public abstract class APIDownloadRequest : APIRequest
|
public abstract class APIDownloadRequest : APIRequest
|
||||||
{
|
{
|
||||||
|
private string filename;
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
var request = new WebRequest(Uri);
|
var request = new FileWebRequest(filename = Path.GetTempFileName(), Uri);
|
||||||
request.DownloadProgress += request_Progress;
|
request.DownloadProgress += request_Progress;
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
@ -23,11 +26,11 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
private void onSuccess()
|
private void onSuccess()
|
||||||
{
|
{
|
||||||
Success?.Invoke(WebRequest.ResponseData);
|
Success?.Invoke(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event APIProgressHandler Progress;
|
public event APIProgressHandler Progress;
|
||||||
|
|
||||||
public new event APISuccessHandler<byte[]> Success;
|
public new event APISuccessHandler<string> Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,16 +123,6 @@ namespace osu.Game.Screens.Select
|
|||||||
Padding = new MarginPadding { Top = 10, Right = 5 },
|
Padding = new MarginPadding { Top = 10, Right = 5 },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beatmapInfoWedge = new BeatmapInfoWedge
|
|
||||||
{
|
|
||||||
Size = wedged_container_size,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Margin = new MarginPadding
|
|
||||||
{
|
|
||||||
Top = left_area_padding,
|
|
||||||
Right = left_area_padding,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -173,6 +163,16 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
beatmapInfoWedge = new BeatmapInfoWedge
|
||||||
|
{
|
||||||
|
Size = wedged_container_size,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Margin = new MarginPadding
|
||||||
|
{
|
||||||
|
Top = left_area_padding,
|
||||||
|
Right = left_area_padding,
|
||||||
|
},
|
||||||
|
},
|
||||||
new ResetScrollContainer(() => Carousel.ScrollToSelected())
|
new ResetScrollContainer(() => Carousel.ScrollToSelected())
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
Loading…
Reference in New Issue
Block a user