Example #1
0
        private void Add_file_to_list_of_managed_files()
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.InitialDirectory = SelectedGame.Save_file_location;

                Nullable <bool> result = dlg.ShowDialog();

                if (result == true)
                {
                    List <string> selected_filenames = dlg.FileNames.ToList <string>();

                    foreach (string selected_filename in selected_filenames)
                    {
                        FileInfo finfo = new FileInfo(selected_filename);

                        if (!FilesToBeManaged.Contains(selected_filename) && string.Equals(finfo.DirectoryName, SelectedGame.Save_file_location))
                        {
                            FilesToBeManaged.Add(finfo.Name);
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to add file names into list.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                FilesToBeManaged.Clear();
            }
        }
Example #2
0
        //private void Load_Games_List() //this method should be availabale in the main window
        //{
        //    //games_listbox.SelectedItem = null;
        //    Games.Clear(); //games_listbox.Items.Clear();
        //    try
        //    {
        //        //Try to load file in xml extension, with list of games
        //        if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "games_list.xml"))
        //        {
        //            XDocument xdoc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "games_list.xml");
        //            //FileStream fs = new FileStream(xdoc.BaseUri, FileMode.Open, FileAccess.Read);

        //            //reminder: games_list.xml construction: Games_list->Games->Game->Id|Name|Save_file_location|Store_profile_saves_in_app_location|
        //            var query = from item in xdoc.Element("Game_save_file_manager").Element("Games").Elements("Game")
        //                        select item;

        //            foreach (var item in query) //adding games to list
        //            {
        //                Game gi_ob = new Game();
        //                gi_ob.Game_name = item.Element("Name").Value;/*(from temp_it in item.Descendants()
        //                                  select temp_it.Element("Name")).First().ToString();*/

        //                gi_ob.Save_file_location = item.Element("Save_file_location").Value;/*(from temp_it in item.Descendants()
        //                                           select temp_it.Element("Save_file_location")).First().ToString();*/

        //                string temp_profile_specific_file_storage_method;
        //                temp_profile_specific_file_storage_method = item.Element("Store_profile_saves_in_app_location").Value; /*(from temp_it in item.Descendants()
        //                                           select temp_it.Element("Store_profile_saves_in_app_location")).First().ToString();*/

        //                gi_ob.Profile_specific_save_file_storage_method = Convert.ToInt32(temp_profile_specific_file_storage_method);

        //                //games_listbox.Items.Add(gi_ob);
        //                Games.Add(gi_ob);
        //            }
        //        }
        //        else
        //        {
        //            FileNotFoundMethod(applicationDataFilePath);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("Failed to load games' list. " + ex.Message);
        //    }
        //}

        private void LoadApplicationData(string path)
        {
            Games.Clear(); //games_listbox.Items.Clear();
            FilesToBeManaged.Clear();

            try
            {
                applicationDataFilePath = path;
                //Try to load file in xml extension, with list of games
                if (File.Exists(applicationDataFilePath))
                {
                    XDocument xdoc = XDocument.Load(applicationDataFilePath);
                    //FileStream fs = new FileStream(xdoc.BaseUri, FileMode.Open, FileAccess.Read);

                    //reminder: games_list.xml construction: Games_list->Games->Game->Id|Name|Save_file_location|Store_profile_saves_in_app_location|
                    var query = from item in xdoc.Element("Game_save_file_manager").Element("Games").Elements("Game")
                                select item;

                    foreach (var item in query) //adding games to list
                    {
                        Game gi_ob = new Game();
                        gi_ob.Game_name = item.Element("Name").Value;                        /*(from temp_it in item.Descendants()
                                                                                              * select temp_it.Element("Name")).First().ToString();*/

                        gi_ob.Save_file_location = item.Element("Save_file_location").Value; /*(from temp_it in item.Descendants()
                                                                                              * select temp_it.Element("Save_file_location")).First().ToString();*/

                        string temp_profile_specific_file_storage_method;
                        temp_profile_specific_file_storage_method = item.Element("Store_profile_saves_in_app_location").Value; /*(from temp_it in item.Descendants()
                                                                                                                                * select temp_it.Element("Store_profile_saves_in_app_location")).First().ToString();*/

                        gi_ob.Profile_specific_save_file_storage_method = Convert.ToInt32(temp_profile_specific_file_storage_method);

                        bool node_exists = item.Elements("Manage_selected_files_only").Any();
                        if (node_exists == false)
                        {
                            gi_ob.ManageSelectedFilesOnly = false;
                        }
                        else
                        {
                            gi_ob.ManageSelectedFilesOnly = Convert.ToBoolean(item.Element("Manage_selected_files_only").Value);
                        }

                        if (item.Elements("Files_to_manage").Any())//.Elements("File").Any())
                        {
                            if (item.Element("Files_to_manage").Elements("File").Any())
                            {
                                foreach (string filename in item.Element("Files_to_manage").Elements("File"))
                                {
                                    gi_ob.FilesToManage.Add(filename);
                                }
                            }
                        }
                        //games_listbox.Items.Add(gi_ob);
                        Games.Add(gi_ob);
                    }
                    Mediator.Instance.NotifyColleagues(Mediator.ViewModelMessages.GameListUpdated, games);
                }
                else
                {
                    //create new "games_list.xml" file
                    FileNotFoundMethod(applicationDataFilePath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to load games' list. " + ex.Message);
            }
        }