示例#1
0
 public void Application_Startup(object sender, StartupEventArgs e)
 {
     AppController.Start();
 }
示例#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);
                    }
                }
            }
        }