Пример #1
0
        static Level GetMuseum(string name, string path)
        {
            Player[] players = PlayerInfo.Online.Items;
            // Since museums are essentially readonly anyways, try to reuse
            //  blocks/CustomBlocks from existing museum to reduce memory usage
            // Lock the search and import so this happens even when
            //  connections occur in quick succession.
            lock (museum_lock) {
                foreach (Player pl in players)
                {
                    Level lvl = pl.level;
                    if (!lvl.IsMuseum || lvl.name != name)
                    {
                        continue;
                    }

                    Level clone = new Level();
                    clone.blocks       = lvl.blocks;
                    clone.CustomBlocks = lvl.CustomBlocks;

                    // Just in case museum was unloaded a split second before
                    if (clone.blocks == null || clone.CustomBlocks == null)
                    {
                        break;
                    }

                    clone.Init(name, lvl.Width, lvl.Height, lvl.Length);
                    return(clone);
                }

                return(IMapImporter.Read(path, name, false));
            }
        }
Пример #2
0
        static void JoinMuseum(Player p, string formattedMuseumName, string mapName, string path)
        {
            Level lvl = IMapImporter.GetFor(path).Read(path, formattedMuseumName, false);

            lvl.MapName = mapName;

            SetLevelProps(lvl);
            Level.LoadMetadata(lvl);
            PlayerActions.ChangeMap(p, lvl);
        }
Пример #3
0
        static void Import(Player p, string url, string map)
        {
            p.Message("downloading");

            byte[] data = HttpUtil.DownloadData(url, p);
            if (data == null)
            {
                return;
            }

            IMapImporter importer = GetImporter(Path.GetExtension(url).ToLower());

            if (importer == null)
            {
                string formats = IMapImporter.Formats.Join(imp => imp.Extension);
                p.Message("%WNo {0} file with that name could be parsed.", formats);
                return;
            }

            if (LevelInfo.MapExists(map))
            {
                p.Message("%WMap {0} already exists. Rename the file to something else before importing",
                          Path.GetFileNameWithoutExtension(map));
                return;
            }

            Level lvl;

            try {
                Stream stream = new MemoryStream(data);
                lvl = importer.Read(stream, map, true);

                MCGalaxy.Commands.World.CmdOverseer.SetPerms(p, lvl);

                try {
                    lvl.Save(true);
                } finally {
                    lvl.Dispose();
                    Server.DoGC();
                }
            } catch (Exception ex) {
                Logger.LogError("Error importing map", ex);
                p.Message("%WImporting map {0} failed. See error logs.", map);
                return;
            }

            string msg = string.Format("{0}%S imported level {1}", p.ColoredName, lvl.ColoredName);

            Chat.MessageGlobal(msg);
        }
Пример #4
0
        static void ImportFrom(Player p, Stream src, string path)
        {
            IMapImporter imp = IMapImporter.GetFor(path);

            if (imp == null)
            {
                string formats = IMapImporter.Formats.Join(x => x.Extension);
                p.Message("&WCannot import {0} as only {1} formats are supported.", path, formats);
                return;
            }

            string map = Path.GetFileNameWithoutExtension(path);

            Import(p, imp, src, map);
        }
Пример #5
0
        bool DoRestore(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            string path   = (string)state;
            Level  source = IMapImporter.Read(path, "templevel", false);

            RestoreSelectionDrawOp op = new RestoreSelectionDrawOp();

            op.Source = source;
            if (DrawOpPerformer.Do(op, null, p, marks))
            {
                return(false);
            }

            // Not high enough draw limit
            source.Dispose();
            return(false);
        }
Пример #6
0
            public void FromMap(string map)
            {
                this.Name = map; MapName = map;
                string  path = LevelInfo.MapPath(map);
                Vec3U16 dims = IMapImporter.GetFor(path).ReadDimensions(path);

                Width          = dims.X; Height = dims.Y; Length = dims.Z;
                BlockDBEntries = BlockDBFile.CountEntries(map);

                path = LevelInfo.PropsPath(map);
                LevelConfig cfg = new LevelConfig();

                cfg.Load(path);

                Config = cfg;
                Visit  = new LevelAccessController(cfg, map, true);
                Build  = new LevelAccessController(cfg, map, false);
            }
Пример #7
0
        public static void RegisterConverter(IMapConverter converter)
        {
            IMapImporter asImporter = converter as IMapImporter;
            IMapExporter asExporter = converter as IMapExporter;

            if (asImporter != null)
            {
                Importers.Add(asImporter.Format, asImporter);
            }
            if (asExporter != null)
            {
                Exporters.Add(asExporter.Format, asExporter);
            }
            if (asImporter == null && asExporter == null)
            {
                throw new ArgumentException("Given converter is neither an IMapImporter nor an IMapExporter.");
            }
        }
Пример #8
0
 void Import(Player p, string path, string name, IMapImporter importer)
 {
     try {
         Level lvl = importer.Read(path + importer.Extension, name, true);
         try {
             lvl.Save(true);
         } finally {
             lvl.Dispose();
             GC.Collect();
             GC.WaitForPendingFinalizers();
         }
     } catch (Exception ex) {
         Server.ErrorLog(ex);
         Player.Message(p, "The map conversion failed.");
         return;
     }
     Player.Message(p, "Converted map!");
     //CmdLoad.LoadLevel(p, name); pls
 }
Пример #9
0
 void Import(Player p, string path, string name, IMapImporter importer)
 {
     if (LevelInfo.MapExists(name))
     {
         p.Message("%WMap {0} already exists. Try renaming the file to something else before importing.", name);
         return;
     }
     try {
         Level lvl = importer.Read(path + importer.Extension, name, true);
         try {
             lvl.Save(true);
         } finally {
             lvl.Dispose();
             Server.DoGC();
         }
     } catch (Exception ex) {
         Logger.LogError("Error importing map", ex);
         p.Message("The map conversion failed.");
         return;
     }
     p.Message("Converted map!");
 }
Пример #10
0
        static void Import(Player p, IMapImporter importer, Stream src, string map)
        {
            if (LevelInfo.MapExists(map))
            {
                p.Message("&WMap {0} already exists. Rename the file to something else before importing", map);
                return;
            }

            try {
                Level lvl = importer.Read(src, map, true);
                try {
                    lvl.Save(true);
                } finally {
                    lvl.Dispose();
                    Server.DoGC();
                }
            } catch (Exception ex) {
                Logger.LogError("Error importing map " + map, ex);
                p.Message("&WImporting map {0} failed. See error logs.", map);
                return;
            }
            p.Message("Successfully imported map {0}!", map);
        }
