티스토리 뷰

장난치기

Resources and Satellite Assemblies 2

알 수 없는 사용자 2008. 1. 28. 22:40

Fusion 9 : Resources and Satellite Assemblies 2

??¤?????? ???????³¼ ?????± ??´????¸???? ?·¸ ????²??§¸ ????°? ????²???¤.

??? (?°???´?????? ????????¤??¼ ??????) XML Compiled Resources

?§??¸? ?¹??§???? ????????¤ ?????¨??? ??°????°? ??´???????¼???´??? ??´??? ??¸?????´ ????????¤??¼ ?????¨?????? ?²½??° ( ?????¼??¤??´, ?????? ???????§?, ??¤??´??¼?¡??·¸ ?°???¤ ?????? ?º¡??? ????³´??? ?°????)?? ????????? ????????´??¤. ????§??§? ?????´?½?, ?¹???¸?§??³¼ ?°???? ?°???´?????? ????????¤??¼ ?????¨????³? ??¶??? ?²½??°,
?°???´?????? ????????¤??? ??¸?????´?????? ?????? ?°??????? ?????¤????????? ????³?????§? ????????¤. ?°???´?????? ????????¤??¼ ?????´?????? ?????¤??¸ ??¸?½??????? ????????´ ?°???´?????? ?°???? ?????¤??¸ ?°???¼?¡? ?³??????´??¼ ?????¤.Convert ??´?????¤??? ??? ?°???? ???????????¼ ????³?????????°, ToBase64String?³¼ FromBase64String??´ ?·¸?²???´??¤.

?´??????????(Managed)???? XML????????¤??? ??¼?°??????¼?¡? .resx ?????¼?¡? ?????¤??¸ ?????¤.
(?²°??­, ??´ resx ?????¼ ??´??? ??°?????? ??????????? ?°???´?????? ????????¤??¼ ?????¨??? ??? ?????¼??° ??´??¼ Compiled ????????¤?¡? ??´?????¼ ??? ?????±?????? .resources ?????¼??? ????????¤?¡? ?????¨????¼? ????¡???¸??¤??¼ ??¤????????´ ?????? ?²???´??¤.)

Raw ????????? XML ????????¤(.resx)?? ?????¼ ?????± --> (resgen ??´??? ??´?????´ ??´?????¼) --> ??´?????¼ ??? xml ????????¤ ?????¼(*.resources) -->??¤??? ????¡??·¸??¨??? ????????¤?¡? ?????¨????¼? ??´?????¼

??´ ?????¼??? ResxResourceWriter ??´?????¤??¼ ????????´ ??¸ ??? ?????¼??°,?? ResxResourceREader ??´?????¤??¼ ??´?????´??? .resx ?????¼??? ??°??´??°??¼ ??½??? ??? ?????¤.?? ????§??§? ResxResourceWriter ????´?????¤??¼ ??????????????° ???????¹? ?????¼????¡? ??´????²???¼ ?·¸??? .resx?¡? ??´?????¼????³? ResourceManager?¡? ??½??? ??? ?????¤??´ ??¸??? ?²???´??¤.
Resgen ??´??? .txt ?????? .resx ?????¼??? ????????? ?°??????¤??¼ ??? ?????¼??°, ?????¸?¡­?²???? .resources ?????¼??? ????????? ?°???? ??¤??¼?????? ?????¤. ??´ ?²½??° ??´??? .resources ?????¼??? ?????´?????¼?????? .txt ?????? .resx?????¼?¡? ?²°?³¼??? ?????±?????¤.
Resx ?????¼??? ????²???? ??¤??¤?§???¼ ?°??§??³? ?????¼??° ??´ ??¤??¤?§???¼ ?§???¤?§? ?????¼??´ ??´?????¼??´ ????§? ????????¤. Visual Studio??¼ ???????????´ ????¡??????¸??? ??? ??¼??? ?¶??°???? ??? ?§???¤ ????????¼?¡? .resx ?????¼??? ?????±??´ ?¤???¤. Visual Studio??¼ ??????????§? ?????¼??´ ??°????°? ?§???? resx ?????¼??? ?????±??´??¼?§? ?????¤.

??¡ ????????¼?¡?
.resx ?§???¤?¸°(without Visual Studio)

