This is the first in what I hope is a series of articles on coding for Windows Home Server. In my first article, I'm not coding an Add-In. Instead I'll show you how to load the Windows Home Server Console using any language (or more appropriately stated: Culture) that you desire.
This is of little use for the casual user as the actual console itself (or at least Microsoft's portion) is still in English, but Add-In developers should find this extremely useful. The reason I wrote the loader was that I needed a way to test my twitter Add-In @WHSTweet as I have it translated into German, French and Spanish.
Here is the HP tab of the Windows Home Server Console after I have loaded it in French:
Now let's go through just how we build our project. You can also download the complete Visual Studio 2008 solution and follow along at home. But first a word of caution. Whenever messing around with RDPing into your WHS or messing with files in the Windows Home Server folder, you run the risk of messing something up. You my want to do this on a Virtual Machine instead of a production server. Personally I use my production server with all of my important family photos, but my middle name is "Danger". :)
You've been warned, now let's get started:
- Load Visual Studio 2008 and create a new C# Windows Application named WHSCultureLoader.
- Add a Label with the Text of "Choose a Culture"
- Add a ComboBox and change the DropDownStyle to DropDownList.
- Add a Button with the Text of "Execute".
- Right click on the designer background and select View Code.
- Add the following code to Form1 constructor so that it look as follows. What we are doing here is loading the ComboBox with all known Cultures.
- public Form1()
- {
- InitializeComponent();
- CultureInfo[] ciArray = CultureInfo.GetCultures(CultureTypes.AllCultures);
- foreach (CultureInfo ci in ciArray)
- {
- comboBox1.Items.Add(ci);
- }
- Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
- comboBox1.DisplayMember = "DisplayName";
- comboBox1.SelectedItem = Thread.CurrentThread.CurrentUICulture;
- }
- Next go back to the Designer and double click on the Execute button. This will create an empty the button1_Click function. Add the code as follows:
- private void button1_Click(object sender, EventArgs e)
- {
- Form f;
- CultureInfo ci = comboBox1.SelectedItem as CultureInfo;
- Thread.CurrentThread.CurrentUICulture = ci;
- try
- {
- string path = Path.GetDirectoryName(Application.ExecutablePath);
- Assembly a = Assembly.LoadFile(path+"\\HomeServerConsole.exe");
- f = (Form)a.CreateInstance(a.EntryPoint.ReflectedType.FullName);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- return;
- }
- this.Hide();
- f.KeyPreview = true;
- f.FormClosed += new FormClosedEventHandler(f_FormClosed);
- f.Show();
- }
- In lines 5 and 6 we set the thread's UI culture to the one selected in our listbox.
- Next we load the assembly HomeServerConsole.exe from the same path as WHSCultureLoader.exe executed from.
- In line 12 we create an instance of MainForm, the main form in the Windows Home Server Console.
- In line 20 we hide our selection form.
- In line 22 we specify that the form is to receive key events before they are passed to any controls.
- In line 23 we setup a handler so that when the form closes, we exit the application.
- And finally in line 24, we show the Windows Home Server Console form.
- Here is the code for the close handler.
- void f_FormClosed(object sender, FormClosedEventArgs e)
- {
- Environment.Exit(0);
- }
Now lets test our code. Build the project and copy WHSCultureLoader to the \Program Files\Windows Home Server folder on your WHS. You will need to RDP into your WHS to run this loader. It does NOT run from the client. Launch WHSCultureLoader.exe and you should see our main form.
Change the Culture to something like French (France) and click Execute. If a few moments the Windows Home Server Console will load. If you are running on an HP MediaSmart Server, you should notice two things. One is that the HP tab is not the first/leftmost tab loaded. This is due to the fact that the HomeServerConsole.exe.config file was not loaded. This file instructs HomeServerConsole.exe on tab order. Here is the config file that ships with the HP:
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <appSettings>
- <add key="MediaSmart Server" value="1" />
- </appSettings>
- </configuration>
OK, now that we've gotten completely off track, lets continue. The other thing that you will notice is that any Add-Ins that support French (most notably the HP tab) are actually IN FRENCH! The same goes for German and Spanish or at least that's what HP supports in their standard language pack DLLs that they ship to customers in the United States.
Unfortunately, Microsoft does not ship language DLLs for the Windows Home Server Console itself, so any Microsoft code or Add-In will still be in English (or whatever language that your SKU of Home Server is in).
I hope you have enjoyed my first WHS Coding Series article.
1 comments:
Hi Donavon,
very interesting peace of coding. When you have one moment a little bit free time, please contact me mike_nl @ web . de.
Post a Comment