public void ParseTests(string data, string expectedCode, LanguageSupportLevel expectedLevel)
        {
            var languageInfo = LanguageInfo.Parse(data);

            Assert.Equal(expectedCode, languageInfo.Code);
            Assert.Equal(expectedLevel, languageInfo.Support);
            Assert.NotNull(languageInfo.Culture);
        }
示例#2
0
        public bool LaunchInstaller(string uri, bool appIsAlreadyRunning, ref List <InternalNotification> queuedNotifications, ref int cultureCodeHash)

        {
            bool languageInstalled = false;

            this.uri = uri;

            this.appIsAlreadyRunning = appIsAlreadyRunning;



            try

            {
                // handle special case where we are resetting the value

                if (uri == "reset")

                {
                    Properties.Settings.Default.CultureCode = "";

                    Properties.Settings.Default.Save();

                    cultureCodeHash = 0;

                    languageInstalled = true;

                    return(languageInstalled);
                }



                this.wc = new Growl.CoreLibrary.WebClientEx();

                wc.Headers.Add("User-Agent", USER_AGENT);



                byte[] data = wc.DownloadData(this.uri);

                string definition = Encoding.UTF8.GetString(data).Trim();

                LanguageInfo info = LanguageInfo.Parse(definition);

                if (info != null)

                {
                    this.InfoLabel.Text = String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_Prompt), info.Name);

                    this.YesButton.Visible = true;

                    this.NoButton.Visible = true;

                    this.OKButton.Visible = false;



                    /* NOTE: there is a bug that is caused when Growl is launched via protocol handler (growl:) from Opera.
                     *
                     * when that happens, the call to ShowDialog hangs.
                     *
                     * i could not find any documentation on this or any reason why it would be happening (not on a non-ui thread, windows handle is already created, etc).
                     *
                     * the only fix i could find was to Show/Hide the form before calling ShowDialog. i dont even know why this works, but it does.
                     *
                     * */

                    this.Show();

                    this.Hide();



                    DialogResult result = this.ShowDialog();

                    if (result == DialogResult.Yes)

                    {
                        this.InfoLabel.Text = Utility.GetResourceString(Properties.Resources.LanguageInstaller_Installing);

                        this.progressBar1.Value = 0;

                        this.progressBar1.Visible = true;

                        this.YesButton.Enabled = false;

                        this.NoButton.Enabled = false;

                        this.Show();

                        this.Refresh();



                        if (Directory.Exists(this.tempFolder))
                        {
                            Directory.Delete(this.tempFolder, true);
                        }

                        Directory.CreateDirectory(this.tempFolder);

                        string guid = System.Guid.NewGuid().ToString();

                        string zipFileName = GetTempZipFileName(guid);

                        info.LocalZipFileLocation = zipFileName;



                        wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);

                        wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);



                        StartDownload(info);



                        Utility.WriteDebugInfo(String.Format("Downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation));



                        System.Threading.WaitHandle[] handles = new System.Threading.WaitHandle[] { are, mre };

                        while (System.Threading.WaitHandle.WaitAny(handles) == 0)

                        {
                            lock (this.progress_lock)

                            {
                                this.progressBar1.Value = this.progress.ProgressPercentage;

                                Application.DoEvents();
                            }
                        }



                        this.progressBar1.Value = 100;

                        Application.DoEvents();



                        Utility.WriteDebugInfo(String.Format("Finished downloading language pack '{0}' to {1}", info.Name, info.LocalZipFileLocation));



                        if (this.errorMessage == null)

                        {
                            // unzip files to the correct location

                            string languageFolder = GetLanguageFolder(info.CultureCode);

                            if (!ApplicationMain.HasProgramLaunchedYet || !Directory.Exists(languageFolder))

                            {
                                Utility.WriteDebugInfo(String.Format("Language '{0}' downloaded - starting unzip.", info.Name));



                                // NOTE: installing a language pack requires elevated privileges (to write the resource assemblies to the bin folder).

                                // as such, we have to be elevated first

                                if (UserAccountControlHelper.IsElevated())

                                {
                                    cultureCodeHash = UnzipFilesToBin(info.Name, info.LocalZipFileLocation, info.CultureCode, ref queuedNotifications);
                                }

                                else

                                {
                                    string argument = String.Format("growl:languageelevatedinstall*{0}~{1}~{2}", info.CultureCode, info.Name, guid);

                                    UserAccountControlHelper.LaunchElevatedApplication(System.Windows.Forms.Application.ExecutablePath, argument, true);
                                }



                                this.Close();
                            }

                            else

                            {
                                // display with the same name aleady exists...

                                ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_AlreadyInstalled), info.Name), true);
                            }
                        }

                        else

                        {
                            Utility.WriteDebugInfo(String.Format("Error downloading language pack '{0}'.", info.Name));

                            ShowMessage(errorMessage, true);
                        }
                    }
                }

                else

                {
                    // definition file was malformed

                    ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_BadDefinitionFile), this.uri), true);
                }
            }

            catch (Exception ex)

            {
                // error downloading definition file

                Utility.WriteDebugInfo(String.Format("Error downloading language pack. {0} - {1}", ex.Message, ex.StackTrace));

                ShowMessage(String.Format(Utility.GetResourceString(Properties.Resources.LanguageInstaller_NonexistentDefinitionFile), this.uri), true);
            }

            return(languageInstalled);
        }