?·¸?????¤?³? resx?????¼??? ?§??????? ?²???´ ?§¤??° ??´??¤??´ ????????? ????????¤ resgen ??´??? ??´?????´??? .resources ?????¼??? ?????´?????¼ ?????? ????¸° ?????¸??´??¤.
?·¸ ?????± ??¨?³???? ?°???¨?????¤. ?¨¼??? ?¹? ?????¤??¸ ?????¼??? ?????±?????¤. ?·¸????³? ????????¤ ?????¼?¡? ??´?????¼ ?????¤. ?§??§??§???¼?¡? .resx ?????¼?¡? ?????´?????¼ ?????¤.

??¼?°?
raw ????????¤ ?????¼ ?????± --> (resgen ??´??? ??´?????´ ??´?????¼) --> ??´?????¼??? ????????¤ ?????¼(.resources)
--> (resgen ??´??? ??´?????´ resx?¡? ?????´?????¼) --> ?????´?????¼??? raw?? XML ????????¤ ?????¼(.resx)



Resgen test.txt

Resgen?? test.resource?? test.resx


??´????²? ?????´ test.resx ??¼??? ??´?????? XML ?????¼??´ ?????±?????¤. ??´ ?????¼??? ?§¤??° ?¸´ ??¼????³¼ ??¤??¤?§?, ?·¸????³? ?¸°?³¸?°???? ?????¨????³? ?????¤. ??¼?????? ????±°????³?,?? ??¤??¤?§???? ????§????????²? ??³??? ?²???´??¤. ?²°?¡??????¼?¡? ????????? ??´?????? resx ?????¼ ??´??? ?¡´?????´??¼ ?????¤.

<?xml version="1.0" encoding="utf-8"?>
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
?? <resheader name="reader">
?????? <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
?? </resheader>
?? <resheader name="writer">
?????? <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
?? </resheader>
</root>


?§??§??§? ??? ??­?ª???? .resx ?????¼??? ??½?³? ??°?????° ???????????? ??´?????¤??¼ ????????¸??¤. ??? ?¤??????? ?²???? resmimetype ??´??¤. ??´??? ??°??´??°??? ?¸°?³¸?????¸ ????????? ????????´??´ ??? ??????????????? text??¼ ?????¨????³? ????????? ????????¸??¤.(text/microsoft-resx)
????????¤ ?????¼??? ??°??´??°??¼ ?¶??°??????? ?²???? ??½??¤. ?°? <data> ??¸?????? <value> ??¸?????¼ ?????¨?????¤. <data> ??¸?????? name ?????±??? ?°??§???° ?¶??°??????¼?¡? type ?????±??? ?°??§? ?????? ?????¤. <value> ??¸?????? ??´?¶? ?????¤??¸??? ?°???´ ??¤??´?°??²? ?????¤.
?§???¼ mimetype??? ?ª????????§? ?????¼??´ <data> ??¸?????? ?¸°?³¸ resmimetype??´ ???????????° ??´??? ?°???´ ??¤??? ?¤? ????????? ????????´??´??¼ ?????¤??? ?²???? ?????¸?????¤.
String, Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, DateTime, TimeSpan, Decimal
ResourceManager??? type?³¼ value??? ??½?????¤ ?·¸????³? ?·¸ ?°???? ?????´ ????????? ?????±?????¤. ResourceManager.GetObject??¼ ??´?????´????? ??´?????¼??? ????????¤?¡??¶???° ??­?ª???? ?°???¸??? ??? ?????¤. ??´??? ????????¤ ?ª???? ??¸????¡? ????????´??¼ ?????¤.GetObject??? Object?? ?°??²´??¼ ?????´???????¡? ?????¹??? ????????¼?¡? ?³??????´??¼ ?????¤.
?????¼ ??¤??´ ????????? ?????¤??¸??¼ test.resx ?????¼??? ?¶??°??????¤.

??<data name="Data" type="System.Int32,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>42</value>
</data>
</root>

Data ??? 32 ?¹???¸ ????????¼??? ?²???? ????????¸??¤.

??´ ????????¤??¼ ??½??? ?½??????? ?°???¨?????¤.

