mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-10 08:34:06 +02:00
Add td:// scheme for modularized resources
This commit is contained in:
parent
901cca268e
commit
7239dcf4d2
@ -32,6 +32,7 @@ static class Program {
|
||||
public static readonly bool IsPortable = File.Exists(Path.Combine(ProgramPath, "makeportable"));
|
||||
|
||||
public static readonly string ScriptPath = Path.Combine(ProgramPath, "scripts");
|
||||
public static readonly string ResourcesPath = Path.Combine(ProgramPath, "resources");
|
||||
public static readonly string PluginPath = Path.Combine(ProgramPath, "plugins");
|
||||
|
||||
public static readonly string StoragePath = IsPortable ? Path.Combine(ProgramPath, "portable", "storage") : GetDataStoragePath();
|
||||
@ -133,8 +134,10 @@ private static void Main() {
|
||||
#endif
|
||||
};
|
||||
|
||||
var resourceScheme = new ResourceSchemeFactory();
|
||||
var pluginScheme = new PluginSchemeFactory();
|
||||
|
||||
settings.SetupCustomScheme(ResourceSchemeFactory.Name, resourceScheme);
|
||||
settings.SetupCustomScheme(PluginSchemeFactory.Name, pluginScheme);
|
||||
|
||||
CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
|
||||
|
@ -50,6 +50,7 @@ let main (argv: string[]) =
|
||||
|
||||
let localesDir = targetDir +/ "locales"
|
||||
let scriptsDir = targetDir +/ "scripts"
|
||||
let resourcesDir = targetDir +/ "resources"
|
||||
let pluginsDir = targetDir +/ "plugins"
|
||||
let importsDir = scriptsDir +/ "imports"
|
||||
|
||||
@ -100,7 +101,7 @@ let main (argv: string[]) =
|
||||
let byPattern path pattern =
|
||||
Directory.EnumerateFiles(path, pattern, SearchOption.AllDirectories) |> Seq.filter (fun (file: string) -> not (file.Contains(importsDir)))
|
||||
|
||||
let exceptEndingWith name =
|
||||
let exceptEndingWith (name: string) =
|
||||
Seq.filter (fun (file: string) -> not (file.EndsWith(name)))
|
||||
|
||||
let iterateFiles (files: string seq) (func: string -> unit) =
|
||||
@ -150,6 +151,7 @@ let main (argv: string[]) =
|
||||
copyFile (projectDir +/ "bld/Resources/LICENSES.txt") (targetDir +/ "LICENSES.txt")
|
||||
|
||||
copyDirectoryContents (projectDir +/ "Resources/Scripts") scriptsDir
|
||||
copyDirectoryContents (projectDir +/ "Resources/Content") resourcesDir
|
||||
|
||||
createDirectory (pluginsDir +/ "official")
|
||||
createDirectory (pluginsDir +/ "user")
|
||||
|
28
Resources/ResourcesSchemeFactory.cs
Normal file
28
Resources/ResourcesSchemeFactory.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using CefSharp;
|
||||
using TweetDuck.Browser.Handling;
|
||||
using TweetLib.Core.Utils;
|
||||
|
||||
namespace TweetDuck.Resources {
|
||||
public class ResourceSchemeFactory : ISchemeHandlerFactory {
|
||||
public const string Name = "td";
|
||||
|
||||
private static readonly string RootPath = Path.Combine(Program.ResourcesPath);
|
||||
private static readonly ResourceProvider ResourceProvider = new ResourceProvider();
|
||||
|
||||
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request) {
|
||||
if (!Uri.TryCreate(request.Url, UriKind.Absolute, out var uri) || uri.Scheme != Name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uri.Authority != "resources") {
|
||||
return null;
|
||||
}
|
||||
|
||||
string filePath = FileUtils.ResolveRelativePathSafely(RootPath, uri.AbsolutePath.TrimStart('/'));
|
||||
return filePath.Length == 0 ? ResourceProvider.Status(HttpStatusCode.Forbidden, "File path has to be relative to the resources root folder.") : ResourceProvider.File(filePath);
|
||||
}
|
||||
}
|
||||
}
|
@ -113,6 +113,7 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Reporter.cs" />
|
||||
<Compile Include="Resources\ResourcesSchemeFactory.cs" />
|
||||
<Compile Include="Resources\ScriptLoader.cs" />
|
||||
<Compile Include="Resources\ScriptLoaderDebug.cs" />
|
||||
<Compile Include="Updates\UpdateCheckClient.cs" />
|
||||
@ -404,6 +405,7 @@
|
||||
rmdir "$(ProjectDir)bin\Release"
|
||||
|
||||
rmdir "$(TargetDir)scripts" /S /Q
|
||||
rmdir "$(TargetDir)resources" /S /Q
|
||||
rmdir "$(TargetDir)plugins" /S /Q
|
||||
|
||||
"$(ProjectDir)bld\post_build.exe" "$(TargetDir)\" "$(ProjectDir)\" "$(ConfigurationName)"
|
||||
|
Loading…
Reference in New Issue
Block a user