1. コンソールアプリケーションの作成
Visual Studio のプロジェクトの新規作成でコンソールアプリケーションを作成します。
下記3箇所の編集を行います。
(2) 参照設定の追加
(3) アプリケーション構成ファイルの設定
(4) ソースコード
2. 参照設定の追加
WIL 3.1 のアセンブリを参照設定に追加します。
3. アプリケーション構成ファイルの設定
WIL 3.0 のインスタンスを WIL 3.1 の型へキャストする際に例外を発生させないためにバージョンリダイレクトの設定を行います。
▽ app.config:
1 <?
xml version=
"1.0" encoding=
"utf-8" ?>
4 <
supportedRuntime version=
"v4.0" sku=
".NETFramework,Version=v4.5.2" />
7 <
assemblyBinding xmlns=
"urn:schemas-microsoft-com:asm.v1">
9 <
assemblyIdentity name=
"fvalgcli" publicKeyToken=
"20bef69103785603" culture=
"neutral" />
10 <
bindingRedirect oldVersion=
"3.0.0.0" newVersion=
"3.1.0.0"/>
13 <
assemblyIdentity name=
"FVILbasic" publicKeyToken=
"6b92ad76edadb73c" culture=
"neutral" />
14 <
bindingRedirect oldVersion=
"3.0.0.0" newVersion=
"3.1.0.0"/>
17 <
assemblyIdentity name=
"FVILdevice" publicKeyToken=
"46550952301e8a49" culture=
"neutral" />
18 <
bindingRedirect oldVersion=
"3.0.0.0" newVersion=
"3.1.0.0"/>
21 <
assemblyIdentity name=
"FVILforms" publicKeyToken=
"2b3e48e63fd7f1a8" culture=
"neutral" />
22 <
bindingRedirect oldVersion=
"3.0.0.0" newVersion=
"3.1.0.0"/>
4. ソースコード
カレントディレクトリまたは引数に指定されたディレクトリの配下の XML リソースファイル (.resx 拡張子) を探索して、 各リソースファイル内の FVIL.GDI.CFviDisplay のインスタンスを一旦デコードして再度エンコードし直す処理です。
▽ Program.cs:
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Reflection;
8 namespace DisplayConverter
13 static void Main(
string[] args)
15 FVIL._SetUp.InitVisionLibrary();
20 dir = System.IO.Directory.GetCurrentDirectory();
27 var paths =
new List<string>();
32 Console.WriteLine(
"The corresponding file was not found.");
36 ulong file_counter = 0;
37 foreach (var item
in paths)
39 Console.WriteLine(
"{0}", item);
45 case 0: Console.WriteLine(
"File conversion was not done.");
break;
46 case 1: Console.WriteLine(
"One file was converted.");
break;
47 default: Console.WriteLine(
"{0} files were converted.", file_counter);
break;
51 FVIL._SetUp.ExitVisionLibrary();
54 static void Find(
string dir, List<string> paths)
56 if (
string.IsNullOrWhiteSpace(dir))
return;
57 if (System.IO.Directory.Exists(dir) ==
false)
59 Console.WriteLine(
"error: The specified directory is not exist.");
63 var files = System.IO.Directory.GetFiles(dir,
"*.resx");
64 paths.AddRange(files);
66 var dirs = System.IO.Directory.GetDirectories(dir);
67 foreach (var item
in dirs)
73 static bool Convert(
string filename)
76 var tempfile = filename +
".converted";
78 using (var src_resx =
new System.Resources.ResXResourceSet(filename))
79 using (var dst_resx =
new System.Resources.ResXResourceWriter(tempfile))
81 foreach (System.Collections.DictionaryEntry entry in src_resx)
83 if (entry.Value.GetType().FullName ==
"FVIL.GDI.CFviDisplay")
85 dst_resx.AddResource((
string)entry.Key, entry.Value);
91 System.IO.File.Move(filename, filename +
".old");
92 System.IO.File.Move(tempfile, filename);
96 System.IO.File.Delete(tempfile);