Example #1
0
        public static void resetGpsBabelExecutable()
        {
            GpsBabelExecutable = "";

            // should be installed under our current dir:
            FileInfo gbExe = new FileInfo(Path.Combine(startupPath, @"gpsbabel-1.3.5\gpsbabel.exe"));

            LibSys.StatusBar.Trace("IP: locating  path=" + gbExe.FullName);
            if (File.Exists(gbExe.FullName))
            {
                GpsBabelExecutable = gbExe.FullName;
            }
            else
            {
                // try our development-time path:
                gbExe = new FileInfo(Path.Combine(startupPath, @"..\..\..\gpsbabel-1.3.5\gpsbabel.exe"));
                LibSys.StatusBar.Trace("IP: locating  path=" + gbExe.FullName);
                if (File.Exists(gbExe.FullName))
                {
                    GpsBabelExecutable = gbExe.FullName;
                }
            }

            if (String.IsNullOrEmpty(GpsBabelExecutable))
            {
                string err = "GPSBabel Executable " + gbExe + " not found";
                LibSys.StatusBar.Error(err);
                Project.ErrorBox(null, err);
            }
            else
            {
                LibSys.StatusBar.Trace("OK: found GPSBabel executable,  path=" + gbExe.FullName);
            }
        }
Example #2
0
        private void tryStartQuakeMap()
        {
            try
            {
                if (!File.Exists(Project.QuakeMapExecutable))
                {
                    string err = "QuakeMap Executable " + Project.QuakeMapExecutable + " not found";
                    LibSys.StatusBar.Error(err);
                    Project.ErrorBox(null, err);
                    return;
                }

                string workingDirectory = (new FileInfo(Project.QuakeMapExecutable)).DirectoryName;
                string cmd  = Project.QuakeMapExecutable;
                string args = "/quick";

                LibSys.StatusBar.Trace(cmd + " " + args);
                // Create startinfo object
                ProcessStartInfo pInfo = new ProcessStartInfo(cmd, args);
                pInfo.WorkingDirectory = workingDirectory;
                pInfo.CreateNoWindow   = true;
                pInfo.UseShellExecute  = false;
                Process processObject = Process.Start(pInfo);

                LibSys.StatusBar.Trace("QuakeMap starting thread finished");
            }
            catch (Exception e)
            {
                LibSys.StatusBar.Error("exception while in tryStartQuakeMap(): " + e.Message);
            }
        }
Example #3
0
        public Bitmap FromNoncontigImage()
        {
            Bitmap bitmap = null;

            m_error = "";
            Exception exc = null;

            string libTiffDir = Project.driveSystem + "Program Files\\GnuWin32";
            string libtiffcp  = Path.Combine(libTiffDir, "bin\\tiffcp.exe");
            string cpArgs     = "-p contig";

            if (!File.Exists(libtiffcp))
            {
                Project.ErrorBox(Project.mainForm, String.Format(libTiffMustInstallMessage, libTiffWin32Url, libTiffDir));
                return(null);
            }

            CmdRunner runner   = new CmdRunner();
            string    tempFile = Path.GetTempFileName();

            Project.filesToDelete.Add(tempFile);

            string outputText = "";

            try
            {
                runner.executeCommand(libtiffcp, cpArgs + " \"" + m_fileName + "\" \"" + tempFile + "\"",
                                      Path.Combine(Project.startupPath, Bindirectory), null, out outputText);
                m_result = runner.OutputString;
                m_error  = runner.ErrorString;
            }
            catch (Exception ee)
            {
                m_error = ee.Message;
                LibSys.StatusBar.Error(ee.Message);
                exc = ee;
            }

            if (runner.exitcode == 0)
            {
                try
                {
                    LibSys.StatusBar.Trace(outputText);
                    bitmap = new Bitmap(tempFile);
                    LibSys.StatusBar.Trace("OK: contig tiff read in");
                }
                catch (Exception ee)
                {
                    m_error = ee.Message;
                    LibSys.StatusBar.Error(ee.Message);
                    exc = ee;
                }
            }

            if (exc != null)
            {
                throw exc;
            }
            return(bitmap);
        }
Example #4
0
        public void run(double lat, double lon, string name, string guid)
        {
            string args = substituteArgs(lat, lon, name, guid);

            LibSys.StatusBar.Trace("Run Tool: '" + this.executablePath + "'  args: '" + args + "'");
            if (this.executablePath == null)
            {
                Project.RunBrowser("\"" + args + "\"");
            }
            else
            {
                if (File.Exists(executablePath))
                {
                    System.Diagnostics.ProcessStartInfo pInfo = new ProcessStartInfo(executablePath, args);

                    Process p = new Process();
                    p.StartInfo = pInfo;
                    p.Start();
                }
                else
                {
                    Project.ErrorBox(null, "Could not find file " + executablePath + "\n\nInstall the Tool, or use \"Tools-->Manage\" and correct the Executable for " + this.displayName);
                }
            }
        }
