/// <summary> /// Writes an uncompressed raw format in a "raw" folder under the config-file specified folder for later recall during super tile regeneration. /// </summary> /// <param name="locationX">Region location x.</param> /// <param name="locationY">Region location y.</param> /// <param name="locationZ">Region location z.</param> /// <param name="bitmap">Bitmap of the region.</param> public void WriteRawTile(int locationX, int locationY, int locationZ, Bitmap bitmap) { var filename = $"{TileTreeNode.MakeId(locationX, locationY, locationZ)}.tiff"; LOG.Debug($"Writing raw image file {filename} for later use."); try { bitmap.Save(Path.Combine(_rawImageFolder.FullName, filename), ImageFormat.Tiff); } catch (Exception e) { LOG.Error($"Error writing map image tile to disk: {e}"); } }
public Bitmap LoadRawTile(int locationX, int locationY, int locationZ) { var image_path = Path.Combine(_rawImageFolder.FullName, $"{TileTreeNode.MakeId(locationX, locationY, locationZ)}.tiff"); try { return(new Bitmap(Image.FromFile(image_path))); } catch (Exception e) { LOG.Warn($"Error reading raw image tile from disk: {e}"); } return(null); }
// This really doesn't belong here, but where should it be? public void RemoveDeadTiles(DataReader.RDBMap rdbMap, IEnumerable <string> superTiles) { LOG.Info("Checking for base region tiles that need to be removed."); var files = Directory.EnumerateFiles(_tileFolder.FullName); var order = string.Join(string.Empty, _tileNameFormat.Split('{') .Where(str => str.Contains("}")) .Select(str => str[0]) ); var region_tile_regex = new Regex("/" + PrepareTileFilename(Regex.Replace(_tileNameFormat, "{[XYZ]}", "([0-9]+)")) + "$"); var counter = 0; Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => { var oldPriority = Thread.CurrentThread.Priority; Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; var match = region_tile_regex.Match(filename); if (!match.Success) { return; } int x, y, z; switch (order) { case "XYZ": x = int.Parse(match.Groups[1].Value); y = int.Parse(match.Groups[2].Value); z = int.Parse(match.Groups[3].Value); break; case "XZY": x = int.Parse(match.Groups[1].Value); z = int.Parse(match.Groups[2].Value); y = int.Parse(match.Groups[3].Value); break; case "YXZ": y = int.Parse(match.Groups[1].Value); x = int.Parse(match.Groups[2].Value); z = int.Parse(match.Groups[3].Value); break; case "YZX": y = int.Parse(match.Groups[1].Value); z = int.Parse(match.Groups[2].Value); x = int.Parse(match.Groups[3].Value); break; case "ZXY": z = int.Parse(match.Groups[1].Value); x = int.Parse(match.Groups[2].Value); y = int.Parse(match.Groups[3].Value); break; //case "ZYX": default: z = int.Parse(match.Groups[1].Value); y = int.Parse(match.Groups[2].Value); x = int.Parse(match.Groups[3].Value); break; } // Delete all region tiles for regions that have been explicitly removed from the DB. For the new guy: this does not remove regions that are simply just offline. if (z == 1) { DataReader.Region region = null; try { region = rdbMap.GetRegionByLocation(x, y); } catch (KeyNotFoundException) { // Don't care } if (region == null) { // Remove the region tile. try { File.Delete(filename); counter++; } catch (IOException) { // File was in use. Skip for now. LOG.Warn($"Attempted removal of {filename} failed as file was in-use."); } } } else { // Check the super tiles for posible removals. Not a high likelyhood on a growing grid, but will happen in all other cases. var key = TileTreeNode.MakeId(x, y, z); if (!superTiles.Contains(key)) { try { File.Delete(filename); counter++; } catch (IOException) { // File was in use. Skip for now. LOG.Warn($"Attempted removal of {filename} failed as file was in-use."); } } } Thread.CurrentThread.Priority = oldPriority; }); if (counter > 0) { LOG.Info($"Deleted {counter} region tiles for removed regions and consequent super tiles."); } // Go clean up the uuid reverse lookup folder. if (_reverseLookupFolder != null) { counter = 0; var uuid_regex = new Regex("/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"); files = Directory.EnumerateFiles(_reverseLookupFolder.FullName); Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => { var match = uuid_regex.Match(filename); if (!match.Success) { return; } // Delete all uuid lookup files for regions that have been explicitly removed from the DB. For the new guy: this does not remove regions that are simply just offline. var uuid = Guid.Parse(match.Value.Substring(1)); if (!rdbMap.GetRegionUUIDs().Contains(uuid)) { // Remove the file. try { File.Delete(filename); counter++; } catch (IOException) { // File was in use. Skip for now. LOG.Warn($"Attempted removal of {filename} failed as file was in-use."); } } }); if (counter > 0) { LOG.Info($"Deleted {counter} uuid lookup files for removed regions."); } } // Go clean up the raw image folder. if (_rawImageFolder != null) { counter = 0; var raw_image_regex = new Regex("/[^/]+.tiff$"); files = Directory.EnumerateFiles(_rawImageFolder.FullName); Parallel.ForEach(files, PARALLELISM_OPTIONS, (filename) => { var match = raw_image_regex.Match(filename); if (!match.Success) { return; } // Delete all uuid lookup files for regions that have been explicitly removed from the DB. For the new guy: this does not remove regions that are simply just offline. var key = match.Value.Substring(1, match.Value.Length - 6); if (!superTiles.Contains(key)) { // Remove the file. try { File.Delete(filename); counter++; } catch (IOException) { // File was in use. Skip for now. LOG.Warn($"Attempted removal of {filename} failed as file was in-use."); } } }); if (counter > 0) { LOG.Info($"Deleted {counter} raw image files for removed super tiles."); } } }