Exemplo n.º 1
0
        public DialogResult ConfirmSceneryInstallation(AFS2GridSquare afs2GridSquare)
        {
            var gridSquareDirectory = AeroSceneryManager.Instance.Settings.WorkingDirectory + afs2GridSquare.Name;

            DialogResult result = DialogResult.No;

            // Does this grid square exist
            if (Directory.Exists(gridSquareDirectory))
            {
                // Do we have an Aerofly folder to install into?
                string afsSceneryInstallDirectory = DirectoryHelper.FindAFSSceneryInstallDirectory(AeroSceneryManager.Instance.Settings);

                if (afsSceneryInstallDirectory != null)
                {
                    // Confirm that the user does want to install scenery
                    StringBuilder sb = new StringBuilder();

                    sb.AppendLine("Are you sure you want to install all scenery for this grid square?");
                    sb.AppendLine("Any existing files in the same destination folder will be overwritten.");
                    sb.AppendLine("");
                    sb.AppendLine(String.Format("Destination: {0}", afsSceneryInstallDirectory));

                    var messageBox = new CustomMessageBox(sb.ToString(),
                                                          "AeroScenery",
                                                          MessageBoxIcon.Question);

                    messageBox.SetButtons(
                        new string[] { "Yes", "No" },
                        new DialogResult[] { DialogResult.Yes, DialogResult.No });

                    result = messageBox.ShowDialog();
                }
                else
                {
                    // Can't find anywhere to install
                    StringBuilder sb = new StringBuilder();

                    sb.AppendLine("Could not find a location to install to.");
                    sb.AppendLine("Either Aerofly FS2 is not installed or your 'My Documents\\Aerofly FS 2' folder has been removed.");

                    var messageBox = new CustomMessageBox(sb.ToString(),
                                                          "AeroScenery",
                                                          MessageBoxIcon.Error);

                    result = messageBox.ShowDialog();
                }
            }
            else
            {
            }

            return(result);
        }
Exemplo n.º 2
0
        public GridSquare ToModel(AFS2GridSquare aFS2GridSquare)
        {
            GridSquare gridSquare = new GridSquare();

            gridSquare.Name          = aFS2GridSquare.Name;
            gridSquare.NorthLatitude = aFS2GridSquare.Coordinates[0].Lat;
            gridSquare.EastLongitude = aFS2GridSquare.Coordinates[1].Lng;
            gridSquare.SouthLatitude = aFS2GridSquare.Coordinates[2].Lat;
            gridSquare.WestLongitude = aFS2GridSquare.Coordinates[3].Lng;

            gridSquare.Level = aFS2GridSquare.Level;

            return(gridSquare);
        }
Exemplo n.º 3
0
        public async Task InstallSceneryAsync(AFS2GridSquare afs2GridSquare, List <string> ttcFiles)
        {
            var task = Task.Run(() =>
            {
                var gridSquareDirectory = AeroSceneryManager.Instance.Settings.WorkingDirectory + afs2GridSquare.Name;

                // Does this grid square exist
                if (Directory.Exists(gridSquareDirectory))
                {
                    // Do we have an Aerofly folder to install into?
                    string afsSceneryInstallDirectory = DirectoryHelper.FindAFSSceneryInstallDirectory(AeroSceneryManager.Instance.Settings);

                    if (afsSceneryInstallDirectory != null)
                    {
                        // We install ttc files into a folder of the level 9 grid square containing the selected grid square
                        var level9GridSquare = afs2GridSquare;

                        if (afs2GridSquare.Level != 9)
                        {
                            level9GridSquare = this.afsGrid.GetGridSquareAtLatLon(afs2GridSquare.GetCenter().Lat, afs2GridSquare.GetCenter().Lng, 9);
                        }

                        // This is now the level9 grid square that contains the selected grid square
                        var afsSceneryFinalInstallDirectory = String.Format(@"{0}\{1}", afsSceneryInstallDirectory, level9GridSquare.Name);

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

                        // Copy the files over
                        foreach (var ttcFilePath in ttcFiles)
                        {
                            var filename        = Path.GetFileName(ttcFilePath);
                            var destinationPath = String.Format(@"{0}/{1}", afsSceneryFinalInstallDirectory, filename);

                            // We want to overwrite files so that users can install updated files again
                            if (File.Exists(destinationPath))
                            {
                                File.Delete(destinationPath);
                            }
                            File.Copy(ttcFilePath, destinationPath);
                        }
                    }
                }
            });

            await task;
        }
