/// <summary> /// Handles incomplete tiles by copying them to the temporary working directory /// </summary> /// <param name="tile">The incomplete tile to copy</param> private void HandleIncompleteTile(Tile tile) { string tmpDir = FS.BuildTempDir(AppController.OutputPath); string copyTo = FS.BuildTempPath(tmpDir, tile.ZoomLevel.ToString(), tile.Coords.Y.ToString(), tile.GetName(), tile.Atlas); File.Copy(tile.Path, copyTo, true); }
/// <summary> /// Handles a single merge job /// </summary> /// <param name="mergeJob">The merge job to handle</param> private void HandleMergeJob(List <Tile> mergeJob) { int jobSize = mergeJob.Count; if (jobSize > 0) { string tmpDir = FS.BuildTempDir(AppController.OutputPath); Tile currentTile = mergeJob[0]; if (jobSize > 1) { // There are multiple tiles to merge if (ApplicationController.Instance.EnableVerboseLogging) { AppController.Logger.Log("Handling " + jobSize + " tiles with ID " + currentTile.GetName() + " in zoom level " + currentTile.ZoomLevel.ToString() + " and region " + currentTile.Coords.Y.ToString()); } Tile nextTile = mergeJob[1]; string resultPath = Path.Combine(tmpDir, currentTile.ZoomLevel.ToString(), currentTile.Coords.Y.ToString()); // Merge the first two tiles string mergeResult = MergeTiles(currentTile, nextTile, resultPath); Tile resultingTile = new Tile(null, currentTile.ZoomLevel, currentTile.Coords, mergeResult); AppController.Progress.Update(2); if (jobSize > 2) { // Merge all the remaining tiles together for (int i = 2; i < jobSize; i++) { // Clean some memory currentTile.Clean(); currentTile = null; nextTile.Clean(); nextTile = null; currentTile = resultingTile; nextTile = mergeJob[i]; mergeResult = MergeTiles(currentTile, nextTile, resultPath); resultingTile = new Tile(null, currentTile.ZoomLevel, currentTile.Coords, mergeResult); AppController.Progress.Update(1); } } // Copy the merge tile to the final location HandleMergedTile(resultingTile); // Clean up tile memory currentTile.Clean(); nextTile.Clean(); } else { // There are not multiple copies of this tile. Just copy it to final destination if (ApplicationController.Instance.EnableVerboseLogging) { AppController.Logger.Warn("There is only one instance of tile " + currentTile.GetName() + " in zoom level " + currentTile.ZoomLevel.ToString() + " and region " + currentTile.Coords.Y.ToString() + ". Copying it to final destination"); } HandleIncompleteNonMergedTile(currentTile); AppController.Progress.Update(1); } } }
/// <summary> /// Performs the cleanup at the end of the tiling. /// </summary> private void Cleanup() { AppController.Logger.Log("Cleaning up the temporary directory"); Directory.Delete(FS.BuildTempDir(AppController.OutputPath), true); }