Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            // Check if the argument is to update config files
            if (args.Length == 4 && args[0] == "-u")
            {
                Console.WriteLine("Starting modime config updater");
                ModimeConfigurationGenerator.UpdateWithSpreadsheet(args[1], args[2],
                                                                   args[3]);
                Console.WriteLine("Done");
                return;
            }

            // Get and create the output directory.
            string outDir;

            if (args.Length > 1)
            {
                outDir = args[0];
            }
            else
            {
                outDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                outDir = Path.Combine(outDir, "output");
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            // Get the services and start working.
            var service = new SpreadsheetsService();

            // Ask for file names.
            while (true)
            {
                // Get the requested SpreadhSheet title.
                Console.WriteLine();
                Console.Write("Type the file title (\"exit\" to quit)> ");
                string title = Console.ReadLine();
                if (title == "exit")
                {
                    break;
                }

                // Search for it
                var spreadsheets = service.SearchSpreadsheets(title, 0).ToArray();
                var targetSheet  = SelectSpreadsheet(spreadsheets);
                if (targetSheet == null)
                {
                    continue;
                }

                // Check that it's a valid spreadsheet by comparing the name
                // All the converted XML are written into the first worksheet.
                var worksheet = targetSheet[0];
                var name      = worksheet[0, 0]; // Written into the first cell.
                if (string.IsNullOrEmpty(name) || !name.StartsWith("Filename "))
                {
                    Console.WriteLine("Invalid spreadsheet name. Please verify it.");
                    continue;
                }

                name = name.Substring("Filename ".Length);

                // Convert.
                Console.WriteLine("Converting {0}...", name);
                var xml = new WorksheetToXml(worksheet).Convert();

                // If it's a subtitle script, the root tag has an attribute with name
                if (xml.Root.Name == "Subtitle")
                {
                    xml.Root.SetAttributeValue("Name", name);
                }

                xml.Save(Path.Combine(outDir, name + ".xml"));
            }
        }