コード例 #1
0
ファイル: SyncTask.cs プロジェクト: wesimon01/hakchi2
 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;
 }
コード例 #2
0
ファイル: SyncTask.cs プロジェクト: wesimon01/hakchi2
        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));
                }
            }
        }
コード例 #3
0
ファイル: SyncTask.cs プロジェクト: wesimon01/hakchi2
        // internal methods

        private void AddSymLinks(NesMenuCollection menuCollection, MemoryStream commandBuilder)
        {
            int    menuIndex       = stats.allMenus.IndexOf(menuCollection);
            string targetDirectory = string.Format("{0:D3}", menuIndex);

            foreach (var menuElement in menuCollection)
            {
                if (menuElement is NesApplication)
                {
                    NesApplication app = menuElement as NesApplication;

                    bool   hasAutoplayPixelArt = Directory.Exists(Path.Combine(app.BasePath, "autoplay")) || Directory.Exists(Path.Combine(app.BasePath, "autoplay"));
                    string src = $"{uploadPath}/.storage/{app.Code}";
                    string dst = $"{uploadPath}/{targetDirectory}/{app.Code}";

                    bool needLink = false;
                    if (ConfigIni.Instance.SyncLinked)
                    {
                        if (app.IsOriginalGame)
                        {
                            if (ConfigIni.Instance.AlwaysCopyOriginalGames)
                            {
                                if (hasAutoplayPixelArt)
                                {
                                    needLink = true;
                                }
                                else
                                {
                                    needLink = true;
                                }
                            }
                            else
                            {
                                if (hasAutoplayPixelArt)
                                {
                                    needLink = true;
                                }
                                else
                                {
                                    needLink = true;
                                    src      = $"{hakchi.SquashFsPath}{hakchi.GamesSquashFsPath}/{app.Code}";
                                }
                            }
                        }
                        else
                        {
                            if (hasAutoplayPixelArt)
                            {
                                needLink = true;
                            }
                            else
                            {
                                // needLink = false;
                            }
                        }
                    }
                    else
                    {
                        if (app.IsOriginalGame)
                        {
                            if (ConfigIni.Instance.AlwaysCopyOriginalGames)
                            {
                                if (hasAutoplayPixelArt)
                                {
                                    // needLink = false;
                                }
                                else
                                {
                                    // needLink = false;
                                }
                            }
                            else
                            {
                                if (hasAutoplayPixelArt)
                                {
                                    // needLink = false;
                                }
                                else
                                {
                                    needLink = true;
                                    src      = $"{hakchi.SquashFsPath}{hakchi.GamesSquashFsPath}/{app.Code}";
                                }
                            }
                        }
                        else
                        {
                            if (hasAutoplayPixelArt)
                            {
                                // needLink = false;
                            }
                            else
                            {
                                // needLink = false;
                            }
                        }
                    }

                    if (needLink)
                    {
                        string linkCode =
                            $"src=\"{src}\" && " +
                            $"dst=\"{dst}\" && " +
                            $"mkdir -p \"$dst\" && " +
                            $"rm -rf \"$dst/autoplay\" && " +
                            $"ln -s \"$src/autoplay\" \"$dst/\" ";
                        if (hakchi.HasPixelArt(ConfigIni.Instance.ConsoleType))
                        {
                            linkCode +=
                                $"&& rm -rf \"$dst/pixelart\" && " +
                                $"ln -s \"$src/pixelart\" \"$dst/\" ";
                        }
                        linkCode += "\n";
#if VERY_DEBUG
                        Trace.WriteLine(linkCode);
#endif
                        commandBuilder.Write(Encoding.UTF8.GetBytes(linkCode), 0, linkCode.Length);
                    }
                }
            }
        }
コード例 #4
0
 public GameCacheTask()
 {
     Games = new NesMenuCollection();
 }