Пример #11
0
        public static Level Load(string name, string path)
        {
            bool cancel = false;

            OnLevelLoadEvent.Call(name, path, ref cancel);
            if (cancel)
            {
                return(null);
            }

            if (!File.Exists(path))
            {
                Logger.Log(LogType.Warning, "Attempted to load level {0}, but {1} does not exist.", name, path);
                return(null);
            }

            try {
                Level lvl = IMapImporter.GetFor(path).Read(path, name, true);
                lvl.backedup = true;
                LoadMetadata(lvl);
                BotsFile.Load(lvl);

                object locker = ThreadSafeCache.DBCache.GetLocker(name);
                lock (locker) {
                    LevelDB.LoadZones(lvl, name);
                    LevelDB.LoadPortals(lvl, name);
                    LevelDB.LoadMessages(lvl, name);
                }

                Logger.Log(LogType.SystemActivity, "Level \"{0}\" loaded.", lvl.name);
                OnLevelLoadedEvent.Call(lvl);
                return(lvl);
            } catch (Exception ex) {
                Logger.LogError("Error loading map from " + path, ex);
                return(null);
            }
        }
Пример #12
0
        static ReturnCode ParseOptions([NotNull] string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            string jpegQualityString = null,
                   imageFormatName   = null,
                   importerName      = null,
                   angleString       = null,
                   isoCatModeName    = null,
                   regionString      = null;

            string importerList = MapUtility.GetImporters().JoinToString(c => c.Format.ToString());

            bool printHelp = false;

            opts = new OptionSet()
                   .Add("a=|angle=",
                        "Angle (orientation) from which the map is drawn. May be -90, 0, 90, 180, or 270. Default is 0.",
                        o => angleString = o)

                   .Add("f=|filter=",
                        "Pattern to filter input filenames, e.g. \"*.dat\" or \"builder*\". " +
                        "Applicable only when a directory name is given as input.",
                        o => inputFilter = o)

                   .Add("i=|importer=",
                        "Optional: Converter used for importing/loading maps. " +
                        "Available importers: Auto (default), " + importerList,
                        o => importerName = o)

                   .Add("e=|export=",
                        "Image format to use for exporting. " +
                        "Supported formats: PNG (default), BMP, GIF, JPEG, TIFF.",
                        o => imageFormatName = o)

                   .Add("m=|mode=",
                        "Rendering mode. May be \"normal\" (default), \"cut\" (cuts out a quarter of the map, revealing inside), " +
                        "\"peeled\" (strips the outer-most layer of blocks), \"chunk\" (renders only a specified region of the map).",
                        o => isoCatModeName = o)

                   .Add("g|nogradient",
                        "Disables altitude-based gradient/shading on terrain.",
                        o => noGradient = (o != null))

                   .Add("s|noshadows",
                        "Disables rendering of shadows.",
                        o => noShadows = (o != null))

                   .Add("o=|output=",
                        "Path to save images to. " +
                        "If not specified, images will be saved to the maps' directories.",
                        o => outputDirName = o)

                   .Add("y|overwrite",
                        "Do not ask for confirmation to overwrite existing files.",
                        o => overwrite = (o != null))

                   .Add("q=|quality=",
                        "Sets JPEG compression quality. Between 0 and 100. Default is 80. " +
                        "Applicable only when exporting images to .jpg or .jpeg.",
                        o => jpegQualityString = o)

                   .Add("r|recursive",
                        "Look through all subdirectories for map files. " +
                        "Applicable only when a directory name is given as input.",
                        o => recursive = (o != null))

                   .Add("region=",
                        "Region of the map to render. Should be given in following format: \"region=x1,y1,z1,x2,y2,z2\" " +
                        "Applicable only when rendering mode is set to \"chunk\".",
                        o => regionString = o)

                   .Add("w|seethroughwater",
                        "Makes all water see-through, instead of mostly opaque.",
                        o => seeThroughWater = (o != null))

                   .Add("l|seethroughlava",
                        "Makes all lava partially see-through, instead of opaque.",
                        o => seeThroughLava = (o != null))

                   .Add("u|uncropped",
                        "Does not crop the finished map image, leaving some empty space around the edges.",
                        o => uncropped = (o != null))

                   .Add("?|h|help",
                        "Prints out the options.",
                        o => printHelp = (o != null));

            List <string> pathList;

            try {
                pathList = opts.Parse(args);
            } catch (OptionException ex) {
                Console.Error.Write("MapRenderer: ");
                Console.Error.WriteLine(ex.Message);
                PrintHelp();
                return(ReturnCode.ArgumentError);
            }

            if (printHelp)
            {
                PrintHelp();
                Environment.Exit((int)ReturnCode.Success);
            }

            if (pathList.Count != 1)
            {
                Console.Error.WriteLine("MapRenderer: At least one file or directory name required.");
                PrintUsage();
                return(ReturnCode.ArgumentError);
            }
            inputPath = pathList[0];

            // Parse angle
            if (angleString != null && (!Int32.TryParse(angleString, out angle) ||
                                        angle != -90 && angle != 0 && angle != 180 && angle != 270))
            {
                Console.Error.WriteLine("MapRenderer: Angle must be a number: -90, 0, 90, 180, or 270");
                return(ReturnCode.ArgumentError);
            }

            // Parse mode
            if (isoCatModeName != null && !EnumUtil.TryParse(isoCatModeName, out mode, true))
            {
                Console.Error.WriteLine(
                    "MapRenderer: Rendering mode should be: \"normal\", \"cut\", \"peeled\", or \"chunk\".");
                return(ReturnCode.ArgumentError);
            }

            // Parse region (if in chunk mode)
            if (mode == IsoCatMode.Chunk)
            {
                if (regionString == null)
                {
                    Console.Error.WriteLine("MapRenderer: Region parameter is required when mode is set to \"chunk\"");
                    return(ReturnCode.ArgumentError);
                }
                try {
                    string[] regionParts = regionString.Split(',');
                    region = new BoundingBox(Int32.Parse(regionParts[0]), Int32.Parse(regionParts[1]),
                                             Int32.Parse(regionParts[2]),
                                             Int32.Parse(regionParts[3]), Int32.Parse(regionParts[4]),
                                             Int32.Parse(regionParts[5]));
                } catch {
                    Console.Error.WriteLine(
                        "MapRenderer: Region should be specified in the following format: \"--region=x1,y1,z1,x2,y2,z2\"");
                }
            }
            else if (regionString != null)
            {
                Console.Error.WriteLine(
                    "MapRenderer: Region parameter is given, but rendering mode was not set to \"chunk\"");
            }

            // Parse given image format
            if (imageFormatName != null)
            {
                if (imageFormatName.Equals("BMP", StringComparison.OrdinalIgnoreCase))
                {
                    exportFormat       = ImageFormat.Bmp;
                    imageFileExtension = ".bmp";
                }
                else if (imageFormatName.Equals("GIF", StringComparison.OrdinalIgnoreCase))
                {
                    exportFormat       = ImageFormat.Gif;
                    imageFileExtension = ".gif";
                }
                else if (imageFormatName.Equals("JPEG", StringComparison.OrdinalIgnoreCase) ||
                         imageFormatName.Equals("JPG", StringComparison.OrdinalIgnoreCase))
                {
                    exportFormat       = ImageFormat.Jpeg;
                    imageFileExtension = ".jpg";
                }
                else if (imageFormatName.Equals("PNG", StringComparison.OrdinalIgnoreCase))
                {
                    exportFormat       = ImageFormat.Png;
                    imageFileExtension = ".png";
                }
                else if (imageFormatName.Equals("TIFF", StringComparison.OrdinalIgnoreCase) ||
                         imageFormatName.Equals("TIF", StringComparison.OrdinalIgnoreCase))
                {
                    exportFormat       = ImageFormat.Tiff;
                    imageFileExtension = ".tif";
                }
                else
                {
                    Console.Error.WriteLine(
                        "MapRenderer: Image file format should be: BMP, GIF, JPEG, PNG, or TIFF");
                    return(ReturnCode.ArgumentError);
                }
            }

            // Parse JPEG quality
            if (jpegQualityString != null)
            {
                if (exportFormat == ImageFormat.Jpeg)
                {
                    if (!Int32.TryParse(jpegQualityString, out jpegQuality) || jpegQuality < 0 || jpegQuality > 100)
                    {
                        Console.Error.WriteLine(
                            "MapRenderer: JpegQuality parameter should be a number between 0 and 100");
                        return(ReturnCode.ArgumentError);
                    }
                }
                else
                {
                    Console.Error.WriteLine(
                        "MapRenderer: JpegQuality parameter given, but image export format was not set to \"JPEG\".");
                }
            }

            // parse importer name
            if (importerName != null && !importerName.Equals("auto", StringComparison.OrdinalIgnoreCase))
            {
                MapFormat importFormat;
                if (!EnumUtil.TryParse(importerName, out importFormat, true) ||
                    (mapImporter = MapUtility.GetImporter(importFormat)) == null)
                {
                    Console.Error.WriteLine("Unsupported importer \"{0}\"", importerName);
                    PrintUsage();
                    return(ReturnCode.UnrecognizedImporter);
                }
            }

            return(ReturnCode.Success);
        }
