• R/O
  • SSH
  • HTTPS

freetrain: Commit


Commit MetaInfo

Revision107 (tree)
Zeit2013-10-27 17:26:38
Autorc477

Log Message

modify GraphicManager to load through IFileSource.
refactoring ImageRef and IFileSource.

Ändern Zusammenfassung

Diff

--- NeoFT/xna/NFT.XNA/XnaGraphicManager.cs (revision 106)
+++ NeoFT/xna/NFT.XNA/XnaGraphicManager.cs (revision 107)
@@ -49,33 +49,33 @@
4949
5050 #endregion
5151
52- public IImageSrc LoadImageFromFile(ResourceKey rkey, string path, SysColor colorkey)
52+ public IImageSrc LoadImageFromFile(ResourceKey rkey, IFileSource file, SysColor colorkey)
5353 {
54- DateTime time_org = File.GetCreationTime(path);
54+ DateTime time_org = DateTime.FromFileTime(file.Timestamp);
5555 if (!SysColor.Transparent.Equals(colorkey))
5656 {
57- return LoadCovertedImageFile(rkey.DataDirectory, path, colorkey);
57+ return LoadCovertedImageFile(rkey.DataDirectory, file, colorkey);
5858 }
5959 else
6060 {
6161 // Assume GIF or PNG with transparent background.
62- return new XnaImageSource(path);
62+ return new XnaImageSource(file);
6363 }
6464 }
6565
66- public IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, string path) {
67- string ext = Path.GetExtension(path);
66+ public IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, IFileSource file) {
67+ string ext = Path.GetExtension(file.Uri);
6868 if (ext.ToLower().Equals(".bmp")) {
69- return LoadCovertedImageFile(rkey.DataDirectory, path, SysColor.Transparent);
69+ return LoadCovertedImageFile(rkey.DataDirectory, file, SysColor.Transparent);
7070 } else {
7171 // Assume GIF or PNG with transparent background.
72- return new XnaImageSource(path);
72+ return new XnaImageSource(file);
7373 }
7474 }
7575
76- private IImageSrc LoadCovertedImageFile(string data_subdir, string path, SysColor colorkey) {
77- DateTime time_org = File.GetCreationTime(path);
78- string savefile = Path.GetFileName(path) + ".png";
76+ private IImageSrc LoadCovertedImageFile(string data_subdir, IFileSource file, SysColor colorkey) {
77+ DateTime time_org = DateTime.FromFileTime(file.Timestamp);
78+ string savefile = Path.GetFileName(file.Uri) + ".png";
7979 savefile = Path.Combine(data_subdir, savefile);
8080 bool create = true;
8181 // Create png if not exist or older than original.
@@ -85,9 +85,9 @@
8585 create = false;
8686 }
8787 if (create) {
88- TextureLoader.SaveAsPng(path, colorkey, savefile);
88+ TextureLoader.SaveAsPng(file, colorkey, savefile);
8989 }
90- return new XnaImageSource(savefile);
90+ return new XnaImageSource(new LocalFile(savefile));
9191 }
9292
9393 /// <summary>
--- NeoFT/xna/NFT.XNA/TextureLoader.cs (revision 106)
+++ NeoFT/xna/NFT.XNA/TextureLoader.cs (revision 107)
@@ -6,6 +6,7 @@
66 {
77 using SysColor = System.Drawing.Color;
88 using XnaColor = Microsoft.Xna.Framework.Color;
9+ using nft.framework;
910
1011 /// <summary>
1112 /// Based on http://jakepoz.com/jake_poznanski__background_load_xna.html
@@ -88,12 +89,12 @@
8889 /// <summary>
8990 /// Convert image to PNG, applying 'color key' to make transparent.
9091 /// </summary>
91- /// <param name="path_orignalimg"></param>
92+ /// <param name="orignalImg"></param>
9293 /// <param name="colorkey"></param>
9394 /// <param name="savefile"></param>
94- public static void SaveAsPng(string path_orignalimg, SysColor colorkey, string savefile)
95+ public static void SaveAsPng(IFileSource orignalImg, SysColor colorkey, string savefile)
9596 {
96- using (Stream fileStream = File.OpenRead(path_orignalimg))
97+ using (Stream fileStream = orignalImg.OpenRead())
9798 {
9899 ToPngAndTexture(fileStream, colorkey, savefile, null);
99100 }
--- NeoFT/xna/NFT.XNA/XnaTexture.cs (revision 106)
+++ NeoFT/xna/NFT.XNA/XnaTexture.cs (revision 107)
@@ -9,6 +9,7 @@
99 using SysRect = System.Drawing.Rectangle;
1010 using XnaColor = Microsoft.Xna.Framework.Color;
1111 using System.Drawing;
12+using nft.framework;
1213
1314 namespace nft.xna
1415 {
@@ -15,12 +16,12 @@
1516 public class XnaImageSource : IImageSrc
1617 {
1718 Texture2D texture;
18- public readonly string FilePath;
19+ public readonly IFileSource File;
1920 int refcount;
2021
21- public XnaImageSource(string file_path)
22+ public XnaImageSource(IFileSource file)
2223 {
23- this.FilePath = file_path;
24+ this.File = file;
2425 }
2526
2627 /// <summary>
@@ -31,7 +32,7 @@
3132 if (Interlocked.Increment(ref refcount) == 1)
3233 {
3334 // First reference;
34- using (Stream stream = File.OpenRead(FilePath))
35+ using (Stream stream = File.OpenRead())
3536 {
3637 texture = Texture2D.FromStream(XnaGraphicManager.GraphicsDevice, stream);
3738 }
--- NeoFT/core/contributions/graphics/CtbImageResource.cs (revision 106)
+++ NeoFT/core/contributions/graphics/CtbImageResource.cs (revision 107)
@@ -14,11 +14,11 @@
1414 {
1515 public class CtbImageResource : Contribution
1616 {
17- protected IImageSrc source;
1817 protected WeakReference reffer;
1918 protected Color colorkey;
2019 protected bool auto_color_key;
2120 protected string src_text;
21+ protected IFileSource file;
2222
2323 public CtbImageResource(Plugin owner, ParamsReader contrib) :base(owner, contrib)
2424 {
@@ -25,6 +25,7 @@
2525 reffer = null;
2626 ParamsReader nd = contrib["src"];
2727 src_text = nd.InnerText;
28+ file = contrib.GetFileSource(src_text);
2829 ParamsReader ckey = nd["colorkey"];
2930 auto_color_key = ckey.IsNull;
3031 if (auto_color_key)
@@ -44,9 +45,9 @@
4445 get { return src_text; }
4546 }
4647
47- public string FilePath
48+ public IFileSource File
4849 {
49- get{ return Path.Combine(PluginDir, SrcText); }
50+ get{ return file; }
5051 }
5152
5253 public IImageSrc ImageSrc
@@ -61,9 +62,9 @@
6162 IImageSrc img;
6263 if (auto_color_key) {
6364 // use left-bottom pixel as color-key
64- img = GraphicManagerEx.GraphicManager.LoadImageFromFileWithDefaultColorKey(key, FilePath);
65+ img = GraphicManagerEx.GraphicManager.LoadImageFromFileWithDefaultColorKey(key, File);
6566 } else {
66- img = GraphicManagerEx.GraphicManager.LoadImageFromFile(key, FilePath, colorkey);
67+ img = GraphicManagerEx.GraphicManager.LoadImageFromFile(key, File, colorkey);
6768 }
6869 reffer = new WeakReference(img);
6970 return img;
--- NeoFT/core/core/GraphicManagerEx.cs (revision 106)
+++ NeoFT/core/core/GraphicManagerEx.cs (revision 107)
@@ -35,12 +35,12 @@
3535 }
3636
3737 #region IGraphicManager implementation
38- public IImageSrc LoadImageFromFile(ResourceKey rkey, string path, SysColor colorkey) {
39- return entity.LoadImageFromFile(rkey, path, colorkey);
38+ public IImageSrc LoadImageFromFile(ResourceKey rkey, IFileSource file, SysColor colorkey) {
39+ return entity.LoadImageFromFile(rkey, file, colorkey);
4040 }
4141
42- public IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, string path) {
43- return entity.LoadImageFromFileWithDefaultColorKey(rkey, path);
42+ public IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, IFileSource file) {
43+ return entity.LoadImageFromFileWithDefaultColorKey(rkey, file);
4444 }
4545
4646 public ITexture CreateStaticTexture(ResourceKey rkey, IImageSrc src, Rectangle region) {
--- NeoFT/framework/contributions/ui/CtbCommandUIGroup.cs (revision 106)
+++ NeoFT/framework/contributions/ui/CtbCommandUIGroup.cs (revision 107)
@@ -31,7 +31,7 @@
3131 string lcap = e["long-caption"].InnerTextOr(cap);
3232 string desc = e["description"].InnerTextOr(lcap);
3333 string iconpath = e["icon"].InnerTextOr(cap);
34- ImageRef imgref = PluginImageManager.GetBundledImageRef(this, iconpath);
34+ ImageRef imgref = PluginImageManager.GetBundledImageRef(this, e, iconpath);
3535 }
3636
3737 }
--- NeoFT/framework/contributions/ui/CtbToolButton.cs (revision 106)
+++ NeoFT/framework/contributions/ui/CtbToolButton.cs (revision 107)
@@ -48,7 +48,7 @@
4848 protected CommandUI parseButton(ParamsReader item)
4949 {
5050 string _img = item["image"].InnerText.Trim();
51- ImageRef iref = PluginImageManager.GetBundledImageRef(this, _img);
51+ ImageRef iref = PluginImageManager.GetBundledImageRef(this, item,_img);
5252 string _cap = item["caption"].InnerTextOr("").Trim();
5353 TriggerCommandUI cui = new TriggerCommandUI(_cap, item.InnerText, iref);
5454 ParamsReader aidx = item["index"];
--- NeoFT/framework/framework/drawing/ImageRef.cs (revision 106)
+++ NeoFT/framework/framework/drawing/ImageRef.cs (revision 107)
@@ -23,7 +23,7 @@
2323 protected IFileSource source;
2424
2525 protected ImageRef(IFileSource src)
26- : this(src, Lifetime.Long) {
26+ : this(src, Lifetime.Short) {
2727 }
2828
2929 protected ImageRef(IFileSource src, Lifetime lifetime) {
@@ -179,13 +179,14 @@
179179 /// <param name="filename"></param>
180180 /// <returns></returns>
181181 public static ImageRef FromFile(string filename) {
182- FileInfo info = new FileInfo(new Uri(filename).LocalPath);
183- string keypath = info.FullName;
182+ Uri uri = new Uri(filename);
183+ FileInfo info = new FileInfo(uri.LocalPath);
184+ string keypath = uri.AbsolutePath;
184185 ImageRef refObj = null;
185186 if (!pathlist.TryGetValue(keypath, out refObj)) {
186187 if (info.Exists) {
187188 IFileSource src = new LocalFile(info.FullName);
188- refObj = new ImageRef(src);
189+ refObj = new ImageRef(src, Lifetime.Short);
189190 pathlist.Add(keypath, refObj);
190191 } else {
191192 Debug.WriteLine("Image file not found for path="+info.FullName);
@@ -194,6 +195,23 @@
194195 return refObj;
195196 }
196197
198+ /// <summary>
199+ /// Get or create ImageRef object for an image from FileSource object.
200+ /// Caller do not need to call first 'IncreaseRefCount'
201+ /// </summary>
202+ /// <param name="source"></param>
203+ /// <returns></returns>
204+ public static ImageRef FromFile(IFileSource source) {
205+ string keypath = source.Uri;
206+ ImageRef refObj = null;
207+ if (!pathlist.TryGetValue(keypath, out refObj)) {
208+ Lifetime lt = source.AccessSpeed == FileAccessSpeed.VerySlow ? Lifetime.Permanent : Lifetime.Long;
209+ refObj = new ImageRef(source, lt);
210+ pathlist.Add(keypath, refObj);
211+ }
212+ return refObj;
213+ }
214+
197215 public static void FreeIsolatedImages() {
198216 List<string> work = new List<string>();
199217 foreach (string key in pathlist.Keys) {
--- NeoFT/framework/framework/drawing/IGraphicManager.cs (revision 106)
+++ NeoFT/framework/framework/drawing/IGraphicManager.cs (revision 107)
@@ -27,10 +27,10 @@
2727 /// 'data_subdir' is recommended to contains plugin-ID so that it should not be affected by other plugins.
2828 /// </summary>
2929 /// <param name="data_subdir">may used to store some cached data.</param>
30- /// <param name="path">file path for the local image.</param>
30+ /// <param name="file">file source of an image.</param>
3131 /// <param name="colorkey">specifies transparent color. (use 'Color.Transparent' for transparent GIF/PNG)</param>
3232 /// <returns></returns>
33- IImageSrc LoadImageFromFile(ResourceKey rkey, string path, Color colorkey);
33+ IImageSrc LoadImageFromFile(ResourceKey rkey, IFileSource file, Color colorkey);
3434
3535 /// <summary>
3636 /// Create a IImageSrc based on specified image file(BMP/GIF/PNG).
@@ -40,9 +40,9 @@
4040 /// for GIF/PNG original transpalency is accepted.
4141 /// </summary>
4242 /// <param name="data_subdir">may used to store some cached data.</param>
43- /// <param name="path">file path for the local image.</param>
43+ /// <param name="file">file source of an image.</param>
4444 /// <returns></returns>
45- IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, string path);
45+ IImageSrc LoadImageFromFileWithDefaultColorKey(ResourceKey rkey, IFileSource file);
4646
4747 /// <summary>
4848 /// Creates a primitive ITexture instance from specified region of image.
--- NeoFT/framework/framework/plugin/Contribution.cs (revision 106)
+++ NeoFT/framework/framework/plugin/Contribution.cs (revision 107)
@@ -200,7 +200,7 @@
200200 ///
201201 /// This poinst to the plug-in directory.
202202 /// </summary>
203- public string PluginDir { get { return parent.dirName; } }
203+ public string PluginPath { get { return parent.PathName; } }
204204
205205 /// <summary>
206206 /// Returns the Plugin object that contains this contribution.
--- NeoFT/framework/framework/plugin/PluginSerializationBinder.cs (revision 106)
+++ NeoFT/framework/framework/plugin/PluginSerializationBinder.cs (revision 107)
@@ -56,7 +56,7 @@
5656 if (lfile != null) {
5757 // load assumig from local strage.
5858 a = Assembly.LoadFrom(lfile.AbsolutePath);
59- } else if (!asmcache.TryGetValue(f.IdenticalPath, out a)) {
59+ } else if (!asmcache.TryGetValue(f.Uri, out a)) {
6060 // load from byte stream.
6161 using (Stream stream = f.OpenRead()) {
6262 byte[] dllimage = new byte[stream.Length];
@@ -64,7 +64,7 @@
6464 stream.Close();
6565 a = Assembly.Load(dllimage);
6666 }
67- asmcache.Add(f.IdenticalPath, a);
67+ asmcache.Add(f.Uri, a);
6868 }
6969 return a;
7070 }
--- NeoFT/framework/framework/plugin/PluginManager.cs (revision 106)
+++ NeoFT/framework/framework/plugin/PluginManager.cs (revision 107)
@@ -137,7 +137,7 @@
137137 // maybe same subdir name in different plugin dirs.
138138 throw new Exception( string.Format(
139139 "プラグイン「{0}」は{1}と{2}の二箇所からロードされています",
140- p.ID, p.dirName, ((Plugin)pluginMap[p.ID]).dirName) );
140+ p.ID, p.Uri, ((Plugin)pluginMap[p.ID]).Uri) );
141141 }
142142 pluginMap.Add( p.ID, p );
143143 }
--- NeoFT/framework/framework/plugin/PluginImageManager.cs (revision 106)
+++ NeoFT/framework/framework/plugin/PluginImageManager.cs (revision 107)
@@ -9,23 +9,19 @@
99
1010 namespace nft.framework.plugin {
1111 class PluginImageManager {
12- static private readonly Dictionary<String, ImageEntry> pathlist
13- = new Dictionary<String, ImageEntry>();
14-
1512 /// <summary>
1613 /// load image from the plugin directory.
1714 /// </summary>
18- /// <param name="ctb">used to specify the owner plugin</param>
15+ /// <param name="pr">used to specify the owner plugin</param>
1916 /// <param name="relativePath">relative path for image, under the plugin dir</param>
2017 /// <returns></returns>
21- public static ImageRef GetBundledImageRef(Contribution ctb, string relativePath) {
22- string key = MakePluginPath(ctb, relativePath);
23- ImageEntry ir;
24- if (!pathlist.TryGetValue(key, out ir)) {
25- ir = new ImageEntry(ctb, relativePath, false);
26- pathlist.Add(key, ir);
18+ public static ImageRef GetBundledImageRef(Contribution ctb, ParamsReader pr, string relativePath) {
19+ IFileSource src = pr.GetFileSource(relativePath);
20+ if (src == null) {
21+ Debug.WriteLine("Bundle image not found for path="+relativePath);
22+ return null;
2723 }
28- return ImageRef.FromFile(ir.FullPath);
24+ return ImageRef.FromFile(src);
2925 }
3026
3127 /// <summary>
@@ -35,68 +31,10 @@
3531 /// <param name="ctb">used to specify the data directroy</param>
3632 /// <param name="relativePath">relative path for image, under the contribution data dir</param>
3733 /// <returns></returns>
34+ [Obsolete]
3835 public static ImageRef GetCachedImageRef(Contribution ctb, string relativePath) {
39- string key = MakeCtbCachePath(ctb, relativePath);
40- ImageEntry ir;
41- if (!pathlist.TryGetValue(key, out ir)) {
42- ir = new ImageEntry(ctb, relativePath, true);
43- pathlist.Add(key, ir);
44- }
45- return ImageRef.FromFile(ir.FullPath);
36+ string path = Path.Combine(ctb.DataDirectory, relativePath);
37+ return ImageRef.FromFile(path);
4638 }
47-
48- protected internal static string MakePluginPath(Contribution ctb, string relative) {
49- return Path.Combine(ctb.PluginDir, relative);
50- }
51-
52- protected internal static string MakeCtbCachePath(Contribution ctb, string relative) {
53- return Path.Combine(ctb.DataDirectory, relative);
54- }
5539 }
56-
57- class ImageEntry : ISerializable {
58- protected readonly string cid;
59- protected readonly string relPath;
60- protected readonly string parentDir;
61-
62- internal protected static string ResolveParentDir(Contribution ctb, bool cached) {
63- if (cached) {
64- return ctb.DataDirectory;
65- } else {
66- return ctb.PluginDir;
67- }
68- }
69-
70- internal ImageEntry(Contribution ctb, string relativepath, bool cached) {
71- this.cid = ctb.ID;
72- this.relPath = relativepath;
73- this.parentDir = ResolveParentDir(ctb, cached);
74- }
75-
76- private ImageEntry(SerializationInfo info, StreamingContext context) {
77- this.cid = info.GetString("cid");
78- this.relPath = info.GetString("path");
79- Contribution ctb = PluginManager.theInstance.GetContribution(cid);
80- bool cached = info.GetBoolean("cached");
81- this.parentDir = ResolveParentDir(ctb, cached);
82- }
83-
84- internal protected string FullPath {
85- get { return Path.Combine(parentDir, relPath); }
86- }
87-
88- #region ISerializable メンバ
89-
90- public void GetObjectData(SerializationInfo info, StreamingContext context) {
91- info.SetType(this.GetType());
92- info.AddValue("cid",cid);
93- info.AddValue("path", relPath);
94- Contribution ctb = PluginManager.theInstance.GetContribution(cid);
95- Boolean cached = !(ctb.PluginDir.Equals(parentDir));
96- info.AddValue("cached", cached);
97- }
98-
99- #endregion
100-
101- }
10240 }
--- NeoFT/framework/framework/plugin/Plugin.cs (revision 106)
+++ NeoFT/framework/framework/plugin/Plugin.cs (revision 107)
@@ -49,11 +49,6 @@
4949 public readonly Uri Uri;
5050
5151 /// <summary>
52- /// Base directory of this plug-in
53- /// </summary>
54- public readonly string dirName;
55-
56- /// <summary>
5752 /// All the contributions in this plug-in
5853 /// </summary>
5954 public readonly IList Contributions = new ArrayList();
@@ -63,15 +58,7 @@
6358 /// </summary>
6459 public readonly IList Primitives = new ArrayList();
6560
66- //public int TotalContribCount { get { return Contributions.Count + Primitives.Count; } }
67-
6861 /// <summary>
69- /// Contents of plugin.xml
70- /// Available only during the initialization phase.
71- /// </summary>
72- private XmlDocument doc;
73-
74- /// <summary>
7562 /// ParamsReader is given from PluginManager and will set null after loading complete.
7663 /// </summary>
7764 internal protected ParamsReader _reader;
@@ -135,24 +122,6 @@
135122 #endregion
136123
137124 /// <summary>
138- /// Loads a plug-in from manifest XML "plugin.xml".
139- /// dirName does NOT contains the file name "plugin.xml".
140- /// </summary>
141- [Obsolete]
142- public Plugin(string dirName) {
143- this.Uri = new Uri(dirName);
144- this.dirName = dirName;
145- _id = Path.GetFileName(dirName);
146- _lastModified = lastUpdatedDate(dirName);
147- doc = loadManifest(dirName);
148- XmlElement root = doc.DocumentElement;
149- _title = XmlUtil.SelectSingleNode(root, "title").InnerText;
150- _homepage = XmlUtil.GetSingleNodeText(root, "homepage", "N/A");
151- _author = XmlUtil.GetSingleNodeText(root, "author", "<unknown>");
152-
153- }
154-
155- /// <summary>
156125 /// Loads a plug-in with ParamsReader".
157126 /// directory name of URI is used as identifier.
158127 /// </summary>
@@ -160,7 +129,6 @@
160129 public Plugin(Uri path, DateTime lastModified) {
161130 this.Uri = path;
162131 _lastModified = lastModified;
163- this.dirName = path.LocalPath; //path.AbsolutePath;
164132 _id = Path.GetFileName(path.LocalPath.Replace("/", "\\"));
165133 }
166134
@@ -172,6 +140,15 @@
172140 }
173141
174142 /// <summary>
143+ /// Base directory of this plug-in
144+ /// </summary>
145+ [Obsolete]
146+ public string PathName {
147+ get { return Uri.LocalPath; }
148+ }
149+
150+
151+ /// <summary>
175152 /// Can be used for Cashed data storage of this plug-in.
176153 /// Each plug-in has it's isolated sub-directory under the DataDir.
177154 /// </summary>
@@ -206,24 +183,6 @@
206183 }
207184
208185 /// <summary>
209- /// Loads plugin.xml file from the directory.
210- /// </summary>
211- [Obsolete]
212- private static XmlDocument loadManifest(string dirName) {
213- string path = Path.Combine(dirName, PluginFileName);
214- return XmlUtil.LoadFile(path);
215- }
216-
217- [Obsolete]
218- private static DateTime lastUpdatedDate(string dirName) {
219- string path = Path.Combine(dirName, PluginFileName);
220- FileInfo info = new FileInfo(path);
221- if (!info.Exists)
222- return DateTime.Now;
223- return info.LastWriteTime;
224- }
225-
226- /// <summary>
227186 /// Loads class type contributions from this plug-in
228187 /// </summary>
229188 internal void loadBinaries() {
@@ -327,14 +286,7 @@
327286 string templ = Main.resources["plugin.contrib_load_error"].stringValue;
328287 string _id = pr["id"].InnerTextOr("unknown");
329288 string _name = pr["name"].InnerTextOr("unknown");
330- return string.Format(templ, dirName, _name, _id);
289+ return string.Format(templ, Uri.AbsoluteUri, _name, _id);
331290 }
332-
333- /// <summary>
334- /// Loads a stream from the plug-in directory.
335- /// </summary>
336- public Stream loadStream(string name) {
337- return new FileStream(Path.Combine(dirName, name), FileMode.Open, FileAccess.Read, FileShare.Read);
338- }
339291 }
340292 }
--- NeoFT/framework/framework/FileSource.cs (revision 106)
+++ NeoFT/framework/framework/FileSource.cs (revision 107)
@@ -28,7 +28,7 @@
2828 /// File offset path. Must be identical and consist of
2929 /// characters available for offset path, in oredr to create cache.
3030 /// </summary>
31- string IdenticalPath { get; }
31+ string Uri { get; }
3232
3333 /// <summary>
3434 /// Reffered when cache is latest or not. Negative value will force update cache.
@@ -38,7 +38,7 @@
3838
3939 public abstract class FileSource : IFileSource
4040 {
41- public abstract string IdenticalPath { get; }
41+ public abstract string Uri { get; }
4242
4343 public abstract Stream OpenRead();
4444
@@ -45,7 +45,7 @@
4545 public override bool Equals(object obj) {
4646 IFileSource iref = obj as IFileSource;
4747 if (iref != null) {
48- return IdenticalPath.Equals(iref.IdenticalPath);
48+ return Uri.Equals(iref.Uri);
4949 } else {
5050 return false;
5151 }
@@ -52,7 +52,7 @@
5252 }
5353
5454 public override int GetHashCode() {
55- return IdenticalPath.GetHashCode();
55+ return Uri.GetHashCode();
5656 }
5757
5858 [Obsolete("non blocking method is desired.")]
@@ -80,7 +80,7 @@
8080 protected string fullpath;
8181 public LocalFile(string path) {
8282 this.fullpath = Path.GetFullPath(path);
83- this.idpath = this.fullpath.Replace(":\\", "$\\");
83+ this.idpath = new Uri(fullpath).AbsoluteUri;
8484 }
8585
8686 public LocalFile(string parent_path, string offset_path) {
@@ -101,7 +101,7 @@
101101 get { return AccessSpeed.Fast; }
102102 }
103103
104- public override string IdenticalPath {
104+ public override string Uri {
105105 get { return idpath; }
106106 }
107107
--- NeoFT/framework/ui/mainframe/ToolStripManager.cs (revision 106)
+++ NeoFT/framework/ui/mainframe/ToolStripManager.cs (revision 107)
@@ -52,6 +52,7 @@
5252 if (cui.Icon != null) {
5353 cui.Icon.AddRef();
5454 newitem.Image = GetIconImage(cui);
55+ cui.Icon.ReleaseRef();
5556 }
5657 string mid = pathHint.ID;
5758 ToolStripMenuItem menuhost = FindMenu(pathHint.Parent);
@@ -239,6 +240,7 @@
239240 newitem.ImageTransparentColor = iref.TranspalentColor;
240241 }
241242 newitem.Image = GetIconImage(cui);
243+ iref.ReleaseRef();
242244 }
243245 return newitem;
244246 }
@@ -247,12 +249,10 @@
247249 int idx = cui.IconIndex;
248250 ImageRef iref = cui.Icon;
249251 if (idx == CommandUI.IconIndexUnassinged) {
250- iref.AddRef();
251252 return iref.Image;
252253 } else {
253254 ImageList il;
254255 if (! imglistTable.TryGetValue(iref, out il)) {
255- iref.AddRef();
256256 il = new ImageList();
257257 il.Images.AddStrip(iref.Image);
258258 if (iref.TranspalentColor != ImageRef.Undefined) {
--- NeoFT/framework/ui/command/CommandUI.cs (revision 106)
+++ NeoFT/framework/ui/command/CommandUI.cs (revision 107)
@@ -22,7 +22,7 @@
2222 ParamsReader eico = e["icon"];
2323 if (!eico.IsNull) {
2424 string iconpath = eico.InnerText;
25- this.icon = PluginImageManager.GetBundledImageRef(owner, iconpath);
25+ this.icon = PluginImageManager.GetBundledImageRef(owner, e, iconpath);
2626 ParamsReader xa = eico["index"];
2727 if (!xa.IsNull) {
2828 this.iconIdx = int.Parse(xa.InnerText);
--- NeoFT/TestLauncher/test/SomeTest.cs (revision 106)
+++ NeoFT/TestLauncher/test/SomeTest.cs (revision 107)
@@ -13,8 +13,10 @@
1313 [TestEntry(new object[]{@"C:\test\testsub"})]
1414 [TestEntry(new object[] { "file://c:/test/testsub" })]
1515 [TestEntry(new object[] { "http://test.com/test/testsub2" })]
16- static private string Test1(string path) {
17- string localpath = new Uri(path).LocalPath;
16+ static private string TestUri(string path) {
17+ Uri u = new Uri(path);
18+ Debug.WriteLine("abPath="+u.AbsolutePath);
19+ string localpath = u.LocalPath;
1820 Debug.WriteLine(localpath);
1921 return Path.GetFileName(localpath);
2022 }
@@ -22,7 +24,16 @@
2224 [TestEntry(new object[] { @"C:\test\testsub.xml" })]
2325 [TestEntry(new object[] { "file://c:/test/testsub" })]
2426 [TestEntry(new object[] { "http://test.com/test/testsub2.xml" })]
25- static private string Test2(string path) {
27+ static private string TestPath(string path) {
28+ try {
29+ Debug.WriteLine("FullPath=" + Path.GetFullPath(path));
30+ } catch (Exception e) {
31+ Debug.WriteLine(e.Message);
32+ }
33+ Debug.WriteLine("DirectoryName=" + Path.GetDirectoryName(path));
34+ Debug.WriteLine("PathRoot=" + Path.GetPathRoot(path));
35+ Debug.WriteLine("FileName=" + Path.GetFileName(path));
36+ Debug.WriteLine("Extension=" + Path.GetExtension(path));
2637 return Path.GetFileName(Path.GetDirectoryName(path) + "");
2738 }
2839
--- NeoFT/TestLauncher/test/ParamsReaderTest.cs (revision 106)
+++ NeoFT/TestLauncher/test/ParamsReaderTest.cs (revision 107)
@@ -36,15 +36,15 @@
3636 }
3737 }
3838 IFileSource fs = reader.GetFileSource("test.txt");
39- Debug.WriteLine("file=" + (fs != null ? fs.IdenticalPath : "null"));
39+ Debug.WriteLine("file=" + (fs != null ? fs.Uri : "null"));
4040 fs = reader.GetFileSource("work/test2.txt");
41- Debug.WriteLine("file2=" + (fs != null ? fs.IdenticalPath : "null"));
41+ Debug.WriteLine("file2=" + (fs != null ? fs.Uri : "null"));
4242 fs = reader.GetFileSource(@"/work/test3.txt");
43- Debug.WriteLine("file3=" + (fs != null ? fs.IdenticalPath : "null"));
43+ Debug.WriteLine("file3=" + (fs != null ? fs.Uri : "null"));
4444 fs = reader.GetFileSource(@"work\test4.txt");
45- Debug.WriteLine("file4=" + (fs != null ? fs.IdenticalPath : "null"));
45+ Debug.WriteLine("file4=" + (fs != null ? fs.Uri : "null"));
4646 fs = reader.GetFileSource(@"\work\test5.txt");
47- Debug.WriteLine("file5=" + (fs != null ? fs.IdenticalPath : "null"));
47+ Debug.WriteLine("file5=" + (fs != null ? fs.Uri : "null"));
4848 }
4949
5050 }
Show on old repository browser