class App
{
static void Main()
{
Assembly a = Assembly.GetExecutingAssembly();
ResourceManager resources = new ResourceManager("test", a);
object obj = resources.GetObject("Data");
int data = (int)resources.GetObject("Data");
Console.WriteLine("value is {0}", data);
}
}

?·¸????³? .resx??¼ compiled ????????¤?¡? ??´?????¼ ????³?, ????¡???¸??¤ ??´?????¼ , ??¤???
??° ?·¸??¼ ?³´??¤??´ ??´???????¸???!(????³´?¸°??? ?°???´ ??????)

??¡ ?°???´??????
????????¤ ??°??´??° ?¶??°?????¸°

??? ??? ??¸?¸???? ?¸°?³¸ ?????? ??¸??? ????????? ??????????³? ??¶??¤??´, ????????? ?§?????????? ???(BinaryFormatter ?????? SoapFormatter??¼ ??´?????´???) ?·¸ ?²°?³¼??¼ base64?¡? ??¸?½???? ??´??¼ ?????¤.??´????²? ?????? ?°???? ?°???¨??? ?°??²???? ResxResourceWriter??¼ ??´????????? ?²???´??¤.
?????¼ ??¤??´, .cur ?????¼??? ?°??§??³? ????³? ??´ ??¤??? ?????¼??? ??¼??? ??¤????¡? ??´???????³? ??¶??¤?³? ?°?????????¤.
genCursor.cs??¼??? ??´?????? ?½???? ??´???????¼?????????? ?????±????³? ?½??????? ????????? ?°???¤

// First parameter is the name of the icon in the .resx file
// Second parameter is the name of the cursor file
using System; using System.IO;
using System.Resources;
using System.Windows.Forms;
class App
{
static void Main(string[] args)
{
if (args.Length < 2) return;
using (ResXResourceWriter writer
= new ResXResourceWriter(Console.Out))
{
using (FileStream fs = File.OpenRead(args[1]))
{
Cursor cursor = new Cursor(fs);
writer.AddResource(args[0], cursor);
cursor.Dispose();
writer.Generate();
}
}
}
}


??? ?½??????? ResXResourceWriter ??? ?¶??????? ?½?????¡? ????§????(redirect)?????¤. ?·¸?????? ?·¸ ?¶??????? ??¤??? ??¤??? ?????¼?¡? ??°?²°????±°????? ?½?????????? ?·¸??? ?³??????´??? ?????¤.

genCursor Cursor test.cur > test.resx


Test.resx ?????¼??? ??´??´ ????????? ?°???´ ????????¤?°? ?¶??°??????´ ?????¤.

<data name="Cursor" type="System.Windows.Forms.Cursor, System.Windows.Forms" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAACAAEAICAAAA8ADwAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH4AAAGBgAACAEAABDwgAAjDEAARAggAEg
QIACIIxAAkESQAJCIkACREJAAkiCQAIxBEABIgSAAQQIgACMMQAAQ8IAACAEAAAYGAAAB+AAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////////////gf///gB///wAP//4AB//8D
wP/+D8B//h+Af/wfAD/8Pgw//DwcP/w4PD/8MHw//AD4P/4B+H/+A/B//wPA//+AAf//wAP//+AH///4
H/////////////////////////////////8=
</value>
</data>


Mimetype??´ application/x-microsoft.net.object-.bytearray.base64??¼?¡? ??¼??´?§???¤. ??´??? Cursor ?°??²´??¼ ?§???????????????° BinaryFormatter?°? ??????????????¤??? ?????¸??´??¤.

??¡ ?°???´??????
????????¤ ??????????¸°

?²°?³¼ ????????¤ ?????¼(test.resx)??? ??´?????¼ ?????¤.

Resgen test.resx

?????¼ ??´???????¼???´?????? ?????? ?§???¤?³? ????????¤?¡? ?????¨??? ??¤?????¼ ??´??????????¡? ?????¤.

using System;
using System.Resources;
using System.Windows.Forms;
using System.Reflection;
class MainForm : Form
{
MainForm()
{
Assembly a = Assembly.GetExecutingAssembly();
??ResourceManager resources = new ResourceManager("test", a);
?????????? this.Cursor = (Cursor)resources.GetObject("Cursor");
}
static void Main()
{
Application.Run(new MainForm());
}
}