Example #5
0
        public static void resetQuakeMapExecutable()
        {
            string quakeMapPath = driveProgramInstalled + "Program Files\\QuakeMap\\QuakeMap\\QuakeMap.exe";

            if (File.Exists(quakeMapPath))
            {
                // newer versions of QuakeMap are here:
                QuakeMapExecutable = quakeMapPath;
            }
            else
            {
                quakeMapPath = null;

                // hope registry key made by older QuakeMap installer is ok:
                string      keyPath = "Software\\VitalBytes\\QuakeMap";
                RegistryKey regKey  = Registry.CurrentUser.OpenSubKey(keyPath);
                if (regKey != null)
                {
                    quakeMapPath = "" + regKey.GetValue("INSTALLDIR");
                    regKey.Close();
                }

                if (quakeMapPath != null)
                {
                    FileInfo qmExe = new FileInfo(Path.Combine(quakeMapPath, "bin\\quakemap.exe"));
                    if (File.Exists(qmExe.FullName))
                    {
                        QuakeMapExecutable = qmExe.FullName;
                    }
                    else
                    {
                        string err = "QuakeMap Executable " + qmExe + " not found";
                        LibSys.StatusBar.Error(err);
                        Project.ErrorBox(null, err);
                    }
                }
            }

            if (String.IsNullOrEmpty(quakeMapPath))
            {
                string err = "QuakeMap Executable not found - registry key missing. Please install QuakeMap.";
                LibSys.StatusBar.Error(err);
                Project.ErrorBox(null, err);
            }
        }
Example #6
0
        /// <summary>
        /// parses listgeo.exe output, filling in GeoTiff's object properties.
        /// </summary>
        /// <param name="libgeoOutput"></param>
        private void parseListgeo(string libgeoOutput)
        {
            /*
             * Geotiff_Information:
             * Version: 1
             * Key_Revision: 0.1
             * Tagged_Information:
             * ModelTiepointTag (2,3):
             * 0                0                0
             * 664354.283       4601368.61       0
             * ModelPixelScaleTag (1,3):
             * 10.16            10.16            0
             * End_Of_Tags.
             * Keyed_Information:
             * GTModelTypeGeoKey (Short,1): ModelTypeProjected
             * GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
             * ProjectedCSTypeGeoKey (Short,1): PCS_WGS84_UTM_zone_17N
             * PCSCitationGeoKey (Ascii,25): "UTM Zone 17 N with WGS84"
             * End_Of_Keys.
             * End_Of_Geotiff.
             *
             * PCS = 32617 (name unknown)
             * Projection = 16017 ()
             * Projection Method: CT_TransverseMercator
             * ProjNatOriginLatGeoKey: 0.000000 (  0d 0' 0.00"N)
             * ProjNatOriginLongGeoKey: -81.000000 ( 81d 0' 0.00"W)
             * ProjScaleAtNatOriginGeoKey: 0.999600
             * ProjFalseEastingGeoKey: 500000.000000 m
             * ProjFalseNorthingGeoKey: 0.000000 m
             * GCS: 4326/WGS 84
             * Datum: 6326/World Geodetic System 1984
             * Ellipsoid: 7030/WGS 84 (6378137.00,6356752.31)
             * Prime Meridian: 8901/Greenwich (0.000000/  0d 0' 0.00"E)
             *
             * Corner Coordinates:
             * Upper Left    (  664354.283, 4601368.607)  ( -79.0294261W,  41.5471041N)
             * Lower Left    (  664354.283, 4537888.927)  ( -79.0465367W,  40.9756259N)
             * Upper Right   (  765151.643, 4601368.607)  ( -77.8223338W,  41.5200659N)
             * Lower Right   (  765151.643, 4537888.927)  ( -77.8498913W,  40.9491226N)
             * Center        (  714752.963, 4569628.767)  ( -78.4369247W,  41.2495544N)
             */

            StringReader reader = new StringReader(libgeoOutput);

            int    state       = 0;
            int    cornerCount = 0;
            string line;
            bool   hasTransformation = false;

            while ((line = reader.ReadLine()) != null)
            {
                try
                {
                    switch (state)
                    {
                    case 0:
                        if (line.StartsWith("Corner Coordinates:"))
                        {
                            state = 10;
                        }
                        else if (line.IndexOf("ModelTransformationTag") != -1)
                        {
                            hasTransformation = true;
                        }
                        break;

                    case 10:
                        if (line.StartsWith("Upper Left"))
                        {
                            parseCoordLine(line, out TopLeftLng, out TopLeftLat);
                            cornerCount++;
                        }
                        if (line.StartsWith("Lower Left"))
                        {
                            parseCoordLine(line, out BottomLeftLng, out BottomLeftLat);
                            cornerCount++;
                        }
                        if (line.StartsWith("Upper Right"))
                        {
                            parseCoordLine(line, out TopRightLng, out TopRightLat);
                            cornerCount++;
                        }
                        if (line.StartsWith("Lower Right"))
                        {
                            parseCoordLine(line, out BottomRightLng, out BottomRightLat);
                            cornerCount++;
                        }
                        break;
                    }
                }
                catch {}
            }

            if (cornerCount == 4)
            {
                // all went well with the corners parsing; now process transformation tags appearing in some weird GeoTIFFs:

                if (hasTransformation)
                {
                    Project.ErrorBox(Project.mainForm, "Sorry, GeoTIFF ModelTransformationTag not supported, image may be misplaced or missing.");
                }
            }
            else
            {
                Project.ErrorBox(Project.mainForm, "Sorry, GeoTIFF files not having corner coordinates not supported.");
            }
        }