コード例 #5
0
        private void AddMenu(NesMenuCollection menuCollection, Manager.BookManager.Page currentPage, Manager.BookManager.Book theBook)
        {
            pagePerCollection[menuCollection] = currentPage;
            processedPages.Add(menuCollection);
            foreach (var element in menuCollection)
            {
                if (element is NesMiniApplication)
                {
                    var app = element as NesMiniApplication;
                    Manager.BookManager.Entry entr = new Manager.BookManager.Entry();
                    entr.Emulator = app.GetEmulator();
                    if (_AppToRom.ContainsKey(app))
                    {
                        entr.Rom = _AppToRom[app];
                    }
                    if (_AppToCover.ContainsKey(app))
                    {
                        entr.Cover = _AppToCover[app];
                    }
                    entr.Label = app.Name;
                    currentPage.Entries.Add(entr);
                }
                if (element is NesMenuFolder)
                {
                    var folder = element as NesMenuFolder;
                    if (!pagePerCollection.ContainsKey(folder.ChildMenuCollection))
                    {
                        Manager.BookManager.Page  p    = theBook.AddPage(folder.Name);
                        Manager.BookManager.Entry entr = new Manager.BookManager.Entry();
                        entr.IsLink = true;
                        entr.Label  = folder.Name;
                        entr.PageId = p.Id;
                        currentPage.Entries.Add(entr);
                        AddMenu(folder.ChildMenuCollection, p, theBook);
                    }
                    else
                    {
                        Manager.BookManager.Entry entr = new Manager.BookManager.Entry();
                        entr.IsLink = true;
                        entr.Label  = folder.Name;
                        entr.PageId = pagePerCollection[folder.ChildMenuCollection].Id;
                        currentPage.Entries.Add(entr);
                    }

                    /*
                     *
                     * if (folder.ChildMenuCollection.Count() > 0)
                     * {
                     *  if (!processedPages.Contains(folder.ChildMenuCollection))
                     *  {
                     *      Manager.BookManager.Page p = theBook.AddPage(folder.Name);
                     *      Manager.BookManager.Entry entr = new Manager.BookManager.Entry();
                     *      entr.IsLink = true;
                     *      entr.Label = folder.Name;
                     *      entr.PageId = p.Id;
                     *      currentPage.Entries.Add(entr);
                     *      AddMenu(folder.ChildMenuCollection, p,currentPage, theBook);
                     *  }
                     * }
                     * else
                     * {
                     *  //Most likely a back, but not quite sure...
                     *  if(parent != null)
                     *  {
                     *      Manager.BookManager.Entry entr = new Manager.BookManager.Entry();
                     *      entr.IsLink = true;
                     *      entr.Label = folder.Name;
                     *      entr.PageId = parent.Id;
                     *      currentPage.Entries.Add(entr);
                     *  }
                     * }*/
                }
            }
        }
コード例 #6
0
        public override void Execute()
        {
            ReportStatus("Importing all selected games in library");
            IOrderedEnumerable <NesMiniApplication> selectedGames = Manager.GameManager.GetInstance().getSelectedGames();
            int processed         = 0;
            NesMenuCollection nmc = new NesMenuCollection();

            foreach (NesMiniApplication mn in selectedGames)
            {
                nmc.Add(mn);
                string localRom = System.IO.Path.Combine(mn.GamePath, mn.RomFile);
                if (!System.IO.Directory.Exists(TempRomFolder))
                {
                    System.IO.Directory.CreateDirectory(TempRomFolder);
                }
                string gameName = mn.Name;
                string fileName = System.IO.Path.GetFileNameWithoutExtension(mn.RomFile);
                string ext      = System.IO.Path.GetExtension(mn.RomFile);
                string destRom  = System.IO.Path.Combine(TempRomFolder, MakeValidFileName(gameName + ext));
                if (mn.RomFile.Trim() != "")
                {
                    System.IO.File.Copy(localRom, destRom);
                    _AppToRom[mn] = Manager.RomManager.getInstance().AddRom(destRom);


                    System.IO.File.Delete(destRom);
                }
                string coverExt = System.IO.Path.GetExtension(mn.IconPath);
                string destIcon = System.IO.Path.Combine(TempRomFolder, MakeValidFileName(gameName + coverExt));
                if (System.IO.File.Exists(mn.IconPath))
                {
                    if (System.IO.File.Exists(destIcon))
                    {
                        System.IO.File.Delete(destIcon);
                    }
                    System.IO.File.Copy(mn.IconPath, destIcon);
                    _AppToCover[mn] = Manager.CoverManager.getInstance().AddCover(destIcon);
                    System.IO.File.Delete(destIcon);
                }
                else
                {
                }
                processed++;
                ReportProgress(processed * 100 / selectedGames.Count());

                Console.Write(mn.RomFile);
            }

            ReportStatus("Loading folder structure");
            ReportProgress(0);
            if (ConfigIni.FoldersMode != NesMenuCollection.SplitStyle.Custom)
            {
                nmc.Split(ConfigIni.FoldersMode, ConfigIni.MaxGamesPerFolder);
            }
            else
            {
                FoldersManagerForm fm = new FoldersManagerForm(nmc, true);

                nmc.AddBack();
            }
            Manager.BookManager.Book theBook = Manager.BookManager.getInstance().GetBookByName("HakchiImport");
            theBook.Pages.Clear();
            Manager.BookManager.Page rootPage = theBook.AddPage("0");
            ReportStatus("Creating pages");
            AddMenu(nmc, rootPage, theBook);
            ReportCompleted();
        }