Example #1
0
        void _bgwUpdater_DoWork(object sender, DoWorkEventArgs e)
        {
            Logger.LogDisp.NewMessage(LogType.Info, "Started player DB update...");
            var lastModTime = (DateTime)e.Argument;
            var len = _db.AccPath.Length + 12;

            if (!Directory.Exists(_db.AccPath))
            {
                Logger.LogDisp.NewMessage(LogType.Error,"Can't find FL PlayerDB!");
                _areReadyToClose.Set();
                return;
            }

            if (StateChanged != null)
                StateChanged(DBStates.UpdatingFormFiles);

            // find all the newer savefiles, get the directory path, get unique directories
            // LINQ magic ;)
            var accDirs =
                new DirectoryInfo(_db.AccPath).GetFiles("??-????????.fl", SearchOption.AllDirectories)
                    .Where(d => d.LastWriteTime > lastModTime)
                    .Select(w => w.FullName.Substring(0, len))
                    .Distinct();

            // add there all the directories whose content had changed (new\del accounts, bans etc)
            accDirs = accDirs.Union(
                new DirectoryInfo(_db.AccPath).GetDirectories("??-????????")
                .Where(w => w.LastWriteTime > lastModTime)
                .Select(w => w.FullName));

            var enumerable = accDirs as IList<string> ?? accDirs.ToList();

            Logger.LogDisp.NewMessage(LogType.Info,
                "Update: found " + enumerable.Count() + " changed accounts.");

            if (StateChanged != null)
                StateChanged(DBStates.Updating);

            var i = 0;
            var count = enumerable.Count;

            // rescan stuff
            foreach (var accDir in enumerable)
            {
                if (_bgwUpdater.CancellationPending)
                {
                    _areReadyToClose.Set();
                    Logger.LogDisp.NewMessage(LogType.Info,"Update aborted.");
                    e.Cancel = true;
                    return;
                }
                LoadAccountDirectory(accDir);
                _bgwUpdater.ReportProgress(
                    (int)(
                    ((double)i / count)
                    * 100
                    ), _db.Queue.Count
                    );
                i++;
            }
            _areReadyToClose.Set();
            Logger.LogDisp.NewMessage(LogType.Info, "Player DB update finished.");
        }
        public ActionResult GetFilesList(string path)
        {
            path = GetSafeDirPath(path);
            var imagesList = new DirectoryInfo(path)
                                .GetFiles()
                                .Select(fileInfo => new KendoFile
                                {
                                    Name = fileInfo.Name,
                                    Size = fileInfo.Length,
                                    Type = KendoFileType
                                }).ToList();

            var foldersList = new DirectoryInfo(path)
                                .GetDirectories()
                                .Select(directoryInfo => new KendoFile
                                {
                                    Name = directoryInfo.Name,
                                    Type = KendoDirType
                                }).ToList();

            return new ContentResult
            {
                Content = JsonConvert.SerializeObject(imagesList.Union(foldersList), new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }),
                ContentType = "application/json",
                ContentEncoding = Encoding.UTF8
            };
        }