示例#1
0
        public async void Load()
        {
            _ = fu.UpdateEntryTask();

            isLoading = true;
            if (File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Tiels\\config.json") == "")
            {
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/ErrorPage.xaml"));
                loadingMessage.Text = "Tiels Error!";
                return;
            }
            ConfigClass config = Config.GetConfig();

            if (config == null)
            {
                ErrorHandler.Log(new FileLoadException(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Tiels\\config.json was empty of corrupted."));
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/ErrorPage.xaml"));
                loadingMessage.Text = "Tiels Error!";
                return;
            }
            else
            {
                if (config.HideAfterStart)
                {
                    ni.Visible = true;
                    this.Hide();
                }
            }
            loadingPage.Rename("Loading Config...");
            this.main.NavigationService.Navigate(loadingPage);
            //main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/LoadingPage.xaml"));
            await Task.Delay(200);

            try
            {
                string[] tiles = Directory.EnumerateDirectories(path).ToArray();
                //Check config version
                if (App.Version != config.Version)
                {
                    //Update version and add default values
                    try
                    {
                        if (int.Parse(config.Version.Substring(3, 1)) < 4)
                        {
                            if (MessageBox.Show("Config version is too old.\r\nReconfiguration required!\r\nReconfiguration can delete current appearance settings.\r\nProceed?", "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                            {
                                ErrorHandler.Error();
                            }
                            else
                            {
                                //this.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.Error();
                    }
                }

                if (!config.SpecialEffects)
                {
                    shadoweffect.Effect = null;
                }

                if (tiles.Length != 0)
                {
                    config = Config.GetConfig();
                    for (int i = 0; i <= tiles.Length - 1; i++)
                    {
                        tiles[i] = tiles[i].Replace(path + "\\", "");

                        //Creating tile
                        TileWindow tile = new TileWindow();
                        tile.folderNameTB.Text = tiles[i];
                        tile.name = tiles[i];
                        tilesw.Add(tile);
                        bool windowexist = false;

                        //Search for tile in config
                        foreach (var window in config.Windows)
                        {
                            if (window.Name == tiles[i])
                            {
                                loadingPage.Rename("Reading data from " + window.Name + "...");
                                //Tile exists?
                                windowexist = true;

                                //Setting tile rosition
                                tile.Left = window.Position.X;
                                tile.Top  = window.Position.Y;

                                //Rotating tile
                                if (!window.EditBar)
                                {
                                    tile.rd.Height  = new GridLength(1, GridUnitType.Star);
                                    tile.trd.Height = new GridLength(28);
                                    Grid.SetRow(tile.ActionGrid, 1);
                                    Grid.SetRow(tile.ScrollFilesList, 0);
                                }
                                else
                                {
                                    tile.rd.Height  = new GridLength(28);
                                    tile.trd.Height = new GridLength(1, GridUnitType.Star);
                                    Grid.SetRow(tile.ActionGrid, 0);
                                    Grid.SetRow(tile.ScrollFilesList, 1);
                                }
                                if (window.Height > 0)
                                {
                                    tile.Height = window.Height;
                                    tile.ScrollFilesList.Height = window.Height;
                                }
                                else
                                {
                                    window.Height = 0;
                                }

                                tile.Width = window.Width;
                            }
                        }
                        //If tile not exists create default values
                        if (!windowexist)
                        {
                            loadingPage.Rename("Creating " + tiles[i] + "...");
                            JsonWindow jsonwindow = new JsonWindow();
                            jsonwindow.Name     = tiles[i];
                            jsonwindow.Position = new WindowPosition {
                                X = 0, Y = 0
                            };
                            jsonwindow.Height  = 0;
                            jsonwindow.Width   = 0;
                            jsonwindow.EditBar = false;
                            jsonwindow.Id      = i;
                            config.Windows.Add(jsonwindow);
                        }

                        //If Config File not Exists
                        bool result = Config.SetConfig(config);
                        if (result == false)
                        {
                            ErrorHandler.Error();
                        }

                        _ = asyncShowTile(tile);
                    }
                }
                loadingPage.Rename("Loading...");
                bool isTilesLoading = true;
                while (isTilesLoading)
                {
                    await Task.Delay(200);

                    isTilesLoading = false;
                    foreach (TileWindow tileWindow in tilesw)
                    {
                        if (tileWindow.isLoading == true)
                        {
                            isTilesLoading = true;
                        }
                    }
                }

                //Load MainPage
                isLoading = false;
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/MainPage.xaml"));
                loadingMessage.Text = "Tile Loaded Successfully!";
            }
            catch (Exception ex)
            {
                ErrorHandler.Log(ex);
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/ErrorPage.xaml"));
                loadingMessage.Text = "Tiels Error!";
                return;
            }
        }
示例#2
0
 private async Task asyncShowTile(TileWindow tile)
 {
     tile.Show();
 }