fCraft.World.SaveBackup C# (CSharp) Method

SaveBackup() public method

Makes a copy of the current map file associated with this world. This does NOT save map to disk, and does NOT guarantee that the most up-to-date copy of the map was backed up.
targetName is null.
public SaveBackup ( [ targetName ) : bool
targetName [ Target file name.
return bool
        public bool SaveBackup( [NotNull] string targetName )
        {
            if ( targetName == null )
                throw new ArgumentNullException( "targetName" );

            if ( !File.Exists( MapFileName ) )
                return false;
            lock ( BackupLock ) {
                DirectoryInfo directory = new DirectoryInfo( Paths.BackupPath );

                if ( !directory.Exists ) {
                    try {
                        directory.Create();
                    } catch ( Exception ex ) {
                        Logger.Log( LogType.Error,
                                    "Map.SaveBackup: Error occurred while trying to create backup directory: {0}", ex );
                        return false;
                    }
                }

                try {
                    HasChangedSinceBackup = false;
                    File.Copy( MapFileName, targetName, true );
                } catch ( Exception ex ) {
                    HasChangedSinceBackup = true;
                    Logger.Log( LogType.Error,
                                "Map.SaveBackup: Error occurred while trying to save backup to \"{0}\": {1}",
                                targetName, ex );
                    return false;
                }

                if ( ConfigKey.MaxBackups.GetInt() > 0 || ConfigKey.MaxBackupSize.GetInt() > 0 ) {
                    DeleteOldBackups( directory );
                }
            }

            Logger.Log( LogType.SystemActivity,
                        "Saved a backup of world {0} to \"{1}\"", Name, targetName );
            return true;
        }