• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂65f6e40d206f286362c779283578a8ef746753ca (tree)
時間2022-08-16 00:39:30
作者yoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[MOD] ResourceHelper の実装を CleanAuLait.Prism.WinUI3 からフィードバック

Change Summary

差異

--- a/Core/Resource/ResourceHelper.cs
+++ b/Core/Resource/ResourceHelper.cs
@@ -3,6 +3,7 @@ using System.IO;
33 using System.Reflection;
44 using System.Windows;
55 using System.Windows.Media.Imaging;
6+using Windows.Storage;
67
78 namespace CleanAuLait.Core.Resource
89 {
@@ -12,9 +13,15 @@ namespace CleanAuLait.Core.Resource
1213
1314 public static string LoadTextFromResource(string resourcePathPrefix, string resourceRelativePath, Assembly assembly = null)
1415 {
16+ Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath);
17+
18+ return LoadTextFromUri(resourceUri);
19+ }
20+
21+ private static string LoadTextFromUri(Uri resourceUri)
22+ {
1523 try
1624 {
17- Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath);
1825 var sri = Application.GetResourceStream(resourceUri);
1926
2027 using var sr = new StreamReader(sri.Stream);
@@ -25,23 +32,27 @@ namespace CleanAuLait.Core.Resource
2532 catch (SystemException e)
2633 {
2734 logger.Error(e);
28- throw new ApplicationException($"リソーステキスト {resourcePathPrefix}{resourceRelativePath} の読み込みに失敗しました", e);
35+ throw new ApplicationException($"リソーステキスト {resourceUri} の読み込みに失敗しました", e);
2936 }
3037 }
31-
32- /// <see cref="https://stackoverflow.com/questions/347614/storing-wpf-image-resources"/>
3338 public static BitmapImage LoadBitmapFromResource(string resourcePathPrefix, string resourceRelativePath, Assembly assembly = null)
3439 {
40+ Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath);
41+
42+ return LoadBitmapFromUri(resourceUri);
43+ }
44+
45+ private static BitmapImage LoadBitmapFromUri(Uri resourceUri)
46+ {
3547 try
3648 {
37- Uri resourceUri = CreateResourceUri(assembly, resourcePathPrefix, resourceRelativePath);
38-
49+ /// <see cref="https://stackoverflow.com/questions/347614/storing-wpf-image-resources"/>
3950 return new BitmapImage(resourceUri);
4051 }
4152 catch (SystemException e)
4253 {
4354 logger.Error(e);
44- throw new ApplicationException($"リソース画像 {resourcePathPrefix}{resourceRelativePath} の読み込みに失敗しました", e);
55+ throw new ApplicationException($"リソース画像 {resourceUri} の読み込みに失敗しました", e);
4556 }
4657 }
4758
@@ -52,17 +63,24 @@ namespace CleanAuLait.Core.Resource
5263 assembly = Assembly.GetCallingAssembly();
5364 }
5465
66+ string assemblyName = assembly.GetName().Name;
67+
68+ string resourcePath = CreateResourcePath(resourcePathPrefix, resourceRelativePath);
69+
70+ Uri resourceUri = CreateResourceUri(assemblyName, resourcePath);
71+
72+ return resourceUri;
73+ }
74+
75+ private static string CreateResourcePath(string resourcePathPrefix, string resourceRelativePath)
76+ {
5577 if (resourcePathPrefix[0] == '/')
5678 {
5779 resourcePathPrefix = resourcePathPrefix[1..];
5880 }
5981
60- string assemblyName = assembly.GetName().Name;
6182 string resourcePath = resourcePathPrefix + resourceRelativePath;
62-
63- Uri resourceUri = CreateResourceUri(assemblyName, resourcePath);
64-
65- return resourceUri;
83+ return resourcePath;
6684 }
6785
6886 private static Uri CreateResourceUri(string assemblyName, string resourcePath)