Esempio n. 1
0
        private static IEnumerable <object[]> GetMapTriggersDataSpecificFormatVersion(MapTriggersFormatVersion?formatVersion)
        {
            foreach (var testData in GetMapTriggersData())
            {
                using var original = FileProvider.GetFile((string)testData[0]);
                using var reader   = new BinaryReader(original);

                if (original.Length >= 8)
                {
                    if (reader.ReadInt32() == MapTriggers.FileFormatSignature)
                    {
                        var actualVersion = (MapTriggersFormatVersion?)reader.ReadInt32();
                        if (!Enum.IsDefined(typeof(MapTriggersFormatVersion), actualVersion))
                        {
                            actualVersion = null;
                        }

                        if (formatVersion == actualVersion)
                        {
                            yield return(testData);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void TestParseCampaignUnitObjectData(string campaignUnitObjectDataFilePath)
        {
            using var original  = FileProvider.GetFile(campaignUnitObjectDataFilePath);
            using var recreated = new MemoryStream();

            CampaignUnitObjectData.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true, true);
        }
Esempio n. 3
0
        public void TestParseMapDoodads(string mapDoodadsFilePath)
        {
            using var original  = FileProvider.GetFile(mapDoodadsFilePath);
            using var recreated = new MemoryStream();

            MapDoodads.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
        private static void TestParseMapCustomTextTriggers(string mapCustomTextTriggersFilePath)
        {
            using var original  = FileProvider.GetFile(mapCustomTextTriggersFilePath);
            using var recreated = new MemoryStream();

            MapCustomTextTriggers.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
Esempio n. 5
0
        public void TestParseMapEnvironment(string environmentFilePath)
        {
            using var original  = FileProvider.GetFile(environmentFilePath);
            using var recreated = new MemoryStream();

            MapEnvironment.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
Esempio n. 6
0
        public void TestParsePathingMap(string pathingMapFile)
        {
            using var original  = FileProvider.GetFile(pathingMapFile);
            using var recreated = new MemoryStream();

            PathingMap.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
Esempio n. 7
0
        // Delete file from the server
        private void DeleteFile(HttpContext context)
        {
            var file = FileProvider.GetFile(context.Request["f"]);

            if (file != null && file.Exists)
            {
                file.Delete();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Processes the content.
        /// </summary>
        /// <returns>processed conntent</returns>
        public string ProcessContent()
        {
            if (HtmlFile == null)
            {
                HtmlFile = FileProvider.GetFile(HtmlFileUri);
            }
            _baseFolderUrl = new Uri(htmlParser.GetBaseUrlFolder(HtmlFile));

            return(ResolveDependencies());
        }
Esempio n. 9
0
        /// <summary>
        /// Gets url of file to download
        /// </summary>
        /// <param name="url">File url</param>
        private string DownloadDependencyFile(string url)
        {
            IWebFile downloadedFile = FileProvider.GetFile(new Uri(url));

            if (downloadedFile == null)
            {
                return(url);
            }
            return(FileStorage.SaveFile(downloadedFile, false));
        }
Esempio n. 10
0
        private FileInfo GetRenamedFileIfExists(string relativeFile)
        {
            var    file     = FileProvider.GetFile(relativeFile);
            string fileName = file.FileNameWithoutExtension();
            string ext      = file.Extension;
            int    idx      = 1;

            while (file.Exists)
            {
                file = new FileInfo(Path.Combine(file.DirectoryName,
                                                 string.Format("{0}({1}){2}", fileName, idx, ext)));
                idx++;
            }
            return(file);
        }
Esempio n. 11
0
        private void DeliverFile(HttpContext context)
        {
            var    filename   = context.Request["f"];
            string uploadPath = GetUploadPath(filename, context);
            var    file       = FileProvider.GetFile(uploadPath + filename);

            if (file.Exists)
            {
                context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
                context.Response.ContentType = "application/octet-stream";
                context.Response.ClearContent();
                context.Response.WriteFile(file.FullName);
            }
            else
            {
                context.Response.StatusCode = 404;
            }
        }
Esempio n. 12
0
        private static void Main()
        {
            var stringProvider = new ExampleStringProvider();

            var mapInfo = MapInfo.Parse(FileProvider.GetFile(Path.Combine(stringProvider.BaseMapFilePath, MapInfo.FileName)));

            mapInfo.MapName            = stringProvider.MapName;
            mapInfo.MapDescription     = stringProvider.MapDescription;
            mapInfo.MapAuthor          = stringProvider.MapAuthor;
            mapInfo.RecommendedPlayers = stringProvider.RecommendedPlayers;

            mapInfo.MapFlags      &= ~MapFlags.MeleeMap;
            mapInfo.ScriptLanguage = ScriptLanguage.Lua;

            PlayerAndForceProperties.ApplyToMapInfo(mapInfo);

            var scriptCompilerOptions = new ScriptCompilerOptions(CoreSystemProvider.GetCoreSystemFiles().Append(@".\LuaLibs\PerlinNoise.lua"));

            scriptCompilerOptions.MapInfo         = mapInfo;
            scriptCompilerOptions.LobbyMusic      = stringProvider.LobbyMusic;
            scriptCompilerOptions.SourceDirectory = stringProvider.SourceProjectPath;
            scriptCompilerOptions.OutputDirectory = stringProvider.OutputDirectoryPath;

            // Note: do not use MpqFileFlags.SingleUnit, as it appears to be bugged.
            scriptCompilerOptions.DefaultFileFlags         = MpqFileFlags.Exists | MpqFileFlags.CompressedMulti;
            scriptCompilerOptions.FileFlags["war3map.wtg"] = 0;
            scriptCompilerOptions.FileFlags[mapInfo.ScriptLanguage == ScriptLanguage.Jass ? "war3map.lua" : "war3map.j"] = 0;
            scriptCompilerOptions.FileFlags[ListFile.Key] = MpqFileFlags.Exists | MpqFileFlags.Encrypted | MpqFileFlags.BlockOffsetAdjustedKey;
#if DEBUG
            scriptCompilerOptions.Debug = true;
#endif

            // Build and launch
            var mapName    = stringProvider.MapFileName;
            var mapBuilder = new MapBuilder(mapName);

            if (mapBuilder.Build(scriptCompilerOptions, stringProvider.AssetsDirectoryPath, stringProvider.BaseMapFilePath))
            {
                var mapPath         = Path.Combine(scriptCompilerOptions.OutputDirectory, mapName);
                var absoluteMapPath = new FileInfo(mapPath).FullName;
                Process.Start(stringProvider.Warcraft3ExecutablePath, $"{stringProvider.CommandLineArguments} -loadfile \"{absoluteMapPath}\"");
            }
        }
Esempio n. 13
0
        internal static void RunBinaryRWTest(
            string filePath,
            Type type,
            string?readMethodName = null,
            object?[]?additionalReadParameters  = null,
            object?[]?additionalWriteParameters = null)
        {
            var expectedReadTypes = new[] { typeof(BinaryReader) };

            if (additionalReadParameters is not null)
            {
                expectedReadTypes = expectedReadTypes.Concat(additionalReadParameters.Select(p => p.GetType())).ToArray();
            }

            var readMethod = typeof(BinaryReaderExtensions).GetMethod(readMethodName ?? $"Read{type.Name}", expectedReadTypes);

            Assert.IsNotNull(readMethod, $"Could not find extension method to read {type.Name}.");

            var expectedWriteTypes = new[] { typeof(BinaryWriter), type };

            if (additionalWriteParameters is not null)
            {
                expectedWriteTypes = expectedWriteTypes.Concat(additionalWriteParameters.Select(p => p.GetType())).ToArray();
            }

            var writeMethod = typeof(BinaryWriterExtensions).GetMethod(nameof(BinaryWriter.Write), expectedWriteTypes);

            Assert.IsNotNull(writeMethod, $"Could not find extension method to write {type.Name}.");

            using var expectedStream = FileProvider.GetFile(filePath);
            using var reader         = new BinaryReader(expectedStream);
            var parsedFile = readMethod !.Invoke(null, new object?[] { reader }.Concat(additionalReadParameters ?? Array.Empty <object?[]>()).ToArray());

            Assert.AreEqual(type, parsedFile.GetType());

            using var actualStream = new MemoryStream();
            using var writer       = new BinaryWriter(actualStream);
            writeMethod !.Invoke(null, new object?[] { writer, parsedFile }.Concat(additionalWriteParameters ?? Array.Empty <object?[]>()).ToArray());
            writer.Flush();

            StreamAssert.AreEqual(expectedStream, actualStream, true);
        }
Esempio n. 14
0
 public void TestFileProviderGetFile(string path, bool expected)
 {
     if (expected)
     {
         using var file = FileProvider.GetFile(path);
         Assert.IsNotNull(file);
     }
     else
     {
         try
         {
             using (var file = FileProvider.GetFile(path))
             {
                 Assert.Fail();
             }
         }
         catch (FileNotFoundException)
         {
         }
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Retrieves application changelog which lists all versions.
        /// </summary>
        /// <returns>Returns object representing application ChangeLog.</returns>
        public async Task <ChangeLog> GetChangeLog()
        {
            if (CachedChangeLog != null)
            {
                return(CachedChangeLog);
            }

            string changelogContent = await FileProvider.GetFile("changelog.json");

            if (string.IsNullOrEmpty(changelogContent))
            {
                return(null);
            }

            ChangeLog changeLog = ChangeLog.FromJson(changelogContent, this);

            if (changeLog != null)
            {
                CachedChangeLog = changeLog;
            }

            return(changeLog);
        }