Exemple #1
0
        public void ConfigureFirstRun()
        {
            main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/LoadingPage.xaml"));

            //Starting Tiels Console that generate Main App Directory and temp
            //Process.Start("TielsConsole.exe","createlostandfound");
            ErrorHandler.Info("Creating lostandfound directory...");
            try
            {
                if (!Directory.Exists(App.config_path))
                {
                    Directory.CreateDirectory(App.config_path);
                }
                if (!Directory.Exists(App.config_path + "\\" + "temp"))
                {
                    Directory.CreateDirectory(App.config_path + "\\" + "temp");
                }
                ErrorHandler.Info("Succesfully created lostandfound directory!");
            }
            catch (Exception ex)
            {
                File.AppendAllText(App.config_path + "\\Error.log", "\r\n[Error: " + DateTime.Now + "] " + ex.ToString());
                try
                {
                    ProcessStartInfo info = new ProcessStartInfo
                    {
                        Arguments = "createlostandfounda",
                        Verb      = "runas"
                    };
                    ErrorHandler.Info(ex.ToString());
                }
                catch (Exception iex)
                {
                    File.AppendAllText(App.config_path + "\\Error.log", "\r\n[Error: " + DateTime.Now + "] " + iex.ToString());
                    Application.Current.Shutdown();
                }
            }

            try
            {
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/ConfigurePage.xaml"));
                loadingMessage.Text = "Configuration.";

                //Creating config and creating example tile
                WindowPosition    pos0      = new WindowPosition();
                WindowPosition    pos1      = new WindowPosition();
                WindowPosition[]  positions = new WindowPosition[] { pos0, pos1 };
                JsonWindow        jwindow   = new JsonWindow();
                List <JsonWindow> jwindows  = new List <JsonWindow>();
                jwindows.Add(jwindow);
                ConfigClass config = new ConfigClass
                {
                    Version        = App.Version,
                    FirstRun       = true,
                    Blur           = true,
                    Theme          = 1,
                    Color          = "#19000000",
                    HideAfterStart = false,
                    SpecialEffects = true,
                    Windows        = jwindows
                };

                //Creating directory and config file
                string json = JsonConvert.SerializeObject(config, Formatting.Indented);
                if (Directory.Exists(App.config_path))
                {
                    File.WriteAllText(App.config_path + "\\config.json", json);
                }
                ErrorHandler.Info(json);
                if (!Directory.Exists(path + "\\Example"))
                {
                    Directory.CreateDirectory(path + "\\Example");
                }

                string             icoPath = "pack://application:,,,/Tiels;component/Assets/TielsDirectory.ico";
                StreamResourceInfo icoInfo = System.Windows.Application.GetResourceStream(new Uri(icoPath));
                byte[]             bytes   = Util.ReadFully(icoInfo.Stream);
                File.WriteAllBytes(App.config_path + "\\directoryicon.ico", bytes);

                //Creating example text file in tile
                File.WriteAllText(path + "\\Example\\ExampleContent.txt", "Example Text.");
                File.WriteAllText(path + "\\Example\\desktop.ini", "[.ShellClassInfo]\r\nIconResource=" + App.config_path + "\\directoryicon.ico,0");
            }
            catch (Exception ex)
            {
                ErrorHandler.Log(ex);
                main.Navigate(new Uri("pack://application:,,,/Tiels;component/Pages/ErrorPage.xaml"));
                loadingMessage.Text = "Tiels Error!";
                return;
            }
        }
Exemple #2
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;
            }
        }
