Ejemplo n.º 1
0
 public Tasker.Conclusion ShowExportDialog(Tasker tasker, Object syncObject = null)
 {
     if (tasker.HostForm.Disposing)
     {
         return(Tasker.Conclusion.Undefined);
     }
     if (tasker.HostForm.InvokeRequired)
     {
         return((Tasker.Conclusion)tasker.HostForm.Invoke(new Func <Tasker, Object, Tasker.Conclusion>(ShowExportDialog), new object[] { tasker, syncObject }));
     }
     tasker.SetStatus(Resources.SelectDrive);
     try
     {
         using (ExportGamesDialog driveSelectDialog = new ExportGamesDialog())
         {
             tasker.PushState(Tasker.State.Paused);
             var result = driveSelectDialog.ShowDialog() == DialogResult.OK;
             tasker.PopState();
             if (!result)
             {
                 return(Tasker.Conclusion.Abort);
             }
             this.exportLinked    = driveSelectDialog.LinkedExport;
             this.exportDirectory = driveSelectDialog.ExportPath;
             if (!Directory.Exists(driveSelectDialog.ExportPath))
             {
                 Directory.CreateDirectory(driveSelectDialog.ExportPath);
             }
         }
         copyMode = exportLinked ? NesApplication.CopyMode.LinkedExport : NesApplication.CopyMode.Export;
         return(Tasker.Conclusion.Success);
     }
     catch (InvalidOperationException) { }
     return(Tasker.Conclusion.Abort);
 }
Ejemplo n.º 2
0
 public SyncTask()
 {
     Games           = new NesMenuCollection();
     exportDirectory = string.Empty;
     uploadPath      = string.Empty;
     exportLinked    = false;
     stats           = new GamesTreeStats();
     localGameSet    = new HashSet <ApplicationFileInfo>();
     transferGameSet = null;
     copyMode        = ConfigIni.Instance.SyncLinked ? NesApplication.CopyMode.LinkedSync : NesApplication.CopyMode.Sync;
 }
Ejemplo n.º 3
0
        private void AddMenu(NesMenuCollection menuCollection, NesApplication.CopyMode copyMode, HashSet <ApplicationFileInfo> localGameSet = null, GamesTreeStats stats = null)
        {
            if (stats == null)
            {
                stats = new GamesTreeStats();
            }
            if (!stats.allMenus.Contains(menuCollection))
            {
                stats.allMenus.Add(menuCollection);
            }
            int    menuIndex       = stats.allMenus.IndexOf(menuCollection);
            string targetDirectory = string.Format("{0:D3}", menuIndex);

            foreach (var element in menuCollection)
            {
                if (element is NesApplication)
                {
                    var game = element as NesApplication;

                    // still use temp directory for game genie games
                    try
                    {
                        if (game is ISupportsGameGenie && File.Exists(game.GameGeniePath))
                        {
                            string tempPath = Path.Combine(tempDirectory, game.Desktop.Code);
                            Shared.EnsureEmptyDirectory(tempPath);
                            NesApplication gameCopy = game.CopyTo(tempDirectory);
                            (gameCopy as ISupportsGameGenie).ApplyGameGenie();
                            game = gameCopy;
                        }
                    }
                    catch (GameGenieFormatException ex)
                    {
                        Trace.WriteLine(string.Format(Resources.GameGenieFormatError, ex.Code, game.Name));
                    }
                    catch (GameGenieNotFoundException ex)
                    {
                        Trace.WriteLine(string.Format(Resources.GameGenieNotFound, ex.Code, game.Name));
                    }

                    long gameSize = game.Size();
                    Trace.WriteLine(string.Format("Processing {0} ('{1}'), size: {2}KB", game.Code, game.Name, gameSize / 1024));
                    gameSize            = game.CopyTo(targetDirectory, localGameSet, copyMode);
                    stats.TotalSize    += gameSize;
                    stats.TransferSize += gameSize;
                    stats.TotalGames++;
                }
                if (element is NesMenuFolder)
                {
                    var folder = element as NesMenuFolder;
                    if (folder.Name == Resources.FolderNameTrashBin)
                    {
                        continue; // skip recycle bin!
                    }
                    if (folder.ChildMenuCollection.Count == 1 && folder.ChildMenuCollection[0].Name == Resources.FolderNameBack)
                    {
                        continue; // skip empty folders
                    }
                    if (!stats.allMenus.Contains(folder.ChildMenuCollection))
                    {
                        stats.allMenus.Add(folder.ChildMenuCollection);
                        AddMenu(folder.ChildMenuCollection, copyMode, localGameSet, stats);
                    }
                    folder.ChildIndex = stats.allMenus.IndexOf(folder.ChildMenuCollection);

                    long folderSize = folder.CopyTo(targetDirectory, localGameSet);
                    stats.TotalSize    += folderSize;
                    stats.TransferSize += folderSize;
                    Trace.WriteLine(string.Format("Processed folder {0} ('{1}'), size: {2}KB", folder.Code, folder.Name, folderSize / 1024));
                }
            }
        }