コード例 #1
0
        /// <summary>
        /// Gets the language corresponding to the currently selected language
        /// </summary>
        /// <returns></returns>
        public TextProvider GetLanguage(string language)
        {
            string file     = Path.Combine(Pandora.Folder, "Lang");
            string resource = null;

            file = Path.Combine(file, string.Format("{0}.dll", language));

            if (!File.Exists(file))
            {
                // Selected language doesn't exist. Revert to English
                System.Windows.Forms.MessageBox.Show(String.Format("The langague selected for the current profile could not be located. {0} will be used instead.\n\nMissing language: {0}.", Pandora.Profile.Language, DEFAULT_LANGUAGE));

                Pandora.Profile.Language = DEFAULT_LANGUAGE;

                file = Path.Combine(Pandora.Folder, "Lang");
                file = Path.Combine(file, string.Format(DEFAULT_LANGUAGE + ".dll"));

                if (!File.Exists(file))
                {
                    // English doesn't exist either. This is wrong.
                    System.Windows.Forms.MessageBox.Show(String.Format("Pandora's Box couldn't locate a required component ({0}.dll). Please reinstall the program to address this issue.", DEFAULT_LANGUAGE));
                    Pandora.Log.WriteError(null, DEFAULT_LANGUAGE + ".dll not found. Closing.");
                    Pandora.ClosePandora();
                    // Is this executed?
                    throw new Exception("Default language file not found");
                }
            }


            try
            {
                // Read the TextProvider object
                resource = string.Format("{0}.language.xml", language);

                // Load the assembly
                Assembly asm    = Assembly.LoadFile(file);
                Stream   stream = asm.GetManifestResourceStream(resource);

                XmlDocument dom = new XmlDocument();
                dom.Load(stream);

                stream.Close();

                TextProvider tp = TextProvider.Deserialize(dom);

                return(tp);
            }
            catch (Exception err)
            {
                System.Windows.Forms.MessageBox.Show("An unexpected error occurred when loading language files. Details about the error have been recorded in the log file. Pandora's Box will now close.");
                Pandora.Log.WriteError(err, "Loading resource {0} from assembly in file {1}", resource, file);
                throw new Exception("Language file corrupted");
            }
        }