Exemple #3
0
        public async Task ReadElements(int collumCount = 4, int rowCount = 1)
        {
            try
            {
                isLoading = true;
                ConfigClass config = Config.GetConfig();
                double      tmp_height;
                double      tmp_max_height;

                JsonWindow window = null;
                foreach (var in_window in config.Windows)
                {
                    if (in_window.Name == name)
                    {
                        window = in_window;
                    }
                }
                if (window.Hidden)
                {
                    isHidded    = true;
                    this.Height = 28;
                }

                FilesList.Visibility   = Visibility.Hidden;
                loadinginfo.Visibility = Visibility.Visible;
                await Task.Delay(100);

                FilesList.Children.Clear();
                FilesList.ColumnDefinitions.Clear();
                FilesList.RowDefinitions.Clear();
                rows = rowCount;

                //Set default values
                RowDefinition mainrow = new RowDefinition
                {
                    Height = new GridLength(1, GridUnitType.Star)
                };
                FilesList.RowDefinitions.Add(mainrow);
                FilesList.Height = 80;
                tmp_max_height   = rowCount * 80 + 28;
                tmp_height       = rowCount * 80 + 28;

                //Creating file and directory with paths to icons
                if (!Directory.Exists(App.config_path + "\\Cache"))
                {
                    Directory.CreateDirectory(App.config_path + "\\Cache");
                }
                if (!File.Exists(App.config_path + "\\Cache\\iconcache.db"))
                {
                    File.WriteAllText(App.config_path + "\\Cache\\iconcache.db", "");
                }
                //Read icon paths
                string[] tmp_iconcache = File.ReadAllLines(App.config_path + "\\Cache\\iconcache.db");
                Dictionary <string, string> iconcache = new Dictionary <string, string>();

                string[] elements    = Directory.EnumerateFiles(path + "\\" + name).ToArray();
                string[] directories = Directory.EnumerateDirectories(path + "\\" + name).ToArray();

                foreach (var cache in tmp_iconcache)
                {
                    iconcache.Add(cache.Split('*')[0], cache.Split('*')[1]);
                }

                int skipframe = 0;

                //Pseudo-random icon id
                int ri = new Random().Next(0, 1000000);

                int j = 0;
                int n = 0;
                int m = 0;
                for (int i = 0; i < elements.Length; i++)
                {
                    //await Task.Delay(5);

                    string num = "";

                    if (!iconcache.ContainsKey(elements[i]))
                    {
                        num = FileUpdates.GenerateIcons(elements[i], App.config_path, ri, i);
                    }
                    else
                    {
                        num = iconcache[elements[i]];
                    }

                    if (File.GetAttributes(elements[i]) != FileAttributes.Hidden)
                    {
                        // TODO: Look at headers instead of file extension
                        //Util.ResizeImage(Util.BitmapFromSource((BitmapSource)bitmap), (int)bitmap.Width <= 128 ? (int)bitmap.Width : ((int)bitmap.Width/10), (int)bitmap.Height <= 128 ? (int)bitmap.Height : (int)bitmap.Height/10);
                        Image image = new Image
                        {
                            Width  = 44,
                            Height = 44,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Margin = new Thickness(0, 1, 0, 19),
                            Source = Util.BitmapFromUri(new Uri(App.config_path + num))
                                     //Source = elements[i].ToLower().Contains(".png") || elements[i].ToLower().Contains(".jpg") || elements[i].ToLower().Contains(".jpeg") ? Util.ImageSourceFromBitmap(bitmap2) : Util.BitmapFromUri(new Uri(path + num)) // ICON
                        };
                        string    filetext = elements[i].Replace(path + "\\" + name + "\\", "").Replace(".lnk", "").Replace(".url", "");
                        TextBlock filename = new TextBlock
                        {
                            VerticalAlignment   = VerticalAlignment.Bottom,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Foreground          = config.Theme == 0 ? Brushes.Black : Brushes.White,
                            Text = filetext.Length > 14 ? filetext.Remove(filetext.Length - (filetext.Length - 14)) + "..." : filetext
                        };

                        Grid button_content = new Grid();
                        button_content.Children.Add(image);
                        button_content.Children.Add(filename);

                        Button button = new Button
                        {
                            Content     = button_content,
                            Background  = Brushes.Transparent,
                            BorderBrush = Brushes.Transparent,
                            Name        = "elementButton_" + i,
                            Tag         = elements[i],
                            ToolTip     = elements[i].Replace(path + "\\" + name + "\\", "").Replace(".lnk", " - Shortcut").Replace(".url", " - Internet Shortcut")
                        };
                        button.Click += ElementClicked;
                        button.MouseRightButtonUp += (sender, e) =>
                        {
                            ShellContextMenu menu  = new ShellContextMenu();
                            FileInfo[]       arrFI = new FileInfo[1];
                            arrFI[0] = new FileInfo((string)((Button)sender).Tag);

                            menu.ShowContextMenu(arrFI, System.Windows.Forms.Control.MousePosition);
                        };

                        SortGrid(collumCount, i, button, ref j, ref n, ref m);
                    }
                }
                #region Old (Needs Refactor)
                //TODO: REFACTOR THIS
                if (directories.Length != 0)
                {
                    for (int i = 0; i < directories.Length; i++)
                    {
                        TextBlock image = new TextBlock
                        {
                            FontSize            = 44,
                            FontFamily          = new FontFamily("Segoe MDL2 Assets"),
                            Width               = 44,
                            Height              = 44,
                            Foreground          = config.Theme == 0 ? Brushes.Black : Brushes.White,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Margin              = new Thickness(0, 1, 0, 19),
                            Text = ""
                        };

                        string    filetext = directories[i].Replace(path + "\\" + name + "\\", "");
                        TextBlock filename = new TextBlock
                        {
                            VerticalAlignment   = VerticalAlignment.Bottom,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Foreground          = config.Theme == 0 ? Brushes.Black : Brushes.White,
                            Text = filetext.Length <= 14 ? filetext : filetext.Remove(filetext.Length - (filetext.Length - 14)) + "..."
                        };

                        Grid button_content = new Grid();
                        button_content.Children.Add(image);
                        button_content.Children.Add(filename);

                        Button button = new Button
                        {
                            Content     = button_content,
                            Background  = Brushes.Transparent,
                            BorderBrush = Brushes.Transparent,
                            Name        = "elementButton_" + i,
                            Tag         = directories[i],
                            ToolTip     = directories[i].Replace(path + "\\" + name + "\\", "") + " - Directory"
                        };
                        button.Click += ElementClicked;

                        SortGrid(collumCount, i, button, ref j, ref n, ref m);
                    }
                }
                #endregion
                tmp_max_height = System.Windows.SystemParameters.PrimaryScreenHeight / 1.025;
                tmp_height     = rows * 80 + 28;
                this.ScrollFilesList.Height += rows * 80;

                id = window.Id;
                if (window.Height > 0)
                {
                    tmp_height = window.Height;
                    this.ScrollFilesList.Height = window.Height;
                }
                if (window.Hidden)
                {
                    tmp_height           = 28;
                    this.lastHeight      = window.Height;
                    this.hideBtn.Content = "";
                    this.chromewindow.ResizeBorderThickness = new Thickness(0);
                }

                if (tmp_height >= System.Windows.SystemParameters.PrimaryScreenHeight - 20)
                {
                    tmp_height = System.Windows.SystemParameters.PrimaryScreenHeight / 2;
                    this.ScrollFilesList.Height = System.Windows.SystemParameters.PrimaryScreenHeight / 2;
                }

                this.MaxHeight = tmp_max_height;
                this.Height    = tmp_height;
            }
            catch (FileNotFoundException fnfex)
            {
                File.AppendAllText(App.config_path + "\\Error.log", "\r\n[Error: " + DateTime.Now + "] " + fnfex.ToString());
                tries++;
                ResetIconCache();
                if (tries == 1)
                {
                    ReadElements();
                }
                else
                {
                    throw fnfex;
                }
            }

            loadinginfo.Visibility = Visibility.Collapsed;
            FilesList.Visibility   = Visibility.Visible;
            this.Show();
            this.Visibility = Visibility.Visible;
            isLoading       = false;
            tries           = 0;
            GC.Collect();
            //filedata.Clear();
        }