Пример #13
0
        static ReturnCode ParseOptions( [NotNull] string[] args ) {
            if( args == null ) throw new ArgumentNullException( "args" );
            string jpegQualityString = null,
                   imageFormatName = null,
                   importerName = null,
                   angleString = null,
                   isoCatModeName = null,
                   regionString = null;

            string importerList = MapUtility.GetImporters().JoinToString( c => c.Format.ToString() );

            bool printHelp = false;

            opts = new OptionSet()
                .Add( "a=|angle=",
                      "Angle (orientation) from which the map is drawn. May be -90, 0, 90, 180, or 270. Default is 0.",
                      o => angleString = o )

                .Add( "f=|filter=",
                      "Pattern to filter input filenames, e.g. \"*.dat\" or \"builder*\". " +
                      "Applicable only when a directory name is given as input.",
                      o => inputFilter = o )

                .Add( "i=|importer=",
                      "Optional: Converter used for importing/loading maps. " +
                      "Available importers: Auto (default), " + importerList,
                      o => importerName = o )

                .Add( "e=|export=",
                      "Image format to use for exporting. " +
                      "Supported formats: PNG (default), BMP, GIF, JPEG, TIFF.",
                      o => imageFormatName = o )

                .Add( "m=|mode=",
                      "Rendering mode. May be \"normal\" (default), \"cut\" (cuts out a quarter of the map, revealing inside), " +
                      "\"peeled\" (strips the outer-most layer of blocks), \"chunk\" (renders only a specified region of the map).",
                      o => isoCatModeName = o )

                .Add( "g|nogradient",
                      "Disables altitude-based gradient/shading on terrain.",
                      o => noGradient = ( o != null ) )

                .Add( "s|noshadows",
                      "Disables rendering of shadows.",
                      o => noShadows = ( o != null ) )

                .Add( "o=|output=",
                      "Path to save images to. " +
                      "If not specified, images will be saved to the maps' directories.",
                      o => outputDirName = o )

                .Add( "y|overwrite",
                      "Do not ask for confirmation to overwrite existing files.",
                      o => overwrite = ( o != null ) )

                .Add( "q=|quality=",
                      "Sets JPEG compression quality. Between 0 and 100. Default is 80. " +
                      "Applicable only when exporting images to .jpg or .jpeg.",
                      o => jpegQualityString = o )

                .Add( "r|recursive",
                      "Look through all subdirectories for map files. " +
                      "Applicable only when a directory name is given as input.",
                      o => recursive = ( o != null ) )

                .Add( "region=",
                      "Region of the map to render. Should be given in following format: \"region=x1,y1,z1,x2,y2,z2\" " +
                      "Applicable only when rendering mode is set to \"chunk\".",
                      o => regionString = o )

                .Add( "w|seethroughwater",
                      "Makes all water see-through, instead of mostly opaque.",
                      o => seeThroughWater = ( o != null ) )

                .Add( "l|seethroughlava",
                      "Makes all lava partially see-through, instead of opaque.",
                      o => seeThroughLava = ( o != null ) )

                .Add( "u|uncropped",
                      "Does not crop the finished map image, leaving some empty space around the edges.",
                      o => uncropped = ( o != null ) )

                .Add( "?|h|help",
                      "Prints out the options.",
                      o => printHelp = ( o != null ) );

            List<string> pathList;
            try {
                pathList = opts.Parse( args );
            } catch( OptionException ex ) {
                Console.Error.Write( "MapRenderer: " );
                Console.Error.WriteLine( ex.Message );
                PrintHelp();
                return ReturnCode.ArgumentError;
            }

            if( printHelp ) {
                PrintHelp();
                Environment.Exit( (int)ReturnCode.Success );
            }

            if( pathList.Count != 1 ) {
                Console.Error.WriteLine( "MapRenderer: At least one file or directory name required." );
                PrintUsage();
                return ReturnCode.ArgumentError;
            }
            inputPath = pathList[0];

            // Parse angle
            if( angleString != null && ( !Int32.TryParse( angleString, out angle ) ||
                                         angle != -90 && angle != 0 && angle != 180 && angle != 270 ) ) {
                Console.Error.WriteLine( "MapRenderer: Angle must be a number: -90, 0, 90, 180, or 270" );
                return ReturnCode.ArgumentError;
            }

            // Parse mode
            if( isoCatModeName != null && !EnumUtil.TryParse( isoCatModeName, out mode, true ) ) {
                Console.Error.WriteLine(
                    "MapRenderer: Rendering mode should be: \"normal\", \"cut\", \"peeled\", or \"chunk\"." );
                return ReturnCode.ArgumentError;
            }

            // Parse region (if in chunk mode)
            if( mode == IsoCatMode.Chunk ) {
                if( regionString == null ) {
                    Console.Error.WriteLine( "MapRenderer: Region parameter is required when mode is set to \"chunk\"" );
                    return ReturnCode.ArgumentError;
                }
                try {
                    string[] regionParts = regionString.Split( ',' );
                    region = new BoundingBox( Int32.Parse( regionParts[0] ), Int32.Parse( regionParts[1] ),
                                              Int32.Parse( regionParts[2] ),
                                              Int32.Parse( regionParts[3] ), Int32.Parse( regionParts[4] ),
                                              Int32.Parse( regionParts[5] ) );
                } catch {
                    Console.Error.WriteLine(
                        "MapRenderer: Region should be specified in the following format: \"--region=x1,y1,z1,x2,y2,z2\"" );
                }
            } else if( regionString != null ) {
                Console.Error.WriteLine(
                    "MapRenderer: Region parameter is given, but rendering mode was not set to \"chunk\"" );
            }

            // Parse given image format
            if( imageFormatName != null ) {
                if( imageFormatName.Equals( "BMP", StringComparison.OrdinalIgnoreCase ) ) {
                    exportFormat = ImageFormat.Bmp;
                    imageFileExtension = ".bmp";
                } else if( imageFormatName.Equals( "GIF", StringComparison.OrdinalIgnoreCase ) ) {
                    exportFormat = ImageFormat.Gif;
                    imageFileExtension = ".gif";
                } else if( imageFormatName.Equals( "JPEG", StringComparison.OrdinalIgnoreCase ) ||
                           imageFormatName.Equals( "JPG", StringComparison.OrdinalIgnoreCase ) ) {
                    exportFormat = ImageFormat.Jpeg;
                    imageFileExtension = ".jpg";
                } else if( imageFormatName.Equals( "PNG", StringComparison.OrdinalIgnoreCase ) ) {
                    exportFormat = ImageFormat.Png;
                    imageFileExtension = ".png";
                } else if( imageFormatName.Equals( "TIFF", StringComparison.OrdinalIgnoreCase ) ||
                           imageFormatName.Equals( "TIF", StringComparison.OrdinalIgnoreCase ) ) {
                    exportFormat = ImageFormat.Tiff;
                    imageFileExtension = ".tif";
                } else {
                    Console.Error.WriteLine(
                        "MapRenderer: Image file format should be: BMP, GIF, JPEG, PNG, or TIFF" );
                    return ReturnCode.ArgumentError;
                }
            }

            // Parse JPEG quality
            if( jpegQualityString != null ) {
                if( exportFormat == ImageFormat.Jpeg ) {
                    if( !Int32.TryParse( jpegQualityString, out jpegQuality ) || jpegQuality < 0 || jpegQuality > 100 ) {
                        Console.Error.WriteLine(
                            "MapRenderer: JpegQuality parameter should be a number between 0 and 100" );
                        return ReturnCode.ArgumentError;
                    }
                } else {
                    Console.Error.WriteLine(
                        "MapRenderer: JpegQuality parameter given, but image export format was not set to \"JPEG\"." );
                }
            }

            // parse importer name
            if( importerName != null && !importerName.Equals( "auto", StringComparison.OrdinalIgnoreCase ) ) {
                MapFormat importFormat;
                if( !EnumUtil.TryParse( importerName, out importFormat, true ) ||
                    ( mapImporter = MapUtility.GetImporter( importFormat ) ) == null ) {
                    Console.Error.WriteLine( "Unsupported importer \"{0}\"", importerName );
                    PrintUsage();
                    return ReturnCode.UnrecognizedImporter;
                }
            }

            return ReturnCode.Success;
        }
 public override void Load(bool startup)
 {
     schem = new SchematicImporter();
     IMapImporter.Formats.Add(schem);
 }
