mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-29 03:15:51 +02:00
* Switch to .NET Framework 4.7.2 & C# 8.0, update libraries * Add TweetLib.Core project targeting .NET Standard 2.0 * Enable reference nullability checks for TweetLib.Core * Move a bunch of utility classes into TweetLib.Core & refactor * Partially move TweetDuck plugin & update system to TweetLib.Core * Move some constants and CultureInfo setup to TweetLib.Core * Move some configuration classes to TweetLib.Core * Minor refactoring and warning suppression * Add App to TweetLib.Core * Add IAppErrorHandler w/ implementation * Continue moving config, plugin, and update classes to TweetLib.Core * Fix a few nullability checks * Update installers to check for .NET Framework 4.7.2
30 lines
947 B
C#
30 lines
947 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace TweetLib.Core.Utils{
|
|
public static class UrlUtils{
|
|
private const string TwitterTrackingUrl = "t.co";
|
|
|
|
public enum CheckResult{
|
|
Invalid, Tracking, Fine
|
|
}
|
|
|
|
public static CheckResult Check(string url){
|
|
if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri)){
|
|
string scheme = uri.Scheme;
|
|
|
|
if (scheme == Uri.UriSchemeHttps || scheme == Uri.UriSchemeHttp || scheme == Uri.UriSchemeFtp || scheme == Uri.UriSchemeMailto){
|
|
return uri.Host == TwitterTrackingUrl ? CheckResult.Tracking : CheckResult.Fine;
|
|
}
|
|
}
|
|
|
|
return CheckResult.Invalid;
|
|
}
|
|
|
|
public static string? GetFileNameFromUrl(string url){
|
|
string file = Path.GetFileName(new Uri(url).AbsolutePath);
|
|
return string.IsNullOrEmpty(file) ? null : file;
|
|
}
|
|
}
|
|
}
|