Inheritance: IInput
コード例 #1
0
ファイル: Compiler.cs プロジェクト: dersteps/WF.Compiler
        /// <summary>
        /// Compiler entry for online compilation.
        /// </summary>
        /// <param name="ifs">Stream of the input file.</param>
        /// <param name="device">Device.</param>
        /// <param name="userName">User name.</param>
        /// <param name="completitionCode">Completition code.</param>
        public static MemoryStream Download(Stream ifs, DeviceType device = DeviceType.Emulator, string userName = "******", string completitionCode = "1234567890ABCDE")
        {
            // ---------- Check device ----------

            // ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

            // Create object für reading input file (could be also any other format implementing IInput)
            var inputFormat = new GWZ(ifs);

            // ---------- Check GWZ file (only required for upload of GWZ file) ----------

            // Check gwz file for errors (Lua code and all files included)
            // Now there shouldn't be any errors, because files on the server are checked.
            inputFormat.Check();

            // ---------- Load cartridge from GWZ file (required when downloading cartridge) ----------

            // Load Lua code and extract all required data
            Cartridge cartridge = inputFormat.Load();

            // ---------- Convert cartridge for engine ----------

            // Create selected player
            IEngine engine = CreateEngine(device);

            // Convert Lua code and insert special code for this player
            cartridge = engine.ConvertCartridge(cartridge);
            userName  = engine.ConvertString(userName);

            // Now we can close the input, because we don't require it anymore
            ifs.Close();

            // ---------- Compile Lua code into binary chunk ----------

            // Compile Lua code
            cartridge.Chunk = LUA.Compile(cartridge.LuaCode, cartridge.LuaFileName);

            // ---------- Save cartridge as GWC file ----------

            // Create object for output format (could be also WFC or any other IOutput)
            var outputFormat = new GWC();

            // Write output file
            try {
                // Create output in correct format
                var ms = outputFormat.Create(cartridge, userName, 0, completitionCode);
                return(ms);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: dersteps/WF.Compiler
        /// <summary>
        /// Checke the stream fileInput, if it is a valid GWZ file and the Lua code has no errors.
        /// </summary>
        /// <param name="fileInput">Stream for input.</param>
        public static void Upload(Stream ifs)
        {
            // ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

            // Create object für reading input file (could be also any other format implementing IInput)
            var inputFormat = new GWZ(ifs);

            // ---------- Check GWZ file (only required for upload of GWZ file) ----------

            // Check gwz file for errors (Lua code and all files included)
            // Could throw CompilerLuaException when there is a bug in Lua code
            inputFormat.Check();

            // We are ready an no exception was thrown, so we only have to close the input stream and leave.
            ifs.Close();
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: dersteps/WF.Compiler
        /// <summary>
        /// The entry point of the program, where the program control starts and ends when used from command line.
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        public static void Main(string[] args)
        {
            var start  = DateTime.Now;
            var device = DeviceType.Unknown;

            Console.WriteLine("WF.Compiler, Version {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            Console.WriteLine("Copyright 2014 by Wherigo Foundation");
            Console.WriteLine();

            string fileInput  = null;
            string fileOutput = null;

            int    userId           = 0;
            string userName         = "******";
            string completitionCode = "123456789ABCDEF";

            int i = 0;

            while (i < args.Length)
            {
                switch (args[i].ToLower())
                {
                case "-d":
                case "-device":
                    if (i + 1 >= args.Length)
                    {
                        Usage();
                        return;
                    }
                    string deviceName = args[i + 1].ToLower();
                    i++;
                    foreach (DeviceType d in Enum.GetValues(typeof(DeviceType)))
                    {
                        if (d.ToString().ToLower() == deviceName)
                        {
                            device = d;
                        }
                    }
                    break;

                case "-o":
                case "-output":
                    if (i + 1 >= args.Length)
                    {
                        Usage();
                        return;
                    }
                    fileOutput = args[i + 1].ToLower();
                    i++;
                    break;

                case "-u":
                case "-username":
                    if (i + 1 >= args.Length)
                    {
                        Usage();
                        return;
                    }
                    userName = args[i + 1];
                    i++;
                    break;

                case "-c":
                case "-code":
                    if (i + 1 >= args.Length)
                    {
                        Usage();
                        return;
                    }
                    completitionCode = args[i + 1];
                    i++;
                    break;

                default:
                    fileInput = args[i];
                    break;
                }
                i++;
            }

            if (fileInput == null)
            {
                Usage();
                return;
            }

            if (!File.Exists(fileInput))
            {
                Usage();
                return;
            }


            if (fileOutput == null)
            {
                fileOutput = Path.ChangeExtension(fileInput, ".gwc");
            }

            Console.WriteLine("Input file: " + fileInput);
            Console.WriteLine("Output file: " + fileOutput);
            Console.WriteLine("Device: " + device.ToString());
            Console.WriteLine("Username: "******"CompletionCode: " + completitionCode);

            FileStream ifs = new FileStream(fileInput, FileMode.Open);

            // ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

            // Create object für reading input file (could be also any other format implementing IInput)
            var inputFormat = new GWZ(ifs);

            // ---------- Check GWZ file (only required for upload of GWZ file) ----------

            // Check gwz file for errors (Lua code and all files included)
            try {
                inputFormat.Check();
            }
            catch (CompilerLuaException e)
            {
                Console.WriteLine();
                Console.WriteLine("Error");
                Console.WriteLine(e.Message);
                Console.WriteLine();
                Console.WriteLine("Line {0}: {1}", e.Line - 1, e.CodeBefore);
                Console.WriteLine("Line {0}: {1}", e.Line, e.Code);
                Console.WriteLine("Line {0}: {1}", e.Line + 1, e.CodeAfter);
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Error");
                Console.WriteLine(e.Message);
                ifs.Close();
                return;
            }

            // ---------- Load cartridge from GWZ file (required when downloading cartridge) ----------

            // Load Lua code and extract all required data
            Cartridge cartridge = inputFormat.Load();

            // ---------- Convert cartridge for engine ----------

            // Create selected engine
            IEngine engine = CreateEngine(device);

            // Convert Lua code and insert special code for this player
            cartridge = engine.ConvertCartridge(cartridge);
            userName  = engine.ConvertString(userName);

            // Now we can close the input, because we don't require it anymore
            ifs.Close();

            // ---------- Compile Lua code into binary chunk ----------

            try {
                // Compile Lua code
                cartridge.Chunk = LUA.Compile(cartridge.LuaCode, cartridge.LuaFileName);
            }
            catch (Exception e)
            {
                var t = e.Message;
            }

            // ---------- Save cartridge as GWC file ----------

            // Create object for output format (could be also WFC or any other IOutput)
            var outputFormat = new GWC();

            // Write output file
            try {
                // Create output in correct format
                var ms = outputFormat.Create(cartridge, userName, userId, completitionCode);
                // Save output to file
                using (FileStream ofs = new FileStream(fileOutput, FileMode.Create)) {
                    ms.CopyTo(ofs);
                    // Close output
                    ofs.Flush();
                    ofs.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Error");
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("Compiletime: {0}", DateTime.Now - start);
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: WFoundation/WF.Compiler
		/// <summary>
		/// The entry point of the program, where the program control starts and ends when used from command line.
		/// </summary>
		/// <param name="args">The command line arguments.</param>
        public static void Main(string[] args)
        {
			var start = DateTime.Now;
			var device = DeviceType.Unknown;

			Console.WriteLine("WF.Compiler, Version {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
			Console.WriteLine("Copyright 2014 by Wherigo Foundation");
			Console.WriteLine();

			string fileInput = null; 
			string fileOutput = null;

			int userId = 0;
			string userName = "******";
			string completitionCode = "123456789ABCDEF";

			int i = 0;

			while (i < args.Length) {
				switch(args[i].ToLower()) {
				case "-d":
				case "-device":
					if (i+1 >= args.Length) {
						Usage();
						return;
					}
					string deviceName = args[i+1].ToLower();
					i++;
					foreach (DeviceType d in Enum.GetValues(typeof(DeviceType))) 
						if (d.ToString().ToLower() == deviceName) 
							device = d;
					break;
				case "-o":
				case "-output":
					if (i+1 >= args.Length) {
						Usage();
						return;
					}
					fileOutput = args[i+1].ToLower();
					i++;
					break;
				case "-u":
				case "-username":
					if (i+1 >= args.Length) {
						Usage();
						return;
					}
					userName = args[i+1];
					i++;
					break;
				case "-c":
				case "-code":
					if (i+1 >= args.Length) {
						Usage();
						return;
					}
					completitionCode = args[i+1];
					i++;
					break;
				default:
					fileInput = args[i];
					break;
				}
				i++;
			}

			if (fileInput == null) {
				Usage();
				return;
			}

			if (!File.Exists(fileInput)) {
				Usage();
				return;
			}


			if (fileOutput == null)
				fileOutput = Path.ChangeExtension(fileInput,".gwc");

			Console.WriteLine("Input file: " + fileInput);
			Console.WriteLine("Output file: " + fileOutput);
			Console.WriteLine("Device: " + device.ToString());
			Console.WriteLine("Username: "******"CompletionCode: " + completitionCode);

			FileStream ifs = new FileStream(fileInput, FileMode.Open);

			// ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

			// Create object für reading input file (could be also any other format implementing IInput)
			var inputFormat = new GWZ(ifs);

			// ---------- Check GWZ file (only required for upload of GWZ file) ----------

			// Check gwz file for errors (Lua code and all files included)
			try {
				inputFormat.Check();
			}
			catch (CompilerLuaException e)
			{
				Console.WriteLine();
				Console.WriteLine("Error");
				Console.WriteLine(e.Message);
				Console.WriteLine();
				Console.WriteLine("Line {0}: {1}", e.Line-1, e.CodeBefore);
				Console.WriteLine("Line {0}: {1}", e.Line, e.Code);
				Console.WriteLine("Line {0}: {1}", e.Line+1, e.CodeAfter);
				return;
			}
			catch (Exception e)
			{
				Console.WriteLine();
				Console.WriteLine("Error");
				Console.WriteLine(e.Message);
				ifs.Close();
				return;
			}

			// ---------- Load cartridge from GWZ file (required when downloading cartridge) ----------

			// Load Lua code and extract all required data
			Cartridge cartridge = inputFormat.Load();

			// ---------- Convert cartridge for engine ----------

			// Create selected engine
			IEngine engine = CreateEngine(device);

			// Convert Lua code and insert special code for this player
			cartridge = engine.ConvertCartridge(cartridge);
			userName = engine.ConvertString(userName);

			// Now we can close the input, because we don't require it anymore
			ifs.Close();

			// ---------- Compile Lua code into binary chunk ----------

			try {
				// Compile Lua code
				cartridge.Chunk = LUA.Compile(cartridge.LuaCode, cartridge.LuaFileName);
			}
			catch (Exception e)
			{
				var t = e.Message;
			}

			// ---------- Save cartridge as GWC file ----------

			// Create object for output format (could be also WFC or any other IOutput)
			var outputFormat = new GWC();

			// Write output file
			try {
				// Create output in correct format
				var ms = outputFormat.Create(cartridge, userName, userId, completitionCode);
				// Save output to file
				using(FileStream ofs = new FileStream(fileOutput, FileMode.Create)) {
					ms.CopyTo(ofs);
					// Close output
					ofs.Flush();
					ofs.Close();
				}
			}
			catch (Exception e)
			{
				Console.WriteLine();
				Console.WriteLine("Error");
				Console.WriteLine(e.Message);
				return;
			}

			Console.WriteLine("Compiletime: {0}", DateTime.Now - start);
        }
コード例 #5
0
ファイル: Compiler.cs プロジェクト: WFoundation/WF.Compiler
		/// <summary>
		/// Compiler entry for online compilation.
		/// </summary>
		/// <param name="ifs">Stream of the input file.</param>
		/// <param name="device">Device.</param>
		/// <param name="userName">User name.</param>
		/// <param name="completitionCode">Completition code.</param>
		public static MemoryStream Download(Stream ifs, DeviceType device = DeviceType.Emulator, string userName = "******", string completitionCode = "1234567890ABCDE")
		{
			// ---------- Check device ----------

			// ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

			// Create object für reading input file (could be also any other format implementing IInput)
			var inputFormat = new GWZ(ifs);

			// ---------- Check GWZ file (only required for upload of GWZ file) ----------

			// Check gwz file for errors (Lua code and all files included)
			// Now there shouldn't be any errors, because files on the server are checked.
			inputFormat.Check();

			// ---------- Load cartridge from GWZ file (required when downloading cartridge) ----------

			// Load Lua code and extract all required data
			Cartridge cartridge = inputFormat.Load();

			// ---------- Convert cartridge for engine ----------

			// Create selected player
			IEngine engine = CreateEngine(device);

			// Convert Lua code and insert special code for this player
			cartridge = engine.ConvertCartridge(cartridge);
			userName = engine.ConvertString(userName);

			// Now we can close the input, because we don't require it anymore
			ifs.Close();

			// ---------- Compile Lua code into binary chunk ----------

			// Compile Lua code
			cartridge.Chunk = LUA.Compile(cartridge.LuaCode, cartridge.LuaFileName);

			// ---------- Save cartridge as GWC file ----------

			// Create object for output format (could be also WFC or any other IOutput)
			var outputFormat = new GWC();

			// Write output file
			try {
				// Create output in correct format
				var ms = outputFormat.Create(cartridge, userName, 0, completitionCode);
				return ms;
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				return null;
			}

		}
コード例 #6
0
ファイル: Compiler.cs プロジェクト: WFoundation/WF.Compiler
		/// <summary>
		/// Checke the stream fileInput, if it is a valid GWZ file and the Lua code has no errors.
		/// </summary>
		/// <param name="fileInput">Stream for input.</param>
		public static void Upload(Stream ifs)
		{
			// ---------- Create GWZ file only (required for upload and download of GWZ file) ----------

			// Create object für reading input file (could be also any other format implementing IInput)
			var inputFormat = new GWZ(ifs);

			// ---------- Check GWZ file (only required for upload of GWZ file) ----------

			// Check gwz file for errors (Lua code and all files included)
			// Could throw CompilerLuaException when there is a bug in Lua code
			inputFormat.Check();

			// We are ready an no exception was thrown, so we only have to close the input stream and leave.
			ifs.Close();
		}