Exemplo n.º 4
0
        public AFS2GridSquare ToAFS2GridSquare(GridSquare gridSquare)
        {
            AFS2GridSquare afsS2GridSquare = new AFS2GridSquare();

            afsS2GridSquare.Name = gridSquare.Name;

            var nwCorner = new PointLatLng(gridSquare.NorthLatitude, gridSquare.WestLongitude);
            var neCorner = new PointLatLng(gridSquare.NorthLatitude, gridSquare.EastLongitude);
            var seCorner = new PointLatLng(gridSquare.SouthLatitude, gridSquare.EastLongitude);
            var swCorner = new PointLatLng(gridSquare.SouthLatitude, gridSquare.WestLongitude);

            afsS2GridSquare.Coordinates.Add(nwCorner);
            afsS2GridSquare.Coordinates.Add(neCorner);
            afsS2GridSquare.Coordinates.Add(seCorner);
            afsS2GridSquare.Coordinates.Add(swCorner);

            return(afsS2GridSquare);
        }
Exemplo n.º 5
0
        public DialogResult?CheckForDuplicateTTCFiles(AFS2GridSquare afs2GridSquare, out List <string> ttcFiles)
        {
            // A null dialog result means that there are no duplicates
            DialogResult?result = null;

            var gridSquareDirectory = AeroSceneryManager.Instance.Settings.WorkingDirectory + afs2GridSquare.Name;

            ttcFiles = this.EnumerateFilesRecursive(gridSquareDirectory, "*.ttc").ToList();

            List <string> ttcFileNames = new List <string>();

            foreach (var ttcFile in ttcFiles)
            {
                var tccFileName = Path.GetFileName(ttcFile);
                ttcFileNames.Add(tccFileName);
            }

            // Check for duplicate ttc files
            if (ttcFileNames.Count != ttcFileNames.Distinct().Count())
            {
                StringBuilder sbDuplicates = new StringBuilder();

                sbDuplicates.AppendLine(String.Format("Duplicate ttc files were found in the folder for grid square ({0})", afs2GridSquare.Name));
                sbDuplicates.AppendLine("This may be because you have downloaded this grid square with multiple map image providers.");
                sbDuplicates.AppendLine("If you continue with the install you may get a mismatched set of ttc files.");

                var duplicatesMessageBox = new CustomMessageBox(sbDuplicates.ToString(),
                                                                "AeroScenery",
                                                                MessageBoxIcon.Warning);

                duplicatesMessageBox.SetButtons(
                    new string[] { "Continue", "Cancel" },
                    new DialogResult[] { DialogResult.OK, DialogResult.Cancel });

                result = duplicatesMessageBox.ShowDialog();
            }

            return(result);
        }
Exemplo n.º 6
0
        public GMapOverlay DrawGridSquare(AFS2GridSquare gridSquare, GridSquareDisplayType gridSquareDisplayType)
        {
            GMapPolygon polygon = new GMapPolygon(gridSquare.Coordinates, gridSquare.Name);

            switch (gridSquareDisplayType)
            {
            case GridSquareDisplayType.Selected:
                polygon.Fill   = new SolidBrush(Color.FromArgb(40, Color.Blue));
                polygon.Stroke = new Pen(Color.Blue, 1);
                break;

            case GridSquareDisplayType.Active:
                polygon.Fill   = new SolidBrush(Color.FromArgb(40, Color.Blue));
                polygon.Stroke = new Pen(Color.DeepSkyBlue, 2);
                break;

            case GridSquareDisplayType.Downloaded:
                polygon.Fill   = new SolidBrush(Color.FromArgb(40, Color.Orange));
                polygon.Stroke = new Pen(Color.Orange, 1);
                break;

            default:
                break;
            }


            GMapOverlay polygonOverlay = new GMapOverlay(gridSquare.Name);

            polygonOverlay.Polygons.Add(polygon);
            this.GMapControl.Overlays.Add(polygonOverlay);

            this.GMapControl.Refresh();
            polygonOverlay.IsVisibile = false;
            polygonOverlay.IsVisibile = true;

            return(polygonOverlay);
        }
