mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 14:12:54 +08:00
Changed URL detection to be more reliable and generally work better
This commit is contained in:
parent
37490c65cc
commit
735dbddd17
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using System;
|
||||
@ -68,30 +69,40 @@ namespace osu.Game.Graphics.Sprites
|
||||
|
||||
var url = Url;
|
||||
|
||||
if (url.StartsWith("https://")) url = url.Substring(8);
|
||||
else if (url.StartsWith("http://")) url = url.Substring(7);
|
||||
else content.Action = () => Process.Start(Url);
|
||||
|
||||
if (url.StartsWith("osu.ppy.sh/"))
|
||||
if (url.StartsWith("http://") || url.StartsWith("https://"))
|
||||
{
|
||||
url = url.Substring(11);
|
||||
if (url.StartsWith("s") || url.StartsWith("beatmapsets"))
|
||||
content.Action = () => beatmapSetOverlay.ShowBeatmapSet(getIdFromUrl(url));
|
||||
else if (url.StartsWith("b") || url.StartsWith("beatmaps"))
|
||||
content.Action = () => beatmapSetOverlay.ShowBeatmap(getIdFromUrl(url));
|
||||
// else if (url.StartsWith("d")) Maybe later
|
||||
var osuUrlIndex = url.IndexOf("osu.ppy.sh/");
|
||||
if (osuUrlIndex == -1)
|
||||
{
|
||||
content.Action = () => Process.Start(url);
|
||||
return;
|
||||
}
|
||||
|
||||
url = url.Substring(osuUrlIndex + 11);
|
||||
if (url.StartsWith("s/") || url.StartsWith("beatmapsets/") || url.StartsWith("d/"))
|
||||
content.Action = () => beatmapSetOverlay.ShowBeatmapSet(getIdFromUrl(url));
|
||||
else if (url.StartsWith("b/") || url.StartsWith("beatmaps/"))
|
||||
content.Action = () => beatmapSetOverlay.ShowBeatmap(getIdFromUrl(url));
|
||||
}
|
||||
else
|
||||
content.Action = () => Process.Start(url);
|
||||
}
|
||||
|
||||
private int getIdFromUrl(string url)
|
||||
{
|
||||
var lastSlashIndex = url.LastIndexOf('/');
|
||||
// Remove possible trailing slash
|
||||
if (lastSlashIndex == url.Length)
|
||||
{
|
||||
url = url.Substring(url.Length - 1);
|
||||
url = url.Substring(0, url.Length - 1);
|
||||
lastSlashIndex = url.LastIndexOf('/');
|
||||
}
|
||||
|
||||
var lastQuestionMarkIndex = url.LastIndexOf('?');
|
||||
// Filter out possible queries like mode specifications (e.g. /b/252238?m=0)
|
||||
if (lastQuestionMarkIndex > lastSlashIndex)
|
||||
url = url.Substring(0, lastQuestionMarkIndex);
|
||||
|
||||
return int.Parse(url.Substring(lastSlashIndex + 1));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user