Пример #15
0
 public override void Load(bool startup)
 {
     importer = new VoxImporter();
     IMapImporter.Formats.Add(importer);
 }
Пример #16
0
        static int Main( string[] args ) {
            Logger.Logged += OnLogged;

            ReturnCode optionParsingResult = ParseOptions( args );
            if( optionParsingResult != ReturnCode.Success ) {
                return (int)optionParsingResult;
            }

            // parse importer name
            if( importerName != null && !importerName.Equals( "auto", StringComparison.OrdinalIgnoreCase ) ) {
                MapFormat importFormat;
                if( !EnumUtil.TryParse( importerName, out importFormat, true )  ) {
                    Console.Error.WriteLine( "Unsupported importer \"{0}\"", importerName );
                    PrintUsage();
                    return (int)ReturnCode.UnrecognizedImporter;
                }
                importer = MapUtility.GetImporter( importFormat );
                if( importer == null ) {
                    Console.Error.WriteLine( "Loading from \"{0}\" is not supported", importFormat );
                    PrintUsage();
                    return (int)ReturnCode.UnsupportedLoadFormat;
                }
            }

            // parse exporter format
            MapFormat exportFormat;
            if( !EnumUtil.TryParse( exporterName, out exportFormat, true ) ) {
                Console.Error.WriteLine( "Unrecognized exporter \"{0}\"", exporterName );
                PrintUsage();
                return (int)ReturnCode.UnrecognizedExporter;
            }

            exporter = MapUtility.GetExporter( exportFormat );
            if( exporter == null ) {
                Console.Error.WriteLine( "Saving to \"{0}\" is not supported", exportFormat );
                PrintUsage();
                return (int)ReturnCode.UnsupportedSaveFormat;
            }

            // check if input path exists, and if it's a file or directory
            bool directoryMode;
            try {
                if( File.Exists( inputPath ) ) {
                    directoryMode = false;
                    if( outputDirName == null ) {
                        outputDirName = Paths.GetDirectoryNameOrRoot( inputPath );
                    }

                } else if( Directory.Exists( inputPath ) ) {
                    directoryMode = true;
                    if( outputDirName == null ) {
                        outputDirName = Paths.GetDirectoryNameOrRoot( inputPath );
                    }

                } else {
                    Console.Error.WriteLine( "MapConverter: Cannot locate \"{0}\"", inputPath );
                    return (int)ReturnCode.InputDirNotFound;
                }

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

            } catch( Exception ex ) {
                Console.Error.WriteLine( "MapConverter: {0}: {1}",
                                         ex.GetType().Name,
                                         ex.Message );
                return (int)ReturnCode.PathError;
            }

            // check recursive flag
            if( recursive && !directoryMode ) {
                Console.Error.WriteLine( "MapConverter: Recursive flag is given, but input is not a directory." );
            }

            // check input filter
            if( inputFilter != null && !directoryMode ) {
                Console.Error.WriteLine( "MapConverter: Filter param is given, but input is not a directory." );
            }

            if( !recursive && importer != null && importer.StorageType == MapStorageType.Directory ) {
                // single-directory conversion
                ConvertOneMap( new DirectoryInfo( inputPath ) );

            } else if( !directoryMode ) {
                // single-file conversion
                ConvertOneMap( new FileInfo( inputPath ) );

            } else {
                // possible single-directory conversion
                if( !recursive && ConvertOneMap( new DirectoryInfo( inputPath ) ) ) {
                    return (int)ReturnCode.Success;
                }

                // otherwise, go through all files inside the given directory
                SearchOption recursiveOption = ( recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly );
                DirectoryInfo inputDirInfo = new DirectoryInfo( inputPath );
                if( inputFilter == null ) inputFilter = "*";
                foreach( var dir in inputDirInfo.GetDirectories( inputFilter, recursiveOption ) ) {
                    ConvertOneMap( dir );
                }
                foreach( var file in inputDirInfo.GetFiles( inputFilter, recursiveOption ) ) {
                    ConvertOneMap( file );
                }
            }

            return (int)ReturnCode.Success;
        }
