Exemplo n.º 1
0
        private Track PeekLocalZipFile(string fileName, Track track, ZipFileEntryDelegate zipHandler)
        {
            using (ZipArchive archive = ZipFile.OpenRead(fileName))
            {
                track = ValidateZipArchive(archive, track, zipHandler);
            }

            return(track);
        }
Exemplo n.º 2
0
        private Track PeekZipFile(string url, Track track, ZipFileEntryDelegate zipHandler)
        {
            using (WebClient client = new WebClient())
            {
                using (Stream memoryStream = new MemoryStream(client.DownloadData(url)))
                {
                    using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                    {
                        track = ValidateZipArchive(archive, track, zipHandler);
                    }
                }
            }

            return(track);
        }
Exemplo n.º 3
0
        public Track ValidateLocalTrack(string fileName, Track track, ZipFileEntryDelegate zipHandler)
        {
            string ext = Path.GetExtension(fileName);

            //We can only run automation on zip files. .rar is a closed format and not accepted.
            if (ext == ".zip")
            {
                track = PeekLocalZipFile(fileName, track, zipHandler);
            }
            else
            {
                track.ErrorInfo += string.Format("Expected .zip file, got {0} file; ", ext);
                track.Valid      = false;
            }

            return(track);
        }
Exemplo n.º 4
0
        public Track ValidateTrack(Track track, ZipFileEntryDelegate zipHandler)
        {
            string ext = Path.GetExtension(track.SourceTrackUrl);

            //We can only run automation on zip files. .rar is a closed format and not accepted.
            if (ext == ".zip")
            {
                track = PeekZipFile(track.SourceTrackUrl, track, zipHandler);
            }
            else if (track.SourceTrackUrl.Contains("drive.google.com"))
            {
                track.ErrorInfo += string.Format("Files are saved on google drive which is not supported; ", ext);
                track.Valid      = false;
            }
            else
            {
                track.ErrorInfo += string.Format("Expected .zip file, got {0} file; ", ext);
                track.Valid      = false;
            }

            return(track);
        }
Exemplo n.º 5
0
        private Track ValidateZipArchive(ZipArchive archive, Track track, ZipFileEntryDelegate zipHandler)
        {
            int databaseCount = 0;
            int levelCount    = 0;
            int packageCount  = 0;
            int sceneCount    = 0;

            string databaseExt = ".dx9.database";
            string levelExt    = ".dx9.level";
            string packageExt  = ".dx9.package";
            string sceneExt    = ".dx9.scene";

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.Name.EndsWith(databaseExt, StringComparison.OrdinalIgnoreCase))
                {
                    if (track.TrackType == TrackType.Unknown)
                    {
                        track.TrackType  = GetTrackType(entry.Name);
                        track.SlotNumber = GetSlot(entry.Name);
                    }
                    ++databaseCount;
                    if (databaseCount == 1)
                    {
                        zipHandler(entry);
                    }
                }
                else if (entry.Name.EndsWith(levelExt, StringComparison.OrdinalIgnoreCase))
                {
                    ++levelCount;
                    if (levelCount == 1)
                    {
                        zipHandler(entry);
                    }
                }
                else if (entry.Name.EndsWith(packageExt, StringComparison.OrdinalIgnoreCase))
                {
                    ++packageCount;
                    if (packageCount == 1)
                    {
                        zipHandler(entry);
                    }
                }
                else if (entry.Name.EndsWith(sceneExt, StringComparison.OrdinalIgnoreCase))
                {
                    ++sceneCount;
                    if (sceneCount == 1)
                    {
                        zipHandler(entry);
                    }
                }
            }

            if (track.TrackType == TrackType.Unknown)
            {
                track.ErrorInfo += "Unknown track type; ";
                track.Valid      = false;
            }

            if (track.SlotNumber == 0)
            {
                track.ErrorInfo += "Unknown slot; ";
                track.Valid      = false;
            }

            track = CheckForRequiredFiles(track, databaseExt, databaseCount);
            track = CheckForRequiredFiles(track, levelExt, levelCount);
            track = CheckForRequiredFiles(track, packageExt, packageCount);
            track = CheckForRequiredFiles(track, sceneExt, sceneCount);

            return(track);
        }