Ejemplo n.º 1
0
        public void Execute(string[] syncFiles)
        {
            m_invalidFiles.Clear();
            IEnumerable <string> diff = null;

            if (syncFiles == null)
            {
                IEnumerable <string> dsFiles = SyncDataSource.GetGameFileNames();
                IEnumerable <string> dbFiles = DbDataSource.GetGameFileNames();
                diff = dsFiles.Except(dbFiles);
            }
            else
            {
                diff = syncFiles;
            }

            SyncFileCount   = diff.Count();
            SyncFileCurrent = 0;

            foreach (string fileName in diff)
            {
                if (SyncFileChange != null)
                {
                    CurrentSyncFileName = fileName;
                    SyncFileChange(this, new EventArgs());
                }

                IGameFile file     = SyncDataSource.GetGameFile(fileName);
                IGameFile existing = DbDataSource.GetGameFile(file.FileName);

                if (existing != null)
                {
                    file = existing;
                }

                if (file != null)
                {
                    CurrentGameFile = file;
                    GameFileDataNeeded?.Invoke(this, new EventArgs());
                    file.Downloaded = DateTime.Now;

                    try
                    {
                        file.Map = GetMaps(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName));
                        if (!string.IsNullOrEmpty(file.Map))
                        {
                            file.MapCount = file.Map.Count(x => x == ',') + 1;
                        }
                    }
                    catch (IOException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "File is in use"));
                    }
                    catch (InvalidDataException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive contained an improper pk3"));
                    }
                    catch (Exception ex)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex)));
                    }

                    if (existing == null)
                    {
                        DbDataSource.InsertGameFile(file);
                    }
                    else
                    {
                        DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields());
                    }
                }
                else
                {
                    m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive"));

                    try
                    {
                        FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName));
                        if (fileDelete.Exists)
                        {
                            fileDelete.Delete();
                        }
                    }
                    catch
                    {
                        //delete failed, just keep going
                    }
                }

                SyncFileCurrent++;
            }
        }
Ejemplo n.º 2
0
        public void Execute(string[] zipFiles)
        {
            m_invalidFiles.Clear();

            SyncFileCount   = zipFiles.Length;
            SyncFileCurrent = 0;

            foreach (string fileName in zipFiles)
            {
                if (SyncFileChange != null)
                {
                    CurrentSyncFileName = fileName;
                    SyncFileChange(this, new EventArgs());
                }

                IGameFile file     = SyncDataSource.GetGameFile(fileName);
                IGameFile existing = DbDataSource.GetGameFile(file.FileName);

                if (existing != null)
                {
                    file = existing;
                }

                if (m_fileManagement == FileManagement.Unmanaged)
                {
                    file.FileName = fileName;
                }

                if (file != null)
                {
                    CurrentGameFile = file;
                    GameFileDataNeeded?.Invoke(this, new EventArgs());
                    file.Downloaded = DateTime.Now;

                    try
                    {
                        using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName)))
                        {
                            FillTextFileInfo(file, reader);
                            FillMapInfo(file, reader);
                        }
                    }
                    catch (IOException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "File is in use/Not found"));
                    }
                    catch (InvalidDataException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive invalid or contained an improper pk3"));
                    }
                    catch (Exception ex)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex)));
                    }

                    if (existing == null)
                    {
                        DbDataSource.InsertGameFile(file);
                    }
                    else
                    {
                        DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields());
                    }
                }
                else
                {
                    m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive"));

                    try
                    {
                        FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName));
                        if (fileDelete.Exists)
                        {
                            fileDelete.Delete();
                        }
                    }
                    catch
                    {
                        //delete failed, just keep going
                    }
                }

                SyncFileCurrent++;
            }
        }