Пример #17
0
        static int Main( string[] args ) {
            Logger.Logged += OnLogged;
            Logger.DisableFileLogging();

            ReturnCode optionParsingResult = ParseOptions( args );
            if( optionParsingResult != ReturnCode.Success ) {
                return (int)optionParsingResult;
            }

            // parse importer name
            if( importerName != null && !importerName.Equals( "auto", StringComparison.OrdinalIgnoreCase ) ) {
                MapFormat importFormat;
                if( !EnumUtil.TryParse( importerName, out importFormat, true ) ) {
                    Console.Error.WriteLine( "MapConverter: Unsupported importer \"{0}\"", importerName );
                    PrintUsage();
                    return (int)ReturnCode.UnrecognizedImporter;
                }
                importer = MapUtility.GetImporter( importFormat );
                if( importer == null ) {
                    Console.Error.WriteLine( "MapConverter: Loading from \"{0}\" is not supported", importFormat );
                    PrintUsage();
                    return (int)ReturnCode.UnsupportedLoadFormat;
                }
            }

            // parse exporter format
            MapFormat exportFormat;
            if( !EnumUtil.TryParse( exporterName, out exportFormat, true ) ) {
                Console.Error.WriteLine( "MapConverter: Unrecognized exporter \"{0}\"", exporterName );
                PrintUsage();
                return (int)ReturnCode.UnrecognizedExporter;
            }
            exporter = MapUtility.GetExporter( exportFormat );
            if( exporter == null ) {
                Console.Error.WriteLine( "MapConverter: Saving to \"{0}\" is not supported", exportFormat );
                PrintUsage();
                return (int)ReturnCode.UnsupportedSaveFormat;
            }

            // check input paths
            bool hadFile = false,
                 hadDir = false;
            foreach( string inputPath in inputPathList ) {
                if( hadDir ) {
                    Console.Error.WriteLine( "MapConverter: Only one directory may be specified at a time." );
                    return (int)ReturnCode.ArgumentError;
                }
                // check if input path exists, and if it's a file or directory
                try {
                    if( File.Exists( inputPath ) ) {
                        hadFile = true;
                    } else if( Directory.Exists( inputPath ) ) {
                        hadDir = true;
                        if( hadFile ) {
                            Console.Error.WriteLine( "MapConverter: Cannot mix directories and files in input." );
                            return (int)ReturnCode.ArgumentError;
                        }
                        directoryMode = true;
                        if( !outputDirGiven ) {
                            outputDirName = inputPath;
                        }
                    } else {
                        Console.Error.WriteLine( "MapConverter: Cannot locate \"{0}\"", inputPath );
                        return (int)ReturnCode.InputPathNotFound;
                    }
                } catch( Exception ex ) {
                    Console.Error.WriteLine( "MapConverter: {0}: {1}",
                                             ex.GetType().Name,
                                             ex.Message );
                    return (int)ReturnCode.PathError;
                }
            }

            // check recursive flag
            if( recursive && !directoryMode ) {
                Console.Error.WriteLine( "MapConverter: Recursive flag is given, but input is not a directory." );
                return (int)ReturnCode.ArgumentError;
            }

            // check input filter
            if( inputFilter != null && !directoryMode ) {
                Console.Error.WriteLine( "MapConverter: Filter param is given, but input is not a directory." );
                return (int)ReturnCode.ArgumentError;
            }

            // check regex filter
            if( useRegex ) {
                try {
                    filterRegex = new Regex( inputFilter );
                } catch( ArgumentException ex ) {
                    Console.Error.WriteLine( "MapConverter: Cannot parse filter regex: {0}",
                                             ex.Message );
                    return (int)ReturnCode.ArgumentError;
                }
            }

            // check if output dir exists; create it if needed
            if( outputDirName != null ) {
                try {
                    if( !Directory.Exists( outputDirName ) ) {
                        Directory.CreateDirectory( outputDirName );
                    }
                } catch( Exception ex ) {
                    Console.Error.WriteLine( "MapRenderer: Error checking output directory: {0}: {1}",
                                             ex.GetType().Name,
                                             ex.Message );
                }
            }

            // process inputs, one path at a time
            foreach( string inputPath in inputPathList ) {
                ReturnCode code = ProcessInputPath( inputPath );
                if( code != ReturnCode.Success ) {
                    return (int)code;
                }
            }
            return (int)ReturnCode.Success;
        }