Exemplo n.º 7
0
        public List <ImageTile> ImageTilesForGridSquares(AFS2GridSquare afs2GridSquare, int zoomLevel)
        {
            List <ImageTile> imageTiles = new List <ImageTile>();

            // Just to make the code more readable
            var northWestCorner = afs2GridSquare.Coordinates[0];
            var northEastCorner = afs2GridSquare.Coordinates[1];
            var southEastCorner = afs2GridSquare.Coordinates[2];
            var southWestCorner = afs2GridSquare.Coordinates[3];

            // Get the pixel X & Y of the first tile
            int pixelX = 0;
            int pixelY = 0;

            BingHelper.LatLongToPixelXY(northWestCorner.Lat, northWestCorner.Lng, zoomLevel, out pixelX, out pixelY);

            // Get the tile X & Y of the frst tile
            int tileX = 0;
            int tileY = 0;

            BingHelper.PixelXYToTileXY(pixelX, pixelY, out tileX, out tileY);

            double currentTileNorthLatitude = 0;
            double currentTileSouthLatitude = 0;
            double currentTileWestLongitude = 0;
            double currentTileEastLongitude = 0;


            int currentTileX = tileX;
            int currentTileY = tileY;

            int currentRow    = 1;
            int currentColumn = 1;

            // Work through the tiles East to West, then top North to South
            do
            {
                do
                {
                    int currentPixelX;
                    int currentPixelY;
                    BingHelper.TileXYToPixelXY(currentTileX, currentTileY, out currentPixelX, out currentPixelY);

                    BingHelper.PixelXYToLatLong(currentPixelX, currentPixelY, zoomLevel, out currentTileNorthLatitude, out currentTileWestLongitude);

                    // Get the lat long of the tile "to the left and down", which will give us the south and east edge of the previous tile
                    int currentTileXPlusOnePixelX;
                    int currentTileYPlusOnePixelY;
                    BingHelper.TileXYToPixelXY(currentTileX + 1, currentTileY + 1, out currentTileXPlusOnePixelX, out currentTileYPlusOnePixelY);
                    BingHelper.PixelXYToLatLong(currentTileXPlusOnePixelX, currentTileYPlusOnePixelY, zoomLevel, out currentTileSouthLatitude, out currentTileEastLongitude);

                    var quadKey1 = BingHelper.TileXYToQuadKey(currentTileX, currentTileY, zoomLevel);

                    ImageTile tile = new ImageTile();
                    tile.Width          = 256;
                    tile.Height         = 256;
                    tile.NorthLatitude  = currentTileNorthLatitude;
                    tile.SouthLatitude  = currentTileSouthLatitude;
                    tile.WestLongitude  = currentTileWestLongitude;
                    tile.EastLongitude  = currentTileEastLongitude;
                    tile.ImageExtension = "jpg";
                    tile.TileX          = currentTileX;
                    tile.TileY          = currentTileY;
                    tile.LocalTileX     = currentColumn;
                    tile.LocalTileY     = currentRow;
                    tile.Source         = "b";
                    tile.ZoomLevel      = zoomLevel;
                    tile.URL            = String.Format(this.urlTemplate, quadKey1);

                    imageTiles.Add(tile);

                    currentTileX++;
                    currentColumn++;
                }while (currentTileWestLongitude < southEastCorner.Lng);

                // Go back to the original tileX
                currentTileX = tileX;
                // Start at column 1 again
                currentColumn = 1;

                // Do the next row
                currentTileY++;
                currentRow++;
            }while (currentTileNorthLatitude > southEastCorner.Lat);

            return(imageTiles);
        }
 public List <ImageTile> ImageTilesForGridSquares(AFS2GridSquare afs2GridSquare, int zoomLevel)
 {
     throw new NotImplementedException();
 }