Example #7
0
        /// <summary>
        /// Generates all web page files using templates and data accumulated in this class.
        /// </summary>
        /// <param name="destinationFolderName"></param>
        /// <param name="physicalBounds"></param>
        public void generateAllPageContentFiles(string destinationFolderName, Rectangle physicalBounds, bool appendToMaster)
        {
            StringBuilder indexPageContent = new StringBuilder();

            // fill in the last missing piece - the click map:
            string clickMapContent = Project.mainCommand.doGenerateClickMap(physicalBounds);

            m_dictionary.Add("{{ClickMap}}", clickMapContent);

            /*
             * indexPageContent.Append("---------- index page HTML -----------<br><br>\r\n");
             *
             * indexPageContent.Append("shortName: <b>" + shortName + "</b><br>\r\n");
             * indexPageContent.Append("heading: <b>" + heading + "</b><br>\r\n");
             * indexPageContent.Append("description: <b>" + description + "</b><br>\r\n");
             * indexPageContent.Append("templateFolder: <b>" + m_templateFolder + "</b><br>\r\n");
             */

            string destIndex           = FromDictionary("index.html");
            string destinationFilename = Path.Combine(destinationFolderName, destIndex);
            string templateFilename    = Path.Combine(m_templateFolder, FromDictionary("template.index.html"));

            // read in the template and fill-the-blanks there:

            FileStream fs         = new FileStream(templateFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
            TextReader textReader = new StreamReader(fs);

            int    lineCounter = 0;
            string str;

            while ((str = textReader.ReadLine()) != null)
            {
                str = str.Trim();
                lineCounter++;

again:
                int pos = str.IndexOf("{{");
                if (pos == -1)
                {
                    indexPageContent.Append(str);
                }
                else
                {
                    indexPageContent.Append(str.Substring(0, pos));
                    str = str.Substring(pos + 2);
                    int pos1 = str.IndexOf("}}");
                    if (pos1 == -1)
                    {
                        // no closing }} -- bad tag. Try recovering.
                        indexPageContent.Append("{{");
                    }
                    else
                    {
                        // ok, we are at the point where replacement token needs to be determined
                        string keyToken = "{{" + str.Substring(0, pos1) + "}}";
                        indexPageContent.Append(FromDictionary(keyToken));
                        str = str.Substring(pos1 + 2);
                    }
                    goto again;
                }
                indexPageContent.Append("\r\n");
            }

            fs.Close();

            Project.writeTextFile(destinationFilename, indexPageContent.ToString());

            // take care of stylesheet:
            string ss = FromDictionary("{{StyleSheet}}");

            if (!"{{StyleSheet}}".Equals(ss))
            {
                File.Copy(Path.Combine(m_templateFolder, ss), Path.Combine(destinationFolderName, ss), true);
            }

            if (appendToMaster)
            {
                DirectoryInfo destinationFolder = new DirectoryInfo(destinationFolderName);
                string        masterFile        = FromDictionary("../index.html");
                string        masterFileName    = Path.Combine(destinationFolder.Parent.FullName, masterFile.Replace("../", ""));

                if (!File.Exists(masterFileName))
                {
                    Project.ErrorBox(null, masterFileName + " not found, will skip inserion to " + masterFile);
                }
                else
                {
                    // find the ../index.html and append relative url of the generated page between <!--trips--> and <!--/trips-->
                    string relativeUrl = destinationFolder.Name + "/" + destIndex;
                    string toInsert    = "<li><a href=\"" + relativeUrl + "\">" + heading + "</a></li>\r\n";
                    bool   masterDirty = false;
                    indexPageContent = new StringBuilder();

                    fs         = new FileStream(masterFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    textReader = new StreamReader(fs);

                    lineCounter = 0;
                    int state = 0;
                    while ((str = textReader.ReadLine()) != null)
                    {
                        str = str.Trim();
                        lineCounter++;

                        switch (state)
                        {
                        case 0:
                            if (str.Replace(" ", "").StartsWith("<!--trips--><ul>"))
                            {
                                state = 1;
                            }
                            break;

                        case 1:
                            if (str.Replace(" ", "").StartsWith("<!--/trips--></ul>"))
                            {
                                indexPageContent.Append(toInsert);
                                masterDirty = true;
                                state       = 2;
                            }
                            else if (str.IndexOf(toInsert) >= 0)
                            {
                                Project.ErrorBox(null, masterFile + " already has " + toInsert);
                                state = 2;
                            }
                            break;

                        default:
                            break;
                        }

                        indexPageContent.Append(str);
                        indexPageContent.Append("\r\n");
                    }

                    fs.Close();

                    if (masterDirty)
                    {
                        Project.writeTextFile(masterFileName, indexPageContent.ToString());
                    }
                }
            }
        }