Пример #18
0
        static int Main( string[] args ) {
            Logger.Logged += OnLogged;
            Logger.DisableFileLogging();

            ReturnCode optionParsingResult = ParseOptions( args );
            if( optionParsingResult != ReturnCode.Success ) {
                return (int)optionParsingResult;
            }

            // parse importer name
            if( importerName != null && !importerName.Equals( "auto", StringComparison.OrdinalIgnoreCase ) ) {
                MapFormat importFormat;
                if( !EnumUtil.TryParse( importerName, out importFormat, true ) ) {
                    Console.Error.WriteLine( "Unsupported importer \"{0}\"", importerName );
                    PrintUsage();
                    return (int)ReturnCode.UnrecognizedImporter;
                }
                mapImporter = MapUtility.GetImporter( importFormat );
                if( mapImporter == null ) {
                    Console.Error.WriteLine( "Loading from \"{0}\" is not supported", importFormat );
                    PrintUsage();
                    return (int)ReturnCode.UnsupportedLoadFormat;
                }
            }

            // check input paths
            bool hadFile = false,
                 hadDir = false;
            foreach( string inputPath in inputPathList ) {
                if( hadDir ) {
                    Console.Error.WriteLine( "MapRenderer: Only one directory may be specified at a time." );
                    return (int)ReturnCode.ArgumentError;
                }
                // check if input path exists, and if it's a file or directory
                try {
                    if( File.Exists( inputPath ) ) {
                        hadFile = true;
                    } else if( Directory.Exists( inputPath ) ) {
                        hadDir = true;
                        if( hadFile ) {
                            Console.Error.WriteLine( "MapRenderer: Cannot mix directories and files in input." );
                            return (int)ReturnCode.ArgumentError;
                        }
                        directoryMode = true;
                        if( !outputDirGiven ) {
                            outputDirName = inputPath;
                        }
                    } else {
                        Console.Error.WriteLine( "MapRenderer: Cannot locate \"{0}\"", inputPath );
                        return (int)ReturnCode.InputPathNotFound;
                    }
                } catch( Exception ex ) {
                    Console.Error.WriteLine( "MapRenderer: {0}: {1}",
                                             ex.GetType().Name,
                                             ex.Message );
                    return (int)ReturnCode.PathError;
                }
            }

            // initialize image encoder
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
            imageEncoder = codecs.FirstOrDefault( codec => codec.FormatID == exportFormat.Guid );
            if( imageEncoder == null ) {
                Console.Error.WriteLine( "MapRenderer: Specified image encoder is not supported." );
                return (int)ReturnCode.UnsupportedSaveFormat;
            }

            // create and configure the renderer
            renderer = new IsoCat {
                SeeThroughLava = seeThroughLava,
                SeeThroughWater = seeThroughWater,
                Mode = mode,
                Gradient = !noGradient,
                DrawShadows = !noShadows
            };
            if( mode == IsoCatMode.Chunk ) {
                renderer.ChunkCoords[0] = region.XMin;
                renderer.ChunkCoords[1] = region.YMin;
                renderer.ChunkCoords[2] = region.ZMin;
                renderer.ChunkCoords[3] = region.XMax;
                renderer.ChunkCoords[4] = region.YMax;
                renderer.ChunkCoords[5] = region.ZMax;
            }
            switch( angle ) {
                case 90:
                    renderer.Rotation = 1;
                    break;
                case 180:
                    renderer.Rotation = 2;
                    break;
                case 270:
                case -90:
                    renderer.Rotation = 3;
                    break;
            }

            // check recursive flag
            if( recursive && !directoryMode ) {
                Console.Error.WriteLine( "MapRenderer: Recursive flag is given, but input is not a directory." );
                return (int)ReturnCode.ArgumentError;
            }

            // check input filter
            if( inputFilter != null && !directoryMode ) {
                Console.Error.WriteLine( "MapRenderer: Filter param is given, but input is not a directory." );
                return (int)ReturnCode.ArgumentError;
            }

            // check regex filter
            if( useRegex ) {
                try {
                    filterRegex = new Regex( inputFilter );
                } catch( ArgumentException ex ) {
                    Console.Error.WriteLine( "MapRenderer: Cannot parse filter regex: {0}",
                                             ex.Message );
                    return (int)ReturnCode.ArgumentError;
                }
            }

            // check if output dir exists; create it if needed
            if( outputDirName != null ) {
                try {
                    if( !Directory.Exists( outputDirName ) ) {
                        Directory.CreateDirectory( outputDirName );
                    }
                } catch( Exception ex ) {
                    Console.Error.WriteLine( "MapRenderer: Error checking output directory: {0}: {1}",
                                             ex.GetType().Name, ex.Message );
                }
            }

            // process inputs, one path at a time
            foreach( string inputPath in inputPathList ) {
                ReturnCode code = ProcessInputPath( inputPath );
                if( code != ReturnCode.Success ) {
                    return (int)code;
                }
            }
            return (int)ReturnCode.Success;
        }
