Ejemplo n.º 1
0
        private bool HasEnoughSpaceOnFastDrive(Game game)
        {
            LocalDataManager ldm    = new LocalDataManager();
            Config           cfg    = ldm.LoadConfig();
            string           letter = Path.GetPathRoot(cfg.OutputPath);

            return(GetTotalFreeSpace(letter) > game.Size);
        }
Ejemplo n.º 2
0
        private void BackgroundWorkerLoadGame(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            DateTime before = DateTime.Now;

            currentGame.Status = GameStatus.Loading;
            LocalDataManager ldm        = new LocalDataManager();
            Config           cfg        = ldm.LoadConfig();
            string           outputPath = Path.Combine(cfg.OutputPath, currentGame.Name);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            DirectoryInfo di = new DirectoryInfo(currentGame.Path);

            OnStartMovingFiles();
            FileInfo[] files = di.GetFiles("*", SearchOption.AllDirectories);
            currentGame.FileCount = files.Length;
            currentGame.Size      = files.Sum(t => t.Length);
            int  count         = 0;
            bool hasCopyIssues = files.AsParallel()
                                 .WithDegreeOfParallelism(Environment.ProcessorCount)
                                 // If any of these are true, then we have a problem
                                 .Any(info =>
            {
                OnGameMoveProgress(count++, files.Length);

                string outputfile = CalculateOutputFilePath(outputPath, info, di);
                FileInfo f        = new FileInfo(outputfile);
                if (!f.Directory.Exists)
                {
                    f.Directory.Create();
                }
                return(!CopyFile(info, outputfile));
            });

            if (hasCopyIssues)
            {
                return;
            }


            OnDoneMovingFiles();

            string newPath = di.FullName + ".oldGameLoader";

            di.MoveTo(newPath);

            CreateDirectoryJunction(outputPath, currentGame.Path);
            OnDoneEnablingGame(currentGame);

            DateTime after = DateTime.Now;

            Console.WriteLine("Task took: " + (after - before).TotalSeconds);
        }
Ejemplo n.º 3
0
        private void BackgroundWorkerLoadGame(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            currentGame.Status = GameStatus.Loading;
            LocalDataManager ldm        = new LocalDataManager();
            Config           cfg        = ldm.LoadConfig();
            string           outputPath = Path.Combine(cfg.OutputPath, currentGame.Name);

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            DirectoryInfo di = new DirectoryInfo(currentGame.Path);

            OnStartMovingFiles();
            FileInfo[] files = di.GetFiles("*", SearchOption.AllDirectories);
            currentGame.FileCount = files.Length;
            currentGame.Size      = files.Sum(t => t.Length);
            for (int i = 0, len = files.Length; i < len; i++)
            {
                OnGameMoveProgress(i, len);
                FileInfo file       = files[i];
                string   outputfile = CalculateOutputFilePath(outputPath, file, di);
                FileInfo f          = new FileInfo(outputfile);
                if (f.Directory != null && !f.Directory.Exists)
                {
                    f.Directory.Create();
                }
                try
                {
                    file.CopyTo(outputfile, true);
                }
                catch (Exception)
                {
                    if (!CalculateMd5(file.FullName).Equals(CalculateMd5(outputfile)))
                    {
                        MessageBox.Show(
                            $"Something went wrong when trying to move file \"{file.FullName}\" to \"{outputfile}\"");
                        return;
                    }
                }
            }
            OnDoneMovingFiles();
            string newPath = di.FullName + ".oldGameLoader";

            di.MoveTo(newPath);

            CreateDirectoryJunction(outputPath, currentGame.Path);
            OnDoneEnablingGame(currentGame);
        }
Ejemplo n.º 4
0
 public GameLoaderForm()
 {
     InitializeComponent();
     Closing += OnClosing;
     folderGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     folderGridView.UserDeletingRow += delegate(object sender, DataGridViewRowCancelEventArgs args)
     {
         Game game = args.Row.DataBoundItem as Game;
         if (game != null && game.Status != GameStatus.Deactivated)
         {
             MessageBox.Show("You need to deactivate the game before you can delete it from GameLoader");
             args.Cancel = true;
         }
         else
         {
             LocalDataManager ldm = new LocalDataManager();
             ldm.SaveGames(Games.ToList());
         }
     };
     Games = new BindingList<Game>(LoadData());
     BindingSource source = new BindingSource(Games, null);
     folderGridView.DataSource = source;
     LoadConfig();
 }
