Exemplo n.º 1
0
        public void TestReadTestDGF()
        {
            IDGF test_dgf = DGFIO.OpenDGF("./test.dgf");

            Assert.IsNotNull(test_dgf);
            Assert.AreEqual("Ethem Kurt", test_dgf.AuthorName);
            Assert.AreEqual("https://github.com/BigETI/DGFSharp", test_dgf.Comments);
            Assert.AreEqual((ushort)1, test_dgf.ApplyPlayPasswordUntilGardenNumber);
            Assert.AreEqual("Edit", test_dgf.EditPassword);
            Assert.AreEqual("Play", test_dgf.PlayPassword);
            Assert.AreEqual(3, test_dgf.Garden.Count);
            foreach (IGarden garden in test_dgf.Garden)
            {
                Assert.IsNotNull(garden);
            }
            Assert.AreEqual("DAISYG_5.MID", test_dgf.GardenOneMIDIPath);
            Assert.AreEqual("Round trip around flying ground", test_dgf.Garden[0].Name);
            Assert.AreEqual("Marmot garden", test_dgf.Garden[1].Name);
            Assert.AreEqual("Underground garden", test_dgf.Garden[2].Name);
            Assert.AreEqual(85, test_dgf.Garden[0].Time);
            Assert.AreEqual(120, test_dgf.Garden[1].Time);
            Assert.AreEqual(225, test_dgf.Garden[2].Time);
            Assert.AreEqual("DAISYG_5.MID", test_dgf.Garden[0].MIDIPath);
            Assert.AreEqual("DAISYG_2.MID", test_dgf.Garden[1].MIDIPath);
            Assert.AreEqual("DAISYG_6.MID", test_dgf.Garden[2].MIDIPath);
            Assert.AreEqual(new Size(17, 12), test_dgf.Garden[0].Size);
            Assert.AreEqual(new Size(17, 12), test_dgf.Garden[1].Size);
            Assert.AreEqual(new Size(40, 40), test_dgf.Garden[2].Size);
            Assert.AreEqual(new Position(0, 10), GetDaisysPosition(test_dgf.Garden[0]));
            Assert.AreEqual(new Position(0, 10), GetDaisysPosition(test_dgf.Garden[1]));
            Assert.AreEqual(new Position(1, 4), GetDaisysPosition(test_dgf.Garden[2]));
        }
