예제 #1
0
        static bool ConvertOneMap([NotNull] FileSystemInfo fileSystemInfo)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }

            try {
                Map map;
                if (importer != null)
                {
                    if (!importer.ClaimsName(fileSystemInfo.FullName))
                    {
                        return(false);
                    }
                    Console.Write("Loading {0}... ", fileSystemInfo.Name);
                    map = importer.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", fileSystemInfo.Name);
                    map = MapUtility.Load(fileSystemInfo.FullName);
                }

                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + '.' + exporter.FileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + '.' +
                                     exporter.FileExtension;
                }

                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return(false);
                    }
                }
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                exporter.Save(map, targetPath);
                Console.WriteLine("ok");
                return(true);
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
                return(false);
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
                return(false);
            }
        }
예제 #2
0
        static bool RenderOneMap([NotNull] FileSystemInfo fileSystemInfo)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }

            try {
                Map map;
                if (mapImporter != null)
                {
                    if (!mapImporter.ClaimsName(fileSystemInfo.FullName))
                    {
                        return(false);
                    }
                    Console.Write("Loading {0}... ", fileSystemInfo.Name);
                    map = mapImporter.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", fileSystemInfo.Name);
                    map = MapUtility.Load(fileSystemInfo.FullName);
                }

                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + imageFileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + imageFileExtension;
                }

                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return(false);
                    }
                }
                Console.Write("Drawing... ");
                IsoCatResult result = renderer.Draw(map);
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                if (uncropped)
                {
                    SaveImage(result.Bitmap, targetPath);
                }
                else
                {
                    SaveImage(result.Bitmap.Clone(result.CropRectangle, result.Bitmap.PixelFormat), targetPath);
                }
                Console.WriteLine("ok");
                return(true);
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
                return(false);
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
                return(false);
            }
        }
예제 #3
0
        static bool ConvertOneMap([NotNull] FileSystemInfo fileSystemInfo, [NotNull] string relativeName)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }
            if (relativeName == null)
            {
                throw new ArgumentNullException("relativeName");
            }

            try {
                // if output directory was not given, save to same directory as the map file
                if (!outputDirGiven)
                {
                    outputDirName = Paths.GetDirectoryNameOrRoot(fileSystemInfo.FullName);
                }

                // load the map file
                Map map;
                if (importer != null)
                {
                    if (!importer.ClaimsName(fileSystemInfo.FullName))
                    {
                        return(false);
                    }
                    Console.Write("Loading {0}... ", relativeName);
                    map = importer.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", relativeName);
                    map = MapUtility.Load(fileSystemInfo.FullName, tryHard);
                }

                // select target map file name
                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + '.' + exporter.FileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + '.' +
                                     exporter.FileExtension;
                }

                // get full target map file name, check if it already exists
                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return(false);
                    }
                }

                // save
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                exporter.Save(map, targetPath);
                Console.WriteLine("ok");
                return(true);
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
                return(false);
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
                return(false);
            }
        }
예제 #4
0
        static bool ConvertOneMap([NotNull] FileSystemInfo sourceFile, [NotNull] string relativeName)
        {
            if (sourceFile == null)
            {
                throw new ArgumentNullException("sourceFile");
            }
            if (relativeName == null)
            {
                throw new ArgumentNullException("relativeName");
            }

            try {
                // if output directory was not given, save to same directory as the map file
                if (!outputDirGiven)
                {
                    outputDirName = Paths.GetDirectoryNameOrRoot(sourceFile.FullName);
                }

                // load the map file
                Map map;
                if (importer != null)
                {
                    if (!importer.ClaimsName(sourceFile.FullName))
                    {
                        return(false);
                    }
                    Console.Write("Loading {0}... ", relativeName);
                    map = importer.Load(sourceFile.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", relativeName);
                    map = MapUtility.Load(sourceFile.FullName, tryHard);
                }

                // select target map file name
                string targetName;
                bool   sourceIsDir = (sourceFile.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
                bool   targetIsDir = (exporter.StorageType == MapStorageType.Directory);
                if (targetIsDir)
                {
                    if (sourceIsDir)
                    {
                        targetName = sourceFile.Name;
                    }
                    else
                    {
                        targetName = Path.GetFileNameWithoutExtension(sourceFile.Name);
                    }
                }
                else
                {
                    if (sourceIsDir)
                    {
                        targetName = sourceFile.Name + '.' + exporter.FileExtension;
                    }
                    else
                    {
                        targetName = Path.GetFileNameWithoutExtension(sourceFile.Name) + '.' +
                                     exporter.FileExtension;
                    }
                }

                // get full target map file name, check if it already exists
                string targetPath = Path.Combine(outputDirName, targetName);
                Console.WriteLine("targetPath=" + targetPath + " | fileExists=" + File.Exists(targetPath) +
                                  " | dirExists=" + Directory.Exists(targetPath));
                if (!overwrite &&
                    (!targetIsDir && File.Exists(targetPath) || targetIsDir && Directory.Exists(targetPath)))
                {
                    string targetType = (targetIsDir ? "Directory" : "File");
                    Console.WriteLine();
                    if (!ConsoleUtil.ShowYesNo("{0} \"{1}\" already exists. Overwrite?", targetType, targetName))
                    {
                        return(false);
                    }
                }

                // save
                Console.Write("Saving {0}... ", Path.GetFileName(targetName));
                exporter.Save(map, targetPath);
                Console.WriteLine("ok");
                return(true);
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
                return(false);
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(false);
            }
        }
예제 #5
0
        static void RenderOneMap([NotNull] FileSystemInfo fileSystemInfo, [NotNull] string relativeName)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }
            if (relativeName == null)
            {
                throw new ArgumentNullException("relativeName");
            }

            try {
                // if output directory was not given, save to same directory as the mapfile
                if (!outputDirGiven)
                {
                    outputDirName = Paths.GetDirectoryNameOrRoot(fileSystemInfo.FullName);
                }

                // load the mapfile
                Map map;
                if (mapImporter != null)
                {
                    if (!mapImporter.ClaimsName(fileSystemInfo.FullName))
                    {
                        return;
                    }
                    Console.Write("Loading {0}... ", relativeName);
                    map = mapImporter.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", relativeName);
                    map = MapUtility.Load(fileSystemInfo.FullName, tryHard);
                }

                // select target image file name
                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + imageFileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + imageFileExtension;
                }

                // get full target image file name, check if it already exists
                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return;
                    }
                }

                // draw and save
                Console.Write("Drawing... ");
                IsoCatResult result = renderer.Draw(map);
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                if (uncropped)
                {
                    SaveImage(result.Bitmap, targetPath);
                }
                else
                {
                    SaveImage(result.Bitmap.Clone(result.CropRectangle, result.Bitmap.PixelFormat), targetPath);
                }
                Console.WriteLine("ok");
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex);
            }
        }