?????¼ ??´???????¼???´??? ??´?????¼
??° ?·¸??¼ ?³´??¤??´ ??´???????¸???!(????³´?¸°??? ?°???´ ??????)
?²°?³¼


??¡ Visual Studio
??¼ ??´?????´ ????????¤ ??????????¸°

?§¤??° ????????´ ?°???¨??´ ?§???¤. ?±°??? ?ª¨??? ????????? Visual Studio?°? ?²??????´ ?¤???¤.
?°???´?????? ?????¼??? ????????¤???(resx ?????¼??? ????????¤?¡? ?¶??°?),?? ????????¤ ?????¼??? ?????? ??´?????¼,?? ????????¤??¼ ??´????¸??????? embed ?????? ?????? ??±

????¡??????¸ ????????? ????????¤ ?????¼ ?¶??°?


?¶??°???? ????????¤ ?????¼(Resource1.resx)??¼ ????????¸ ?ª¨????¡? ??´??´,
??¸?????´/??´??¸?§?/?????´?½?/??? ??±??? ?¹´????³???? ?³? ????????¤??¼ ?????¸??? ??? ?????¤.



??¸?????´ ????????¤ ?????? ?¶??°? : a=1



?°???´?????? ????????¤ ?????? ?¶??°? : ?????¤??? ?????? ?¸°?¡´ ??´??¸?§? ?????¼??? ????????¤?¡? ?¶??°?



??´??¸?§? ?????¼??? ?¶??°??????¼????¡? ??¼?ª½ ?¹´????³??????¼ "??´??¸?§?"?¡? ?³??²½?????´ ?¶??°???? ?????¼??´ ?³´??¸??¤.



????????¤ ??????????¸°

?½??????? ?§¤??° ?°???¨?????¤.
??private void Form1_Load(object sender, EventArgs e)
{
//??¸?????´ ????????¤ ??????
MessageBox.Show(Resource1.a);
//?°???´?????? ????????¤ ??????
this.BackgroundImage = Resource1.KKansoon;
}

??¤???




??¹?³?????²? ????²½ ??°?§? ????????? Visual Studio?°? embedded ????????¤ ???????¡? ??´??¸?§???¼ ??¤??? ??´????¸??????? ?????¨????¼? ?¤???¤.
??? ?³´??´, managed XML ????????¤ ?????¼(resx)??´ ?????¨(embedded)?? ????????¤?¡? ??´????¸??????? ?????¨??¨??? ?????±??¼?¡? ?§????????³? ?????¤.(?¸°?³¸?°?)



??´ ?????¸??? ?³§ Resource1.resx ?????¼ ?????? ?°???´?????? ??°??´??°(base64 ??¸?½??????? ?????¤??¸)?°? ?????¨??? ?²???´?³?, ??´ Resource1.resx?°? ??¤??? ??´????¸????(exe)??? ?????¨??? ?²???´????¡?, ????¡??????¸ ?????? ?¶??°??????´ ?????? ??¤??? ??´??¸?§? ?????¼(?¹????.jpg)??? ??³??´ ??¤??? ??¤??? ??´????¸??????? ?????¨?????? ???????°? ?????¤.
?³§ ??´??¸?§? ?????¼??? Visual Studio?°? ?¹?????³¼?????????,?? Resource1.resx??? ??´?????¼ ?????? Resource1.resources ??¼ ?????±??? ??? ?·¸ ?°???´?????? ??°??´??°??¼ ????³?????¸° ?????´ ??????????¸° ?????? ?²???´??¼ ?§??????´ ?°?????????¤.


???,?? ????????¸ ??????????§? ????????? ????????´??¼???...??¤???????°??????? ???????°? ?????¤???..
??´??¹ ??´??¸?§? ?????¼??? ?¹?????????? ?????±??? ?°???? "??????" ?°???´ ?¸°?³¸??´??¤. (??´?²? ?????¸??? ?§???´ ??·?°???¤ ???????????°???)