Ejemplo n.º 5
0
 private void saveFastFolderButton_Click(object sender, EventArgs e)
 {
     if (Games.Any(g => g.Status != GameStatus.Deactivated))
     {
         MessageBox.Show("Not all games are deactivated, please do this first!");
         return;
     }
     string text = fastFolderTextBox.Text;
     if (string.IsNullOrWhiteSpace(text))
     {
         MessageBox.Show("You have to enter a path");
         return;
     }
     if (File.Exists(text))
     {
         MessageBox.Show("There is a file at this path. It is therefor not valid");
         return;
     }
     if (!Directory.Exists(text))
     {
         DialogResult result = MessageBox.Show("The destination folder does not exist, do you want me to create it?", "Directory not found", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
             Directory.CreateDirectory(text);
         else
             return;
     }
     LocalDataManager ldm = new LocalDataManager();
     Config cfg = ldm.LoadConfig();
     cfg.OutputPath = text;
     ldm.SaveConfig(cfg);
 }
Ejemplo n.º 6
0
 private void SaveData()
 {
     List<Game> ga = Games.ToList();
     LocalDataManager ldm = new LocalDataManager();
     ldm.SaveGames(ga);
 }
Ejemplo n.º 7
0
 private List<Game> LoadData()
 {
     LocalDataManager ldm = new LocalDataManager();
     return ldm.LoadGames();
 }
Ejemplo n.º 8
0
 private void LoadConfig()
 {
     LocalDataManager ldm = new LocalDataManager();
     Config cfg = ldm.LoadConfig();
     fastFolderTextBox.Text = cfg.OutputPath;
     if (cfg.FirstRun)
     {
         cfg.FirstRun = false;
         ldm.SaveConfig(cfg);
         using (BackgroundWorker bw = new BackgroundWorker())
         {
             bw.DoWork += BackgroundWorkerScanForGames;
             bw.RunWorkerAsync();
         }
     }
     else
     {
         SearchFoldersForGames(cfg.GamesFolders);
     }
 }
Ejemplo n.º 9
0
 private void BackgroundWorkerScanForGames(object sender, DoWorkEventArgs doWorkEventArgs)
 {
     workingProgress = WorkingProgress.ScanningForGames;
     var ldm = new LocalDataManager();
     var cfg = ldm.LoadConfig();
     DialogResult result =
             MessageBox.Show(
                 "This is the first time you are running GameLoader, do you want it to check for installed games?",
                 "Check for games", MessageBoxButtons.YesNo);
     List<string> fs = cfg.GamesFolders;
     if (result == DialogResult.Yes)
     {
         string[] paths = GameSuggestions.GetGameFolders();
         string question = "I found these paths: " + Environment.NewLine + string.Join(Environment.NewLine, paths) + Environment.NewLine + "Do you want to use them?" + Environment.NewLine + "You can add other folders to auto-discovery later if you want. ";
         result = MessageBox.Show(question, "Found paths", MessageBoxButtons.YesNo);
         if (result == DialogResult.Yes)
         {
             fs.AddRange(paths.Distinct());
         }
     }
     ldm.SaveConfig(cfg);
     SearchFoldersForGames(fs);
 }
Ejemplo n.º 10
0
 private void AddAutodiscoveryFolderButton_Click(object sender, EventArgs e)
 {
     string t = AddAutoDiscoveryTextBox.Text;
     if (string.IsNullOrWhiteSpace(t)) return;
     if (!Directory.Exists(t))
     {
         MessageBox.Show("Directory does not exist");
         return;
     }
     LocalDataManager ldm = new LocalDataManager();
     Config cfg = ldm.LoadConfig();
     cfg.GamesFolders.Add(t);
     GameAdder ga = new GameAdder();
     ga.DataReady += AdderOnDataReady;
     ga.AddGames(GameSuggestions.GetGameFolders(t));
     AddAutoDiscoveryTextBox.Text = "";
 }
Ejemplo n.º 11
0
        private void BackgroundWorkerUnloadGame(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            currentGame.Status = GameStatus.Unloading;
            LocalDataManager ldm = new LocalDataManager();
            Config           cfg = ldm.LoadConfig();

            DirectoryInfo gameDirectory = new DirectoryInfo(currentGame.Path + ".oldGameLoader");

            if (!gameDirectory.Exists)
            {
                gameDirectory = new DirectoryInfo(currentGame.Path);
                if (gameDirectory.Exists)
                {
                    gameDirectory.Delete();
                }
                gameDirectory.Create();
                DirectoryInfo gameLoaderDirectory = new DirectoryInfo(PathCombine(cfg.OutputPath, currentGame.Name));
                OnStartMovingFiles();
                FileInfo[] files = gameLoaderDirectory.GetFiles("*", SearchOption.AllDirectories);
                currentGame.FileCount = files.Length;
                currentGame.Size      = files.Sum(t => t.Length);
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    FileInfo file       = files[i];
                    string   outputfile = CalculateOutputFilePath(gameDirectory, file, gameLoaderDirectory);
                    FileInfo f          = new FileInfo(outputfile);
                    if (f.Directory != null && !f.Directory.Exists)
                    {
                        f.Directory.Create();
                    }
                    file.CopyTo(outputfile, true);
                }
                OnDoneMovingFiles();
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    files[i].Delete();
                }
                gameLoaderDirectory.Delete(true);
                OnDoneDisablingGame(currentGame);
            }
            else
            {
                OnStartMovingFiles();
                if (Directory.Exists(currentGame.Path))
                {
                    Directory.Delete(currentGame.Path, true);
                }
                gameDirectory.MoveTo(currentGame.Path);

                OnDoneMovingFiles();

                DirectoryInfo gameLoaderDirectory = new DirectoryInfo(PathCombine(cfg.OutputPath, currentGame.Name));
                FileInfo[]    files = gameLoaderDirectory.GetFiles("*", SearchOption.AllDirectories);
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    files[i].Delete();
                }
                gameLoaderDirectory.Delete(true);
                OnDoneDisablingGame(currentGame);
            }
        }
