Пример #1
0
 void ProcessFiles(string msg)
 {
     lock (_locker) if (_inBatch)
         {
             return;
         }
     //Open the folder and keep going until there are any files left
     //Skip any locked files
     try {
         if (LockPath(_inputFolder))
         {
             Log.Debug("{0} ({1}\\{2})", msg, _inputFolder, _info.Filter);
             StartBatch();
             FileSystemEnumerator fse = new FileSystemEnumerator(_inputFolder, _info.Filter ?? "*", includeSubDirs: false);
             int i = 0;
             foreach (FileInfo f in fse.Matches())
             {
                 if (!IsLocked(f.FullName))
                 {
                     EnqueueFile(f.FullName, f.Name);
                     ++i;
                 }
             }
             Log.Debug("{0} - enqueued {1} files", msg, i);
             StopBatch();
             UnlockPath(_inputFolder);
         }
     } catch (Exception e) {
         Log.Error("Exception processing files. ERROR: {0}", e.ToString().Replace("\n", " "));
     }
 }
Пример #2
0
        /// <summary>
        /// Finds all files within the CSData folder and loads them to memory
        /// </summary>
        /// <returns>Lazy loading coroutine, loading on demand</returns>
        private IEnumerator FindAllFiles()
        {
            string localPath = CSUtils.CSDataPath;

            Log($"Locating all files in CSData folder (@{localPath})");
            //Locate data folder
            if (!Directory.Exists(localPath))
            {
                Debug.LogWarning(DebugPrefix + "CSData folder could not be located. Creating new one.");
                Directory.CreateDirectory(localPath);
                yield break; //Created folder will be empty
            }

            //Enumerate through all files in all the folders starting at the root folder
            using (FileSystemEnumerator e = new FileSystemEnumerator(localPath, "*", true))
            {
                //Loop through all "normal" files
                foreach (FileInfo file in e.Matches().Where(f => f.Attributes == FileAttributes.Normal && !string.IsNullOrEmpty(f.Extension)))
                {
                    this.loadingbar.SetLabel("Locating file " + file.FullName);
                    List <FileInfo> files;
                    string          jsonExt = Path.GetExtension(file.Name);

                    //If there is a secondary extension, assume it's a potential Json file
                    if (!string.IsNullOrEmpty(jsonExt))
                    {
                        Dictionary <string, List <FileInfo> > jsonFiles;
                        if (!this.jsonFilesByExt.TryGetValue(file.Extension, out jsonFiles))
                        {
                            jsonFiles = new Dictionary <string, List <FileInfo> >();
                            this.jsonFilesByExt.Add(file.Extension, jsonFiles);
                        }
                        if (!jsonFiles.TryGetValue(jsonExt, out files))
                        {
                            files = new List <FileInfo>();
                            jsonFiles.Add(jsonExt, files);
                        }
                        files.Add(file);
                    }

                    //If .dll file
                    if (file.Extension == ".dll")
                    {
                        this.dlls.Add(file);
                    }

                    //Add to normal extension dict
                    if (!this.filesByExt.TryGetValue(file.Extension, out files))
                    {
                        files = new List <FileInfo>();
                        this.filesByExt.Add(file.Extension, files);
                    }
                    files.Add(file);
                    this.allFiles.Add(file);

                    Log("Located " + file.FullName);
                    yield return(null);
                }
            }
        }