Exemple #1
0
        public static void load_theme(Themes.ThemeInfo theme)
        {
            string path = theme.filepath;

            if (!System.IO.File.Exists(path) && !path.StartsWith("Themes"))
            {
                MessageBox.Show("The theme file has not been found in " + path, "Theme not found", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            System.Windows.Application.Current.Resources.MergedDictionaries.Clear();


            ResourceDictionary defaults = new ResourceDictionary();

            defaults.Source = new Uri(@"Themes/GeneralDefaults.xaml", UriKind.Relative);
            System.Windows.Application.Current.Resources.MergedDictionaries.Add(defaults);

            if (theme.useDefaultDarkItems)
            {
                ResourceDictionary defaultButtonsDark = new ResourceDictionary();
                defaultButtonsDark.Source = new Uri(@"Themes/DefaultDarkButtons.xaml", UriKind.Relative);
                System.Windows.Application.Current.Resources.MergedDictionaries.Add(defaultButtonsDark);
            }

            ResourceDictionary skin = new ResourceDictionary();

            if (path.StartsWith("Themes"))
            {
                skin.Source = new Uri(path, UriKind.Relative);
                Properties.Settings.Default.theme_currentPath = path;
            }
            else
            {
                try
                {
                    string tempFile = System.IO.Path.GetTempFileName() + ".xaml";
                    System.IO.File.Copy(path, tempFile);
                    string theme_content = System.IO.File.ReadAllText(tempFile);
                    theme_content = theme_content.Replace("%THEMES_DIR%", AppController.themesPath);
                    System.IO.File.WriteAllText(tempFile, theme_content);
                    skin.Source = new Uri(tempFile, UriKind.Absolute);
                    Properties.Settings.Default.theme_currentPath = path;
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message, "Loading of theme failed");
                }
            }
            System.Windows.Application.Current.Resources.MergedDictionaries.Add(skin);
        }
Exemple #2
0
        private AppController()
        {
            Current     = this;
            appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\liGhun\\Chapper\\";
            themesPath  = appDataPath + "themes\\";
            if (!System.IO.Directory.Exists(themesPath))
            {
                System.IO.Directory.CreateDirectory(themesPath);
            }
            appProgramPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

            current_filter_language_exclude_empty = false;
            init_languages();

            mainwindow          = new MainWindow();
            mainwindow.Closing += mainwindow_Closing;



            CurrentLayout = new Layouts.Layout();

            Chapper.Themes.ThemeInfo defaultLight = new Chapper.Themes.ThemeInfo();
            defaultLight.name                = "DefaultLight";
            defaultLight.filepath            = @"Themes/DefaultLight.xaml";
            defaultLight.author              = "Sven Walther";
            defaultLight.description         = "The default light theme embedded into Chapper";
            defaultLight.useDefaultDarkItems = true;
            Themes.Add(defaultLight);

            Chapper.Themes.ThemeInfo defaultDark = new Chapper.Themes.ThemeInfo();
            defaultDark.name                = "DefaultDark";
            defaultDark.filepath            = @"Themes/DefaultDark.xaml";
            defaultDark.author              = "Sven Walther";
            defaultDark.description         = "The default dark theme embedded into Chapper";
            defaultDark.useDefaultDarkItems = false;
            Themes.Add(defaultDark);

            string[] themeFiles = System.IO.Directory.GetFiles(themesPath, "*xaml");
            if (themeFiles != null)
            {
                foreach (string theme in themeFiles)
                {
                    Chapper.Themes.ThemeInfo themeInfo = new Chapper.Themes.ThemeInfo();
                    themeInfo.name     = System.IO.Path.GetFileNameWithoutExtension(theme);
                    themeInfo.filepath = theme;
                    string themeInfoPath = themesPath + "\\" + themeInfo.name + ".info";
                    if (System.IO.File.Exists(themeInfoPath))
                    {
                        try
                        {
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Chapper.Themes.ThemeInfo));
                            Chapper.Themes.ThemeInfo loadedInfo = new Themes.ThemeInfo();
                            using (System.IO.FileStream file_stream = new System.IO.FileStream(themeInfoPath, System.IO.FileMode.Open))
                            {
                                loadedInfo = (Chapper.Themes.ThemeInfo)serializer.Deserialize(file_stream);
                            }
                            loadedInfo.name     = themeInfo.name;
                            loadedInfo.filepath = themeInfo.filepath;
                            themeInfo           = loadedInfo;
                        }
                        catch (Exception exp)
                        {
                            MessageBox.Show("Can't read the contents of the theme info file of " + themeInfo.name + "\r\n" + exp.Message, "Error loading theme info", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                    Themes.Add(themeInfo);
                }
            }



            try
            {
                if (!Properties.Settings.Default.settingsUpdated)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.settingsUpdated = true;
                }
            }
            catch
            {
                try
                {
                    Properties.Settings.Default.Reset();
                }
                catch { }
            }



            //Properties.Settings.Default.accessToken = null;
            if (string.IsNullOrEmpty(Properties.Settings.Default.accessToken))
            {
                account = new Account();
                AppNetDotNet.Model.Authorization.clientSideFlow apnClientAuthProcess = new Authorization.clientSideFlow(ApiKeys.appNetClientID, ApiKeys.appNetRedirectUri, "basic stream write_post follow messages files update_profile");
                apnClientAuthProcess.AuthSuccess += apnClientAuthProcess_AuthSuccess;
                apnClientAuthProcess.showAuthWindow();
            }
            else
            {
                bool authSuccess = false;
                account             = new Account();
                account.accessToken = Properties.Settings.Default.accessToken;
                if (account.verifyCredentials())
                {
                    if (account.token.scopes.Contains("files"))
                    {
                        authSuccess = true;
                        openMainWindow();
                    }
                }

                if (!authSuccess)
                {
                    AppNetDotNet.Model.Authorization.registerAppInRegistry(Authorization.registerBrowserEmulationValue.IE8Always, alsoCreateVshostEntry: true);
                    AppNetDotNet.Model.Authorization.clientSideFlow apnClientAuthProcess = new Authorization.clientSideFlow(ApiKeys.appNetClientID, ApiKeys.appNetRedirectUri, "basic stream write_post follow messages files update_profile");
                    apnClientAuthProcess.AuthSuccess += apnClientAuthProcess_AuthSuccess;
                    apnClientAuthProcess.showAuthWindow();
                }
            }

            if (!string.IsNullOrEmpty(Properties.Settings.Default.theme_currentPath))
            {
                Chapper.Themes.ThemeInfo theme = null;
                IEnumerable <Chapper.Themes.ThemeInfo> themes = Themes.Where(t => t.filepath == Properties.Settings.Default.theme_currentPath);
                if (themes != null)
                {
                    if (themes.Count() > 0)
                    {
                        theme = themes.First();
                        load_theme(theme);
                    }
                }
            }
        }