Пример #19
0
        static int Main(string[] args)
        {
            Logger.Logged += OnLogged;
            Logger.DisableFileLogging();

            ReturnCode optionParsingResult = ParseOptions(args);

            if (optionParsingResult != ReturnCode.Success)
            {
                return((int)optionParsingResult);
            }

            // parse importer name
            if (importerName != null && !importerName.Equals("auto", StringComparison.OrdinalIgnoreCase))
            {
                MapFormat importFormat;
                if (!EnumUtil.TryParse(importerName, out importFormat, true))
                {
                    Console.Error.WriteLine("MapConverter: Unsupported importer \"{0}\"", importerName);
                    PrintUsage();
                    return((int)ReturnCode.UnrecognizedImporter);
                }
                importer = MapUtility.GetImporter(importFormat);
                if (importer == null)
                {
                    Console.Error.WriteLine("MapConverter: Loading from \"{0}\" is not supported", importFormat);
                    PrintUsage();
                    return((int)ReturnCode.UnsupportedLoadFormat);
                }
            }

            // parse exporter format
            MapFormat exportFormat;

            if (!EnumUtil.TryParse(exporterName, out exportFormat, true))
            {
                Console.Error.WriteLine("MapConverter: Unrecognized exporter \"{0}\"", exporterName);
                PrintUsage();
                return((int)ReturnCode.UnrecognizedExporter);
            }
            exporter = MapUtility.GetExporter(exportFormat);
            if (exporter == null)
            {
                Console.Error.WriteLine("MapConverter: Saving to \"{0}\" is not supported", exportFormat);
                PrintUsage();
                return((int)ReturnCode.UnsupportedSaveFormat);
            }

            // check input paths
            bool hadFile = false,
                 hadDir  = false;

            foreach (string inputPath in inputPathList)
            {
                if (hadDir)
                {
                    Console.Error.WriteLine("MapConverter: Only one directory may be specified at a time.");
                    return((int)ReturnCode.ArgumentError);
                }
                // check if input path exists, and if it's a file or directory
                try {
                    if (File.Exists(inputPath))
                    {
                        hadFile = true;
                    }
                    else if (Directory.Exists(inputPath))
                    {
                        hadDir = true;
                        if (hadFile)
                        {
                            Console.Error.WriteLine("MapConverter: Cannot mix directories and files in input.");
                            return((int)ReturnCode.ArgumentError);
                        }
                        directoryMode = true;
                        if (!outputDirGiven)
                        {
                            outputDirName = inputPath;
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("MapConverter: Cannot locate \"{0}\"", inputPath);
                        return((int)ReturnCode.InputPathNotFound);
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine("MapConverter: {0}: {1}",
                                            ex.GetType().Name,
                                            ex.Message);
                    return((int)ReturnCode.PathError);
                }
            }

            // check recursive flag
            if (recursive && !directoryMode)
            {
                Console.Error.WriteLine("MapConverter: Recursive flag is given, but input is not a directory.");
                return((int)ReturnCode.ArgumentError);
            }

            // check input filter
            if (inputFilter != null && !directoryMode)
            {
                Console.Error.WriteLine("MapConverter: Filter param is given, but input is not a directory.");
                return((int)ReturnCode.ArgumentError);
            }

            // check regex filter
            if (useRegex)
            {
                try {
                    filterRegex = new Regex(inputFilter);
                } catch (ArgumentException ex) {
                    Console.Error.WriteLine("MapConverter: Cannot parse filter regex: {0}",
                                            ex.Message);
                    return((int)ReturnCode.ArgumentError);
                }
            }

            // check if output dir exists; create it if needed
            if (outputDirName != null)
            {
                try {
                    if (!Directory.Exists(outputDirName))
                    {
                        Directory.CreateDirectory(outputDirName);
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine("MapRenderer: Error checking output directory: {0}: {1}",
                                            ex.GetType().Name,
                                            ex.Message);
                }
            }

            // process inputs, one path at a time
            foreach (string inputPath in inputPathList)
            {
                ReturnCode code = ProcessInputPath(inputPath);
                if (code != ReturnCode.Success)
                {
                    return((int)code);
                }
            }
            return((int)ReturnCode.Success);
        }
Пример #20
0
        static int Main(string[] args)
        {
            Logger.Logged += OnLogged;

            ReturnCode optionParsingResult = ParseOptions(args);

            if (optionParsingResult != ReturnCode.Success)
            {
                return((int)optionParsingResult);
            }

            // parse importer name
            if (importerName != null && !importerName.Equals("auto", StringComparison.OrdinalIgnoreCase))
            {
                MapFormat importFormat;
                if (!EnumUtil.TryParse(importerName, out importFormat, true) ||
                    (importer = MapUtility.GetImporter(importFormat)) == null)
                {
                    Console.Error.WriteLine("Unsupported importer \"{0}\"", importerName);
                    PrintUsage();
                    return((int)ReturnCode.UnrecognizedImporter);
                }
            }

            // parse exporter format
            MapFormat exportFormat;

            if (!EnumUtil.TryParse(exporterName, out exportFormat, true) ||
                (exporter = MapUtility.GetExporter(exportFormat)) == null)
            {
                Console.Error.WriteLine("Unsupported exporter \"{0}\"", exporterName);
                PrintUsage();
                return((int)ReturnCode.UnrecognizedExporter);
            }

            // check if input path exists, and if it's a file or directory
            bool directoryMode;

            try {
                if (File.Exists(inputPath))
                {
                    directoryMode = false;
                    if (outputDirName == null)
                    {
                        outputDirName = Paths.GetDirectoryNameOrRoot(inputPath);
                    }
                }
                else if (Directory.Exists(inputPath))
                {
                    directoryMode = true;
                    if (outputDirName == null)
                    {
                        outputDirName = Paths.GetDirectoryNameOrRoot(inputPath);
                    }
                }
                else
                {
                    Console.Error.WriteLine("MapConverter: Cannot locate \"{0}\"", inputPath);
                    return((int)ReturnCode.InputDirNotFound);
                }

                if (!Directory.Exists(outputDirName))
                {
                    Directory.CreateDirectory(outputDirName);
                }
            } catch (Exception ex) {
                Console.Error.WriteLine("MapConverter: {0}: {1}",
                                        ex.GetType().Name,
                                        ex.Message);
                return((int)ReturnCode.PathError);
            }

            // check recursive flag
            if (recursive && !directoryMode)
            {
                Console.Error.WriteLine("MapConverter: Recursive flag is given, but input is not a directory.");
            }

            // check input filter
            if (inputFilter != null && !directoryMode)
            {
                Console.Error.WriteLine("MapConverter: Filter param is given, but input is not a directory.");
            }

            if (!recursive && importer != null && importer.StorageType == MapStorageType.Directory)
            {
                // single-directory conversion
                ConvertOneMap(new DirectoryInfo(inputPath));
            }
            else if (!directoryMode)
            {
                // single-file conversion
                ConvertOneMap(new FileInfo(inputPath));
            }
            else
            {
                // possible single-directory conversion
                if (!recursive && ConvertOneMap(new DirectoryInfo(inputPath)))
                {
                    return((int)ReturnCode.Success);
                }

                // otherwise, go through all files inside the given directory
                SearchOption  recursiveOption = (recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                DirectoryInfo inputDirInfo    = new DirectoryInfo(inputPath);
                if (inputFilter == null)
                {
                    inputFilter = "*";
                }
                foreach (var dir in inputDirInfo.GetDirectories(inputFilter, recursiveOption))
                {
                    ConvertOneMap(dir);
                }
                foreach (var file in inputDirInfo.GetFiles(inputFilter, recursiveOption))
                {
                    ConvertOneMap(file);
                }
            }

            return((int)ReturnCode.Success);
        }
Пример #21
0
        static int Main(string[] args)
        {
            Logger.Logged += OnLogged;
            Logger.DisableFileLogging();

            ReturnCode optionParsingResult = ParseOptions(args);

            if (optionParsingResult != ReturnCode.Success)
            {
                return((int)optionParsingResult);
            }

            // parse importer name
            if (importerName != null && !importerName.Equals("auto", StringComparison.OrdinalIgnoreCase))
            {
                MapFormat importFormat;
                if (!EnumUtil.TryParse(importerName, out importFormat, true))
                {
                    Console.Error.WriteLine("Unsupported importer \"{0}\"", importerName);
                    PrintUsage();
                    return((int)ReturnCode.UnrecognizedImporter);
                }
                mapImporter = MapUtility.GetImporter(importFormat);
                if (mapImporter == null)
                {
                    Console.Error.WriteLine("Loading from \"{0}\" is not supported", importFormat);
                    PrintUsage();
                    return((int)ReturnCode.UnsupportedLoadFormat);
                }
            }

            // check input paths
            bool hadFile = false,
                 hadDir  = false;

            foreach (string inputPath in inputPathList)
            {
                if (hadDir)
                {
                    Console.Error.WriteLine("MapRenderer: Only one directory may be specified at a time.");
                    return((int)ReturnCode.ArgumentError);
                }
                // check if input path exists, and if it's a file or directory
                try {
                    if (File.Exists(inputPath))
                    {
                        hadFile = true;
                    }
                    else if (Directory.Exists(inputPath))
                    {
                        hadDir = true;
                        if (hadFile)
                        {
                            Console.Error.WriteLine("MapRenderer: Cannot mix directories and files in input.");
                            return((int)ReturnCode.ArgumentError);
                        }
                        directoryMode = true;
                        if (!outputDirGiven)
                        {
                            outputDirName = inputPath;
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("MapRenderer: Cannot locate \"{0}\"", inputPath);
                        return((int)ReturnCode.InputPathNotFound);
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine("MapRenderer: {0}: {1}",
                                            ex.GetType().Name,
                                            ex.Message);
                    return((int)ReturnCode.PathError);
                }
            }

            // initialize image encoder
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
            imageEncoder = codecs.FirstOrDefault(codec => codec.FormatID == exportFormat.Guid);
            if (imageEncoder == null)
            {
                Console.Error.WriteLine("MapRenderer: Specified image encoder is not supported.");
                return((int)ReturnCode.UnsupportedSaveFormat);
            }

            // create and configure the renderer
            renderer = new IsoCat {
                SeeThroughLava  = seeThroughLava,
                SeeThroughWater = seeThroughWater,
                Mode            = mode,
                Gradient        = !noGradient,
                DrawShadows     = !noShadows
            };
            if (mode == IsoCatMode.Chunk)
            {
                renderer.ChunkCoords[0] = region.XMin;
                renderer.ChunkCoords[1] = region.YMin;
                renderer.ChunkCoords[2] = region.ZMin;
                renderer.ChunkCoords[3] = region.XMax;
                renderer.ChunkCoords[4] = region.YMax;
                renderer.ChunkCoords[5] = region.ZMax;
            }
            switch (angle)
            {
            case 90:
                renderer.Rotation = 1;
                break;

            case 180:
                renderer.Rotation = 2;
                break;

            case 270:
            case -90:
                renderer.Rotation = 3;
                break;
            }

            // check recursive flag
            if (recursive && !directoryMode)
            {
                Console.Error.WriteLine("MapRenderer: Recursive flag is given, but input is not a directory.");
                return((int)ReturnCode.ArgumentError);
            }

            // check input filter
            if (inputFilter != null && !directoryMode)
            {
                Console.Error.WriteLine("MapRenderer: Filter param is given, but input is not a directory.");
                return((int)ReturnCode.ArgumentError);
            }

            // check regex filter
            if (useRegex)
            {
                try {
                    filterRegex = new Regex(inputFilter);
                } catch (ArgumentException ex) {
                    Console.Error.WriteLine("MapRenderer: Cannot parse filter regex: {0}",
                                            ex.Message);
                    return((int)ReturnCode.ArgumentError);
                }
            }

            // check if output dir exists; create it if needed
            if (outputDirName != null)
            {
                try {
                    if (!Directory.Exists(outputDirName))
                    {
                        Directory.CreateDirectory(outputDirName);
                    }
                } catch (Exception ex) {
                    Console.Error.WriteLine("MapRenderer: Error checking output directory: {0}: {1}",
                                            ex.GetType().Name, ex.Message);
                }
            }

            // process inputs, one path at a time
            foreach (string inputPath in inputPathList)
            {
                ReturnCode code = ProcessInputPath(inputPath);
                if (code != ReturnCode.Success)
                {
                    return((int)code);
                }
            }
            return((int)ReturnCode.Success);
        }