/// <summary>
        /// Extracts the contents of a zip file and uploads the contents into a single directory
        /// </summary>
        private async Task UploadZipAsync(IFormFile uploadedFile, ContentFileType fileType)
        {
            ZipArchive archive = new ZipArchive(uploadedFile.OpenReadStream(), ZipArchiveMode.Read);
            Dictionary <string, Stream> contents = new Dictionary <string, Stream>();

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                string fileName = WebUtility.UrlEncode(Path.GetFileName(entry.Name));
                contents[fileName] = entry.Open();
            }

            Dictionary <string, Uri> fileUrls = await FileManager.UploadBlobsAsync(contents, Event.ID);

            foreach (KeyValuePair <string, Uri> fileUrl in fileUrls)
            {
                ContentFile file = new ContentFile()
                {
                    ShortName = fileUrl.Key,
                    Puzzle    = Puzzle,
                    Event     = Event,
                    FileType  = fileType,
                    Url       = fileUrl.Value,
                };
                _context.ContentFiles.Add(file);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Helper for taking an uploaded form file, uploading it, and tracking it in the database
        /// </summary>
        private async Task UploadFileAsync(IFormFile uploadedFile, ContentFileType fileType)
        {
            ContentFile file     = new ContentFile();
            string      fileName = WebUtility.UrlEncode(Path.GetFileName(uploadedFile.FileName));

            file.ShortName = fileName;
            file.Puzzle    = Puzzle;
            file.Event     = Event;
            file.FileType  = fileType;

            file.Url = await FileManager.UploadBlobAsync(fileName, Event.ID, uploadedFile.OpenReadStream());

            _context.ContentFiles.Add(file);
        }
        private void SeedContentFileType(AdirContext context)
        {
            var welfare = new ContentFileType()
            {
                Name = "Welfare"
            };

            var disease = new ContentFileType()
            {
                Name = "Disease"
            };

            context.ContentFileTypes.AddOrUpdate(c => c.Name, welfare);
            context.ContentFileTypes.AddOrUpdate(c => c.Name, disease);

            context.SaveChanges();
        }
Beispiel #4
0
        protected override void Seed(BAI.Adir.Api.Domain.Context.AdirContext context)
        {
            var welfare = new ContentFileType()
            {
                Name = "Welfare"
            };

            var disease = new ContentFileType()
            {
                Name = "Disease"
            };

            context.ContentFileTypes.AddOrUpdate(c => c.Name, welfare);
            context.ContentFileTypes.AddOrUpdate(c => c.Name, disease);

            context.SaveChanges();
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }
Beispiel #5
0
        /// <summary>
        /// Helper for taking an uploaded form file, uploading it, and tracking it in the database
        /// </summary>
        private async Task UploadFileAsync(IFormFile uploadedFile, ContentFileType fileType)
        {
            if ((fileType == ContentFileType.PuzzleMaterial || fileType == ContentFileType.SolveToken) &&
                Path.GetExtension(uploadedFile.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase) && ExpandZipFiles)
            {
                await UploadZipAsync(uploadedFile, fileType);

                return;
            }

            ContentFile file     = new ContentFile();
            string      fileName = WebUtility.UrlEncode(Path.GetFileName(uploadedFile.FileName));

            file.ShortName = fileName;
            file.Puzzle    = Puzzle;
            file.Event     = Event;
            file.FileType  = fileType;

            file.Url = await FileManager.UploadBlobAsync(fileName, Event.ID, uploadedFile.OpenReadStream());

            _context.ContentFiles.Add(file);
        }
Beispiel #6
0
        /// <summary>
        /// Extracts the contents of a zip file and uploads the contents into a single directory
        /// </summary>
        private async Task UploadZipAsync(IFormFile uploadedFile, ContentFileType fileType)
        {
            ZipArchive archive = new ZipArchive(uploadedFile.OpenReadStream(), ZipArchiveMode.Read);
            Dictionary <string, Stream> contents = new Dictionary <string, Stream>();

            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                if (entry.FullName.EndsWith("/"))
                {
                    continue;
                }

                if (entry.FullName.StartsWith("/") || entry.FullName.StartsWith("\\") || entry.FullName.Contains(".."))
                {
                    throw new ArgumentException();
                }

                string fileName = entry.FullName;
                contents[fileName] = entry.Open();
            }

            Dictionary <string, Uri> fileUrls = await FileManager.UploadBlobsAsync(contents, Event.ID);

            foreach (KeyValuePair <string, Uri> fileUrl in fileUrls)
            {
                ContentFile file = new ContentFile()
                {
                    ShortName = fileUrl.Key,
                    Puzzle    = Puzzle,
                    Event     = Event,
                    FileType  = fileType,
                    Url       = fileUrl.Value,
                };
                _context.ContentFiles.Add(file);
            }
        }