??´
??´??¸?§? ?????¼??? "?????¨????????¤"?¡? ?³??²½?????´? ??´??¸ ????????¤ ?????¼??? ?????¨??? ??´??¸?§? ??°??´??°?°? ??¤??? ??°?¡? ??¤??? ??´????¸???? ?????¼?¡? ?????¨???????¡?, ??¸??°?????´ ??¤??? ??´????¸???? ?????´????§? ????°??????¤??? ?²°?³¼??¼ ??³?????¤.
??????????¤?¡? ?????¨??? ??¤??¸ ????????? ?????¼??¤??? ?§??°??°??§? ??¼ ?²???´??¤.


??? ??¤????????¼??? ????????¤?¡?

Visual Studio??¼ ??´?????´??? ??¤??? ?????¼??? ????????¤?¡? ?¶??°??????? ?²???? ?¡°?¸? ????¡??????­??´ ?????¤.(*.cur) ????????¼ ?°¸?¡° ?°????.

http://edndoc.esri.com/arcobjects/9.0/ArcGISDevHelp/DevelopmentEnvs/DotNet/WorkingWithResources.htm

*.cur
??? ????????¤?¡? ?¶??°???? ??? ?·¸??? "?????¼" ???????¡? ?¶??°??????¤. (??¤?????¼??? ?¹´????³???? ??????, ?·¸?????¤?³? ??´??¸?§???? ??????)



?·¸??????
?????? ?²???¼ ??¼??? ??¤??? ?????±??? ?°???´?????? ??°??´??°??¼ ??°?²¨ ?????¼??´ ??????.

this.Cursor = (Cursor)Resouce1.TestCursor;

Visual Studio??¼ ??°?§? ?????? ?°????????¡? resx??¼ ????????¼?¡? ?§???¤??´??? ??´??¹ ??¤??? ?°???´?????? ??°??´??°??¼ ?????´??? ?·¸?±¸ ?¶???? ????¸° ??? ??? ?????¤.
?·¸?????? ????????¼?¡? ????????? resx??¼ ?§???¤??´ ?·¸ ?????? ??¤??? ?°???´????????¼ ?¶??°???? ??¤??? ??´??¹ <data> ??­?ª?(????????¤)??¼ ??´??½?³´????¡? ?³??????????,
Resource1.resx ?????¼ ??´?????? ?§???´ ????????¤.

???)
<data name="TestCursor" type="System.Windows.Forms.Cursor, System.Windows.Forms" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAACAAEAICAAAA8ADwAwAQAAFgAAACgAAAAgAAAAQAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH4AAAGBgAACAEAABDwgAAjDEAARAggAEg
QIACIIxAAkESQAJCIkACREJAAkiCQAIxBEABIgSAAQQIgACMMQAAQ8IAACAEAAAYGAAAB+AAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////////////gf///gB///wAP//4AB//8D
wP/+D8B//h+Af/wfAD/8Pgw//DwcP/w4PD/8MHw//AD4P/4B+H/+A/B//wPA//+AAf//wAP//+AH///4
H/////////////////////////////////8=
</value>
</data>


?·¸??¼ "?¸°??? " ?¹´????³??????? ??­?ª???´ ????¸°??´??? ?????? ?²???¼ ???????????¤.



?·¸??° ??? ???

this.Cursor = (Cursor)Resouce1.TestCursor;


????²? ?????´ ??¤?????? ?°??????¤.?? ?·¸?????? ??? ?²??±°?¡­??¤??? resx??¼ ????????¼?¡? ?§??????? ????????? ??´??¼ ?????????.

?????¤??¸ ????²??§¸ ?°??²???? ????°???? ?????¡?¸°?¡? ????????¸ ?°??²???´??¤. CursorConverter??¼ ??´?????´??? ?????¤. ?·¸??? "?????¼" ?¹´????³?????¡? ??¤??? ?????¼??? ????????¤??? ?¶??°???´ ????³?, ???????²???¼ ????????¤ ?°???´?????? ??°??´??°??¼ ??¤????¡? ?³?????????¤.

??CursorConverter cv = new CursorConverter();
this.Cursor = (Cursor)cv.ConvertFrom(Resource1.Cursor1);


????²??§¸?°? ?¡°?¸? ?°???¨??´ ?³´??¸??¤.. ?°¸?³?) ??? ?????? ?°??²???´ ?¡´?????? ?±°??¼ ?³¸??¤.

??¤?????? ????¹???´