Esempio n. 1
0
        static void Main(string[] args)
        {
            GpxcOptions options = new GpxcOptions();
            List<string> extraCommandLineArgs = new List<string>();
            var p = new OptionSet()
            .Add("v|version", dummy => { ShowVersion(); Environment.Exit(0); })
                .Add("?|h|help", dummy => { ShowHelp(); Environment.Exit(0); })
                .Add("silent", v => { if (v != null) options.Silent = true; })
                .Add("n|nuvi", r => { if (r != null) options.Nuvi = true; })
                .Add("n2|nuvi2", r => { if (r != null) options.Nuvi2 = true; });

            //解析
            try
            {
                // extraCommandLineArgs には、上記オプションを取り除いた残りの引数が入る
                extraCommandLineArgs = p.Parse(Environment.GetCommandLineArgs());
            }
            catch (Exception ex)
            {
                Console.WriteLine("オプションの解析が失敗しました。\n" + ex.Message);
                Environment.Exit(0);
            }

            extraCommandLineArgs.RemoveAt(0);
            List<string> target_files = get_target_files(extraCommandLineArgs);
            foreach(string each_target_file in target_files)
            {
                switch (System.IO.Path.GetExtension(each_target_file).ToUpper())
                {
                    case ".GPX":
                        convert_gpx(each_target_file,options);
                        continue;
                    case ".ZIP":
                        using (ZipFile zip = ZipFile.Read(each_target_file))
                        {
                            foreach (ZipEntry entry in zip)
                            {
                                if (System.IO.Path.GetExtension(entry.FileName).ToUpper() == ".GPX")
                                {
                                    string dirname = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(each_target_file),System.IO.Path.GetFileNameWithoutExtension(each_target_file));
                                    if (!System.IO.Directory.Exists(dirname))
                                    {
                                        System.IO.Directory.CreateDirectory(dirname);
                                    }
                                    string gpx_filepath = System.IO.Path.Combine(dirname , entry.FileName);
                                    entry.Extract(dirname, ExtractExistingFileAction.OverwriteSilently);
                                    convert_gpx(gpx_filepath,options);
                                    System.IO.File.Delete(gpx_filepath);
                                }
                            }
                        }
                        continue;
                    default:
                        continue;
                }
            }
        }
Esempio n. 2
0
        static void convert_gpx(string file_path, GpxcOptions options)
        {
            string new_gpx_file_path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(file_path),"gpxc." + System.IO.Path.GetFileName(file_path));
            if(!options.Silent)Console.WriteLine("{0}を処理中...",file_path);
            using(System.IO.StreamReader sr = new System.IO.StreamReader(file_path,System.Text.Encoding.GetEncoding("utf-8"))){
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(new_gpx_file_path, false, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    while (sr.EndOfStream==false)
                    {
                        sw.WriteLine(LibGpx.decode(sr.ReadLine()));
                    };
                    sw.Flush();
                }

            }
            if (options.Nuvi)
            {
                LibGpx.conv_nuvi(new_gpx_file_path, nuvi: true);
            }
            else if (options.Nuvi2)
            {
                LibGpx.conv_nuvi(new_gpx_file_path, nuvi2: true);
            }
        }