Esempio n. 1
0
        /// <summary>
        /// Registers the dictionaries while startup of the application.
        /// </summary>
        /// <param name="e">The eventarguments.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("de-DE"),
                new XmlLanguageDictionary("Languages/de-DE.xml"));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("en-US"),
                new XmlLanguageDictionary("Languages/en-US.xml"));

            LanguageContext.Instance.Culture = CultureInfo.GetCultureInfo("de-DE");

            base.OnStartup(e);
        }
Esempio n. 2
0
        /// <summary>
        /// Change de app language.
        /// </summary>
        /// <param name="lang"></param>
        public static void ChangeLanguage(string lang)
        {
            string file = "lang/" + lang + ".tsl";

            if (!File.Exists(file))
            {
                return;
            }

            try {
                CultureInfo culture = CultureInfo.GetCultureInfo(lang);

                LanguageDictionary.RegisterDictionary(culture, new Hieda.Tool.XmlLanguageDictionary(file));
                LanguageContext.Instance.Culture = culture;

                Lang.Initialize();
            } catch {
                // If error (invalid culture), default hard-coded texts will be used
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("en-US"),
                new XmlLanguageDictionary("Languages/en-US.xml"));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("es-ES"),
                new XmlLanguageDictionary("Languages/es-ES.xml"));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("fr-FR"),
                new XmlLanguageDictionary("Languages/fr-FR.xml"));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("it-IT"),
                new XmlLanguageDictionary("Languages/it-IT.xml"));

            var culture = CurrentCultureManager.Current.CurrentCultureName;

            culture = string.IsNullOrEmpty(culture) ? "en-US" : culture;
            LanguageContext.Current.Culture = CultureInfo.GetCultureInfo(culture);


            DispatcherUnhandledException += onDispatcherUnhandledException;

            //Prepare db for synchronization.
            if (!ScopeHelper.CheckScope(Constants.LocalConnectionString))
            {
                ScopeHelper.CreateScope(Constants.LocalConnectionString);
            }

            base.OnStartup(e);

            SyncServiceManager.Current.RunService();
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an instance of the App.
        /// </summary>
        App()
        {
            U.Level = LogLevel.Debug;
            U.L(LogLevel.Information, "APP", "Starting up");

            string a = Assembly.GetExecutingAssembly().CodeBase;
            Uri    b = new Uri(a);
            string c = b.AbsolutePath;
            string d = Uri.EscapeDataString(c);

            string baseFolder = U.BasePath;

            languageFolder = Path.Combine(baseFolder, languageFolder);

            U.L(LogLevel.Debug, "APP", "Loading languages from " + languageFolder);

            if (!Directory.Exists(languageFolder))
            {
                languageFolder = Path.Combine(baseFolder, @"..\..\Platform\Windows 7\GUI\Languages");
            }

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("en-US"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "en-US.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("nb-NO"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "nb-NO.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("sv-SE"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "sv-SE.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("zh-CN"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "zh-CN.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("pt-BR"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "pt-BR.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("de-DE"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "de-DE.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("it-IT"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "it-IT.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("hu-HU"),
                new XmlLanguageDictionary(Path.Combine(languageFolder, "hu-HU.xml")));

            string lang = Stoffi.Properties.Settings.Default.Language;

            if (lang == null)
            {
                lang = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag;
            }
            CultureInfo ci = CultureInfo.GetCultureInfo(lang);

            U.L(LogLevel.Debug, "APP", String.Format("Setting culture: {0} ({1})", ci.TwoLetterISOLanguageName, ci.IetfLanguageTag));
            LanguageContext.Instance.Culture      = ci;
            Thread.CurrentThread.CurrentUICulture = ci;

            // check arguments
            string[] arguments = Environment.GetCommandLineArgs();

            // restart
            bool restarting = arguments.Length > 1 && arguments.Contains <string>("--restart");

            // register associations
            if (arguments.Length == 3 && arguments[1] == "--associate")
            {
                U.L(LogLevel.Information, "APP", "Associating file types and URI handles");
                SetAssociations(arguments[2] == "true");
                Application.Current.Shutdown();
                return;
            }

            // uninstall
            else if (arguments.Length == 2 && arguments[1] == "--uninstall")
            {
                Uninstall();
                Application.Current.Shutdown();
                return;
            }

            // find out if Stoffi is already running
            if (!restarting)
            {
                Process   ThisProcess   = Process.GetCurrentProcess();
                Process[] SameProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);
                U.L(LogLevel.Debug, "APP", "Checking for processes named: " + ThisProcess.ProcessName);
                if (SameProcesses.Length > 1)                 // Stoffi is already running!
                {
                    U.L(LogLevel.Information, "APP", "Another instance is already running");

                    // pass arguments to first instance
                    try
                    {
                        using (NamedPipeClientStream client = new NamedPipeClientStream(identifier.ToString()))
                        {
                            using (StreamWriter writer = new StreamWriter(client))
                            {
                                U.L(LogLevel.Debug, "APP", "Sending arguments");
                                client.Connect(200);

                                foreach (String argument in arguments)
                                {
                                    writer.WriteLine(argument);
                                }

                                if (arguments.Count() == 1)
                                {
                                    U.L(LogLevel.Debug, "APP", "Trying to raise window");
                                    SetForegroundWindow(SameProcesses[0].MainWindowHandle);
                                    ShowWindow(SameProcesses[0].MainWindowHandle, 9);
                                }

                                // shut down
                                U.L(LogLevel.Information, "APP", "Dying gracefully after sending data to running instance");
                                Application.Current.Shutdown();
                                return;
                            }
                        }
                    }
                    catch (TimeoutException exc)
                    {
                        U.L(LogLevel.Error, "APP", "Couldn't connect to server: " + exc.Message);
                    }
                    catch (IOException exc)
                    {
                        U.L(LogLevel.Error, "APP", "Pipe was broken: " + exc.Message);
                    }
                    catch (Exception exc)
                    {
                        U.L(LogLevel.Error, "APP", "Couldn't send arguments: " + exc.Message);
                    }
                    U.L(LogLevel.Warning, "APP", "Couldn't contact the other instance; I declare it dead and take its place");
                }
            }

            if (!Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.IsPlatformSupported)
            {
                MessageBox.Show(U.T("MessageOldWindows", "Message"), U.T("MessageOldWindows", "Title"), MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
                return;
            }
        }