Exemplo n.º 1
0
    private void ScanFilesAsynchronously()
    {
        Debug.Log("ScanFilesAsynchronously");

        List <string> txtFiles;

        lock (scanLock)
        {
            SongsFound   = 0;
            SongsSuccess = 0;
            SongsFailed  = 0;

            FolderScanner scannerTxt = new FolderScanner("*.txt");

            // Find all txt files in the song directories
            txtFiles = ScanForTxtFiles(scannerTxt);
        }

        // Load the txt files in a background thread
        ThreadPool.QueueUserWorkItem(poolHandle =>
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            Debug.Log("Started song-scan-thread.");
            lock (scanLock)
            {
                LoadTxtFiles(txtFiles);
                isSongScanFinished = true;
            }
            stopwatch.Stop();
            Debug.Log($"Finished song-scan-thread after {stopwatch.ElapsedMilliseconds} ms.");
            songScanFinishedEventStream.OnNext(new SongScanFinishedEvent());
        });
    }
Exemplo n.º 2
0
    private static void ScanSongFilesAsThread()
    {
        SetSongScanStatus("Initializing scan of song information files...");
        FolderScanner scannerTxt = new FolderScanner("*.txt");
        List <string> txtFiles   = new List <string>();

        SetSongScanStatus("Scanning for matching file names in songs folder...");
        txtFiles = scannerTxt.GetFiles((string)SettingsManager.GetSetting(ESetting.SongDir));
        SetSongScanStatus(String.Format("Discovered a total of {0} possible song data files...", txtFiles.Count));
        int counter = 0;

        txtFiles.ForEach(delegate(string path)
        {
            counter += 1;
            SetSongScanStatus(String.Format("Scanning file {0} of {1} possible song data files...", counter, txtFiles.Count));
            try
            {
                if (SongParser.ParseSongFile(path))
                {
                    Debug.Log("success::" + path);
                }
                else
                {
                    Debug.Log("nope::" + path);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            SetSongScanStatus("Song files scan finished.");
        });
    }
Exemplo n.º 3
0
 private static void ScanFilesAsThread()
 {
     lock (s_scanLock)
     {
         s_songsFound = 0;
         s_songsSuccess = 0;
         s_songsFailed = 0;
         FolderScanner scannerTxt = new FolderScanner("*.txt");
         List<string> txtFiles = scannerTxt.GetFiles((string)SettingsManager.GetSetting(ESetting.SongDir));
         s_songsFound = txtFiles.Count;
         txtFiles.ForEach(delegate (string path)
         {
             try
             {
                 Add(SongMetaBuilder.ParseFile(path));
                 Interlocked.Increment(ref s_songsSuccess);
             }
             catch (SongMetaBuilderException e)
             {
                 Debug.Log("nope::"+path+"\n"+e.Message);
                 Interlocked.Increment(ref s_songsFailed);
             }
             catch (Exception ex)
             {
                 Debug.LogException(ex);
                 Debug.Log("nope::" + path);
                 Interlocked.Increment(ref s_songsFailed);
             }
         });
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button3_Click(object sender, EventArgs e)
 {
     FileManager.SearchForInstalledVersions(model);
     FolderScanner.GetGameInformation(null, "", "");
     CemuFeatures.UpdateFeaturesForInstalledVersions(model);
     autoSize = false;
     PopulateList();
 }
Exemplo n.º 5
0
        public void ReadInvalidFolderPath()
        {
            var mockLogger = new Mock <ILogger <CSVProcessor> >();

            FolderScanner       folderScanner = new FolderScanner(this.logger, this.invalidConfig);
            List <FoundCSVItem> filesFound    = null;

            Assert.DoesNotThrow(() => filesFound = folderScanner.FindCSVFiles());
            Assert.True(filesFound.Count == 0);
        }
Exemplo n.º 6
0
        public void ReturnedFolderScannerTest()
        {
            // Arrange
            Creator        creator = new Creator();
            IFolderScanner scannerTest;
            FolderScanner  expScanner = new FolderScanner();

            // Act
            scannerTest = creator.GetScanner();

            // Assert
            Assert.IsInstanceOf(expScanner.GetType(), scannerTest);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="file"></param>
        /// <param name="xElement"></param>
        private void ReadMetaData(string folder, string file, XElement xElement)
        {
            var productCode = Xml.GetValue(xElement, "product_code");

            if (productCode != null)
            {
                var companyCode = Xml.GetValue(xElement, "company_code");
                if (companyCode != null)
                {
                    string key = productCode.Replace("WUP-P-", "").Replace("WUP-U-", "").Replace("WUP-N-", "") + companyCode;

                    GameInformation game;

                    if (!gameData.ContainsKey(key))
                    {
                        game = new GameInformation {
                            GameSetting = new GameSettings()
                        };
                        gameData.Add(key, game);
                        game.Name           = Xml.GetValue(xElement, "longname_en").Replace("\n", " ");
                        game.Region         = Nintendo.GetRegion(Xml.GetValue(xElement, "region"));
                        game.Publisher      = Xml.GetValue(xElement, "publisher_en");
                        game.ProductCode    = productCode;
                        game.CompanyCode    = companyCode;
                        game.TitleId        = Xml.GetValue(xElement, "title_id").ToUpper();
                        game.GroupId        = Xml.GetValue(xElement, "group_id").ToUpper();
                        game.Size           = (FolderScanner.GetDirectorySize(folder) / 1024 / 1024).ToString("N0") + " MB";
                        game.LaunchFile     = file;
                        game.LaunchFileName = Path.GetFileName(file);
                    }
                    else
                    {
                        game                = gameData[key];
                        game.Name           = Xml.GetValue(xElement, "longname_en").Replace("\n", " ");
                        game.Region         = Nintendo.GetRegion(Xml.GetValue(xElement, "region"));
                        game.Publisher      = Xml.GetValue(xElement, "publisher_en");
                        game.ProductCode    = productCode;
                        game.CompanyCode    = companyCode;
                        game.TitleId        = Xml.GetValue(xElement, "title_id").ToUpper();
                        game.GroupId        = Xml.GetValue(xElement, "group_id").ToUpper();
                        game.LaunchFile     = file;
                        game.LaunchFileName = Path.GetFileName(file);
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void oldVersionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var toolStripMenuItem = sender as ToolStripMenuItem;

            if (toolStripMenuItem != null)
            {
                OldVersion oldVersion = toolStripMenuItem.Tag as OldVersion;
                if (oldVersion != null)
                {
                    unpacker.DownloadAndUnpack(oldVersion.Name + ".zip", oldVersion.Uri, model.Settings.DefaultInstallFolder, oldVersion.Name);
                    FileManager.SearchForInstalledVersions(model);
                    FolderScanner.GetGameInformation(null, "", "");
                    CemuFeatures.UpdateFeaturesForInstalledVersions(model);
                }
                AddOldGameMenuItems();
                PopulateList();
            }
        }
Exemplo n.º 9
0
        public frmFileFolderSelectionDialog(string localPathToScan)
            : this()
        {
            FolderScanner scanner  = new FolderScanner();
            SysFileItem   rootItem = scanner.ScanFolder(localPathToScan);

            if (rootItem != null)
            {
                listBox1.BeginUpdate();

                foreach (SysFileItem item in rootItem.AssociatedItems)
                {
                    listBox1.Items.Add(item);
                }

                listBox1.EndUpdate();
            }
        }
Exemplo n.º 10
0
        public void CheckScopeResourceFilesTest()
        {
            var configuration = new LocalizationConfiguration
            {
                BasePath          = "Localization",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("cs"),
                    new CultureInfo("en"),
                    new CultureInfo("es"),
                },
            };


            var folderScanner = new FolderScanner(JsonDictionaryFactory.FactoryInstance);

            folderScanner.CheckResourceFiles(configuration);
        }
Exemplo n.º 11
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Epub data parser");
            Console.WriteLine("****************");

            Console.WriteLine("Default path: " + TestEpubFolder);
            Console.WriteLine("Folder (empty to keep default): ");
            var folderToUse = Console.ReadLine();

            System.Console.WriteLine($"User input: {folderToUse}");
            folderToUse = !string.IsNullOrWhiteSpace(folderToUse) ? folderToUse : TestEpubFolder;

            var files = new FolderScanner().GetEpubFilesFromFolder(folderToUse);

            System.Console.WriteLine($"Retrieved {files.Count} files");

            //Read and parse files
            var parser      = new EpubFileParser();
            var epubDetails = files.Select(f => parser.GetDataFromFile(f)).ToList();

            EchoToOutput(epubDetails);

            if (AskConfirmOnAction("Perform database actions?"))
            {
                var compareHelper  = new DatabaseComparisonHelper(new BookLogicApiHandler(Secrets.ApiLocation));
                var compareResults = compareHelper.CompareSetWithDatabase(epubDetails);
                compareHelper.EchoComparisonSetDetails(compareResults);

                //Check if we want and need to take action to save new and/or existing items
                if (compareResults.NewItems.Any() && AskConfirmOnAction("Store new books to database?"))
                {
                    await compareHelper.SaveNewItems(compareResults);
                }

                if (compareResults.ExistingItems.Any() && AskConfirmOnAction("Overwrite existing books to database?"))
                {
                    await compareHelper.SaveExistingItems(compareResults);
                }
            }
            //if(AskConfirmOnAction("Write output file?")) { WriteOutputFile(epubDetails); }
        }
Exemplo n.º 12
0
    private void ScanFilesSynchronously()
    {
        lock (scanLock)
        {
            SongsFound   = 0;
            SongsSuccess = 0;
            SongsFailed  = 0;
            FolderScanner scannerTxt = new FolderScanner("*.txt");

            // Find all txt files in the song directories
            List <string> txtFiles = new List <string>();
            List <string> songDirs = SettingsManager.Instance.Settings.GameSettings.songDirs;
            foreach (string songDir in songDirs)
            {
                List <string> txtFilesInSongDir = scannerTxt.GetFiles(songDir);
                txtFiles.AddRange(txtFilesInSongDir);
            }
            SongsFound = txtFiles.Count;
            Debug.Log($"Found {SongsFound} songs in {songDirs.Count} configured song directories");

            txtFiles.ForEach(delegate(string path)
            {
                try
                {
                    Add(SongMetaBuilder.ParseFile(path));
                    SongsSuccess++;
                }
                catch (SongMetaBuilderException e)
                {
                    Debug.LogWarning(path + "\n" + e.Message);
                    SongsFailed++;
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    Debug.LogError(path);
                    SongsFailed++;
                }
            });
        }
    }
Exemplo n.º 13
0
    private void ScanPlaylistFolder()
    {
        playlists             = new List <UltraStarPlaylist>();
        playlistToFilePathMap = new Dictionary <UltraStarPlaylist, string>();

        FolderScanner scanner           = new FolderScanner("*" + playlistFileExtension);
        List <string> playlistFilePaths = scanner.GetFiles(playlistFolder);

        foreach (string filePath in playlistFilePaths)
        {
            UltraStarPlaylist playlist = UltraStarPlaylistParser.ParseFile(filePath);
            playlists.Add(playlist);
            playlistToFilePathMap.Add(playlist, filePath);

            // This is the special playlist for the favorite songs.
            if (Path.GetFullPath(favoritesPlaylistFile) == Path.GetFullPath(filePath))
            {
                favoritesPlaylist = playlist;
            }
        }
    }
Exemplo n.º 14
0
    private List <string> ScanForTxtFiles(FolderScanner scannerTxt)
    {
        List <string> txtFiles = new List <string>();
        List <string> songDirs = SettingsManager.Instance.Settings.GameSettings.songDirs;

        foreach (string songDir in songDirs)
        {
            try
            {
                List <string> txtFilesInSongDir = scannerTxt.GetFiles(songDir);
                txtFiles.AddRange(txtFilesInSongDir);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        SongsFound = txtFiles.Count;
        Debug.Log($"Found {SongsFound} songs in {songDirs.Count} configured song directories");
        return(txtFiles);
    }
Exemplo n.º 15
0
        public void ConstructResourceFileName()
        {
            var configuration = new LocalizationConfiguration
            {
                BasePath          = "Localization",
                DefaultCulture    = new CultureInfo("cs"),
                SupportedCultures = new List <CultureInfo>
                {
                    new CultureInfo("cs"),
                    new CultureInfo("en"),
                    new CultureInfo("es"),
                },
            };


            var folderScanner = new FolderScanner(JsonDictionaryFactory.FactoryInstance);
            var fileName      = folderScanner.ConstructResourceFileName(
                configuration, Path.Combine("Localization", "slovniky"), new CultureInfo("cs"), JsonLocalizationDictionary.JsonExtension
                );

            Assert.AreEqual(Path.GetFullPath("Localization/slovniky/slovniky.cs.json"), Path.GetFullPath(fileName));
        }
Exemplo n.º 16
0
        private IEnumerable <IProjectFile> GetDesignModelFiles()
        {
            if (string.IsNullOrWhiteSpace(_designModelFolders))
            {
                yield break;
            }

            if (string.IsNullOrWhiteSpace(SourceFolder))
            {
                throw new ConfigurationException("Source folder must be set.");
            }

            var scanner = new FolderScanner(Path.GetFullPath(SourceFolder));

            foreach (var folder in scanner.Scan(_designModelFolders))
            {
                foreach (var file in Directory.EnumerateFiles(folder, "*.xml", SearchOption.AllDirectories))
                {
                    var relativePath = PathUtils.GetRelativePath(SourceFolder, file);

                    yield return(new ProjectFile(this, relativePath));
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Check for resource files base on folders structure in basePath.
        /// </summary>
        /// <param name="configuration">Library configuration.</param>
        /// <param name="dictionaryFactory"></param>
        /// <returns>List of resource files to load.</returns>
        private IEnumerable <string> CheckResourceFiles(LocalizationConfiguration configuration, IDictionaryFactory dictionaryFactory)
        {
            var fs = new FolderScanner(dictionaryFactory);

            return(fs.CheckResourceFiles(configuration));
        }