Exemplo n.º 2
0
        public void TestOutputDGFFile()
        {
            IDGF test_dgf = DGFIO.OpenDGF("./test.dgf");

            Assert.IsNotNull(test_dgf);
            Assert.IsTrue(test_dgf.Save("./output.dgf"));
            FileAssert.AreEqual("./output.dgf", "./test.dgf");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">Command line arguments</param>
        private static void Main(string[] args)
        {
            Dictionary <string, string> files = new Dictionary <string, string>();
            string     output_directory       = string.Empty;
            bool       show_help          = false;
            bool       verbose            = false;
            EInputFlag current_input_flag = EInputFlag.Nothing;
            string     last_path          = null;
            string     help_topic         = null;

            foreach (string arg in args)
            {
                string trimmed_arg = arg.Trim().ToLower();
                if (trimmed_arg.Length > 0)
                {
                    if (trimmed_arg[0] == '-')
                    {
                        string    key        = ((trimmed_arg.Length > 1) ? trimmed_arg.Substring(1) : string.Empty);
                        InputFlag?input_flag = null;
                        if (inputFlags.ContainsKey(key))
                        {
                            input_flag = inputFlags[key];
                        }
                        else if (inputFlagAliases.ContainsKey(key))
                        {
                            input_flag = inputFlags[inputFlagAliases[key]];
                        }
                        if (input_flag == null)
                        {
                            Console.Error.Write("Invalid input flag \"");
                            Console.Error.Write(arg);
                            Console.Error.WriteLine("\"");
                        }
                        else
                        {
                            PrintInputFlagError(current_input_flag);
                            current_input_flag = input_flag.Value.Flag;
                            switch (current_input_flag)
                            {
                            case EInputFlag.ShowHelp:
                                show_help = true;
                                break;

                            case EInputFlag.Verbose:
                                verbose            = true;
                                current_input_flag = EInputFlag.Nothing;
                                break;
                            }
                        }
                    }
                    else
                    {
                        switch (current_input_flag)
                        {
                        case EInputFlag.Nothing:
                            if (!(files.ContainsKey(arg)))
                            {
                                files.Add(arg, arg);
                            }
                            last_path = arg;
                            break;

                        case EInputFlag.ShowHelp:
                            help_topic = trimmed_arg;
                            break;

                        case EInputFlag.SpecifyOutputPath:
                            if (last_path == null)
                            {
                                Console.Error.WriteLine("No input path is defined");
                            }
                            else
                            {
                                files[last_path] = arg;
                            }
                            current_input_flag = EInputFlag.Nothing;
                            break;

                        case EInputFlag.SpecifyOutputDirectoryPath:
                            output_directory   = arg;
                            current_input_flag = EInputFlag.Nothing;
                            break;
                        }
                        current_input_flag = EInputFlag.Nothing;
                    }
                }
            }
            PrintInputFlagError(current_input_flag);
            if (show_help || (files.Count <= 0))
            {
                if (help_topic == null)
                {
                    PrintInputFlags();
                }
                else
                {
                    InputFlag?input_flag = null;
                    if (inputFlags.ContainsKey(help_topic))
                    {
                        input_flag = inputFlags[help_topic];
                    }
                    else if (inputFlagAliases.ContainsKey(help_topic))
                    {
                        input_flag = inputFlags[inputFlagAliases[help_topic]];
                    }
                    if (input_flag == null)
                    {
                        Console.Error.Write("Invalid help topic \"");
                        Console.Error.Write(help_topic);
                        Console.Error.WriteLine("\".");
                        PrintInputFlags();
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.Write("Help topic: ");
                        Console.WriteLine(input_flag.Value.Description);
                        Console.WriteLine();
                        string[] full_description = input_flag.Value.FullDescription.Split(Environment.NewLine);
                        if (full_description != null)
                        {
                            foreach (string full_description_line in full_description)
                            {
                                if (full_description_line != null)
                                {
                                    Console.Write("\t");
                                    Console.WriteLine(full_description_line);
                                }
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <string, string> file in files)
                {
                    try
                    {
                        string input_file_path = Path.GetFullPath(file.Key);
                        if (File.Exists(input_file_path))
                        {
                            if (verbose)
                            {
                                Console.Write("Opening file \"");
                                Console.Write(input_file_path);
                                Console.WriteLine("\"...");
                            }
                            IDGF dgf = DGFIO.OpenDGF(input_file_path);
                            dgf.EditPassword = string.Empty;
                            dgf.PlayPassword = string.Empty;
                            dgf.ApplyPlayPasswordUntilGardenNumber = 1;
                            if (dgf == null)
                            {
                                Console.Error.Write("Could not open file \"");
                                Console.Error.Write(input_file_path);
                                Console.Error.WriteLine("\".");
                            }
                            else
                            {
                                string output_path    = Path.GetFullPath(Path.Combine(output_directory, file.Value));
                                string directory_path = Path.GetFullPath(Path.GetDirectoryName(output_path));
                                if (!(Directory.Exists(directory_path)))
                                {
                                    Directory.CreateDirectory(directory_path);
                                    if (verbose)
                                    {
                                        Console.Write("Created directory \"");
                                        Console.Write(directory_path);
                                        Console.WriteLine("\".");
                                    }
                                }
                                if (dgf.Save(output_path))
                                {
                                    if (verbose)
                                    {
                                        Console.Write("Created file \"");
                                        Console.Write(output_path);
                                        Console.WriteLine("\".");
                                    }
                                }
                                else
                                {
                                    Console.Error.Write("Failed to write output to \"");
                                    Console.Error.Write(output_path);
                                    Console.Error.WriteLine("\".");
                                }
                            }
                        }
                        else
                        {
                            Console.Error.Write("File \"");
                            Console.Error.Write(input_file_path);
                            Console.Error.WriteLine("\" does not exist.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e);
                    }
                }
            }
        }