Ejemplo n.º 12
0
 private bool HasEnoughSpaceOnFastDrive(Game game)
 {
     LocalDataManager ldm = new LocalDataManager();
     Config cfg = ldm.LoadConfig();
     string letter = Path.GetPathRoot(cfg.OutputPath);
     return GetTotalFreeSpace(letter) > game.Size;
 }
Ejemplo n.º 13
0
        private void BackgroundWorkerUnloadGame(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            currentGame.Status = GameStatus.Unloading;
            LocalDataManager ldm = new LocalDataManager();
            Config cfg = ldm.LoadConfig();

            DirectoryInfo gameDirectory = new DirectoryInfo(currentGame.Path + ".oldGameLoader");
            if (!gameDirectory.Exists)
            {
                gameDirectory = new DirectoryInfo(currentGame.Path);
                if (gameDirectory.Exists)
                {
                    gameDirectory.Delete();
                }
                gameDirectory.Create();
                DirectoryInfo gameLoaderDirectory = new DirectoryInfo(PathCombine(cfg.OutputPath, currentGame.Name));
                OnStartMovingFiles();
                FileInfo[] files = gameLoaderDirectory.GetFiles("*", SearchOption.AllDirectories);
                currentGame.FileCount = files.Length;
                currentGame.Size = files.Sum(t => t.Length);
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    FileInfo file = files[i];
                    string outputfile = CalculateOutputFilePath(gameDirectory, file, gameLoaderDirectory);
                    FileInfo f = new FileInfo(outputfile);
                    if (f.Directory != null && !f.Directory.Exists)
                    {
                        f.Directory.Create();
                    }
                    file.CopyTo(outputfile, true);
                }
                OnDoneMovingFiles();
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    files[i].Delete();
                }
                gameLoaderDirectory.Delete(true);
                OnDoneDisablingGame(currentGame);
            }
            else
            {
                OnStartMovingFiles();
                if (Directory.Exists(currentGame.Path))
                {
                    Directory.Delete(currentGame.Path, true);
                }
                gameDirectory.MoveTo(currentGame.Path);

                OnDoneMovingFiles();

                DirectoryInfo gameLoaderDirectory = new DirectoryInfo(PathCombine(cfg.OutputPath, currentGame.Name));
                FileInfo[] files = gameLoaderDirectory.GetFiles("*", SearchOption.AllDirectories);
                for (int i = 0, len = files.Length; i < len; i++)
                {
                    OnGameMoveProgress(i, len);
                    files[i].Delete();
                }
                gameLoaderDirectory.Delete(true);
                OnDoneDisablingGame(currentGame);
            }
        }
Ejemplo n.º 14
0
        private void BackgroundWorkerLoadGame(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            currentGame.Status = GameStatus.Loading;
            LocalDataManager ldm = new LocalDataManager();
            Config cfg = ldm.LoadConfig();
            string outputPath = Path.Combine(cfg.OutputPath, currentGame.Name);
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            DirectoryInfo di = new DirectoryInfo(currentGame.Path);
            OnStartMovingFiles();
            FileInfo[] files = di.GetFiles("*", SearchOption.AllDirectories);
            currentGame.FileCount = files.Length;
            currentGame.Size = files.Sum(t => t.Length);
            for (int i = 0, len = files.Length; i < len; i++)
            {
                OnGameMoveProgress(i, len);
                FileInfo file = files[i];
                string outputfile = CalculateOutputFilePath(outputPath, file, di);
                FileInfo f = new FileInfo(outputfile);
                if (f.Directory != null && !f.Directory.Exists)
                {
                    f.Directory.Create();
                }
                try
                {
                    file.CopyTo(outputfile, true);
                }
                catch (Exception)
                {
                    if (!CalculateMd5(file.FullName).Equals(CalculateMd5(outputfile)))
                    {
                        MessageBox.Show(
                            $"Something went wrong when trying to move file \"{file.FullName}\" to \"{outputfile}\"");
                        return;
                    }
                }
            }
            OnDoneMovingFiles();
            string newPath = di.FullName + ".oldGameLoader";
            di.MoveTo(newPath);

            CreateDirectoryJunction(outputPath, currentGame.Path);
            OnDoneEnablingGame(currentGame);
        }