mirror of
https://github.com/ppy/osu
synced 2025-02-12 16:17:16 +00: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;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using System;
|
using System;
|
||||||
@ -68,30 +69,40 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
|
|
||||||
var url = Url;
|
var url = Url;
|
||||||
|
|
||||||
if (url.StartsWith("https://")) url = url.Substring(8);
|
if (url.StartsWith("http://") || url.StartsWith("https://"))
|
||||||
else if (url.StartsWith("http://")) url = url.Substring(7);
|
|
||||||
else content.Action = () => Process.Start(Url);
|
|
||||||
|
|
||||||
if (url.StartsWith("osu.ppy.sh/"))
|
|
||||||
{
|
{
|
||||||
url = url.Substring(11);
|
var osuUrlIndex = url.IndexOf("osu.ppy.sh/");
|
||||||
if (url.StartsWith("s") || url.StartsWith("beatmapsets"))
|
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));
|
content.Action = () => beatmapSetOverlay.ShowBeatmapSet(getIdFromUrl(url));
|
||||||
else if (url.StartsWith("b") || url.StartsWith("beatmaps"))
|
else if (url.StartsWith("b/") || url.StartsWith("beatmaps/"))
|
||||||
content.Action = () => beatmapSetOverlay.ShowBeatmap(getIdFromUrl(url));
|
content.Action = () => beatmapSetOverlay.ShowBeatmap(getIdFromUrl(url));
|
||||||
// else if (url.StartsWith("d")) Maybe later
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
content.Action = () => Process.Start(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIdFromUrl(string url)
|
private int getIdFromUrl(string url)
|
||||||
{
|
{
|
||||||
var lastSlashIndex = url.LastIndexOf('/');
|
var lastSlashIndex = url.LastIndexOf('/');
|
||||||
|
// Remove possible trailing slash
|
||||||
if (lastSlashIndex == url.Length)
|
if (lastSlashIndex == url.Length)
|
||||||
{
|
{
|
||||||
url = url.Substring(url.Length - 1);
|
url = url.Substring(0, url.Length - 1);
|
||||||
lastSlashIndex = url.LastIndexOf('/');
|
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));
|
return int.Parse(url.Substring(lastSlashIndex + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user