Beispiel #7
0
 internal KnowledgeEntry(int id, ContentFileType type, int param, string text)
 {
     this.id = id;
      this.type = type;
      this.param = param;
      this.text = text;
 }
Beispiel #8
0
 protected BasicResource()
 {
     Type = ContentFileType.FileUnknown;
 }
Beispiel #9
0
			public void Read(BlamLib.IO.EndianReader s)
			{
				Unknown000 = s.ReadUInt64();
				Name = s.ReadUnicodeString(16);
				Description = s.ReadAsciiString(128);
				Author = s.ReadAsciiString(16);
				FileType = (ContentFileType)s.ReadUInt32();
				Unknown0BC = s.ReadInt32() > 0;
				Unknown0C0 = s.ReadUInt64();
				ContentLength = s.ReadUInt64();
				Unknown0D0 = s.ReadUInt64();
				Unknown0D8 = s.ReadInt32();
				MapId.Read(s);
				GameEngineType = s.ReadInt32();
				CampaignDifficulty = s.ReadInt32();
				HopperId = (ushort)((s.ReadUInt32() & 0xFFFF0000) >> 16);
				GameId = s.ReadUInt64();
			}
Beispiel #10
0
        private static BasicResource CreateResource(int index)
        {
            WarResource resource = rawResources[index];

            KnowledgeEntry ke = KnowledgeBase[index];

            ContentFileType fileType = ContentFileType.FileUnknown;

            if (ke != null)
            {
                fileType = ke.type;
            }

            switch (fileType)
            {
            case ContentFileType.FileCursor:
            {
                WarResource palRes = null;
                if (ke != null)
                {
                    palRes = rawResources[ke.param];
                }

                return(new CursorResource(resource, palRes));
            }

            case ContentFileType.FileImage:
            {
                WarResource palRes = null;
                if (ke != null)
                {
                    palRes = rawResources[ke.param];
                }

                return(new ImageResource(resource, palRes, rawResources[191]));
            }

            case ContentFileType.FileLevelInfo:
                return(new LevelInfoResource(resource));

            case ContentFileType.FileLevelPassable:
                return(new LevelPassableResource(resource));

            case ContentFileType.FileLevelVisual:
                return(new LevelVisualResource(resource));

            case ContentFileType.FilePalette:
                return(new PaletteResource(resource));

            case ContentFileType.FilePaletteShort:
                return(new PaletteResource(resource));

            case ContentFileType.FileSprite:
            {
                WarResource palRes = null;
                if (ke != null)
                {
                    palRes = rawResources[ke.param];
                }

                return(new SpriteResource(resource, palRes, rawResources[191]));
            }

            case ContentFileType.FileTable:
                return(new TableResource(resource));

            case ContentFileType.FileText:
                return(new TextResource(resource));

            case ContentFileType.FileTiles:
                return(new RawResource(resource, ContentFileType.FileTiles));

            case ContentFileType.FileTileSet:
                return(new RawResource(resource, ContentFileType.FileTileSet));

            case ContentFileType.FileUI:
                return(new UIResource(resource));

            case ContentFileType.FileVOC:
                return(new RawResource(resource, ContentFileType.FileVOC));

            case ContentFileType.FileWave:
                return(new RawResource(resource, ContentFileType.FileWave));

            case ContentFileType.FileXMID:
                return(new RawResource(resource, ContentFileType.FileXMID));

            default:
                return(new RawResource(resource, ContentFileType.FileUnknown));
            }
        }
Beispiel #11
0
        internal RawResource(WarResource setResource, ContentFileType fileType)
        {
            Type = fileType;

            Resource = setResource;
        }