Esempio n. 1
0
        public static void init(string cgibinptrUrl)
        {
            m_mapsPath = Project.GetMapsTempPath();

            LibSys.StatusBar.WriteLine("Actual location for mapping cache in " + m_mapsPath);

            try
            {
#if DEBUG
                LibSys.StatusBar.Trace("IP: reaching cgibinptr URL='" + cgibinptrUrl + "'");
#endif

                /*
                 * this code has long uncontrolled timeout, and has been replaced with the WebDownload-based code below
                 * HttpWebRequest req = (HttpWebRequest)WebRequest.Create(cgibinptrUrl);
                 * if(Project.suspendKeepAlive)
                 * {
                 *      req.KeepAlive = false;
                 * }
                 * WebResponse res = req.GetResponse();
                 * Stream responseStream = res.GetResponseStream();
                 * StreamReader reader = new StreamReader (responseStream);
                 */

                WebDownload webDL = new WebDownload(Project.webTimeoutMs);                              // default 7 seconds to time out
                // Create the state object.
                DownloadInfo info = new DownloadInfo();
                info.baseName           = "";
                info.strUrl             = cgibinptrUrl;
                info.addMonitoredMethod = null;

                byte[] downloadedData = null;
                int    tries          = 1;
                int    maxTries       = 1;
                while (tries <= maxTries && downloadedData == null && !info.is404)
                {
                    downloadedData = webDL.Download(info, ProgressCallback);                                    // will timeout
#if DEBUG
                    if (downloadedData != null)
                    {
                        LibSys.StatusBar.Trace("IP: try " + tries + " TileCache:Download() - " + cgibinptrUrl + " delivered " + downloadedData.Length + " bytes");
                    }
                    else
                    {
                        LibSys.StatusBar.Trace("IP: try " + tries + " TileCache:Download() - " + cgibinptrUrl + " delivered null bytes");
                    }
#endif
                    tries++;
                }

                if (downloadedData == null || downloadedData.Length == 0)
                {
                    LibSys.StatusBar.Error("failed to reach QuakeMap.com");
                    return;                             // Project.serverAvailable will be set to false, and no web attempts will take place.
                }
                LibSys.StatusBar.Trace("OK: reached QuakeMap.com");

                string       responseString = Project.ByteArrayToStr(downloadedData);
                StringReader reader         = new StringReader(responseString);

                string upgrVersion   = "";
                bool   ignoreUpgrade = false;
                int    state         = 0;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    try
                    {
                        switch (state)
                        {
                        case 0:
                            if (line.StartsWith("MAPSERVER="))
                            {
                                MappingServer ms = new MappingServer(line.Substring("MAPSERVER=".Length));
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - ms='" + ms + "'");
#endif
                                m_mappingServers.Add(ms);
                            }
                            else if (line.StartsWith("ZIPSERVER="))
                            {
                                ZipcodeServer zs = new ZipcodeServer(line.Substring("ZIPSERVER=".Length));
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - zs='" + zs + "'");
#endif
                                m_zipcodeServer = zs;
                            }
                            else if (line.StartsWith("TILERABOUT="))
                            {
                                Project.ABOUT_URL = line.Substring("TILERABOUT=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - about='" + Project.ABOUT_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERORDER="))
                            {
                                Project.ORDER_URL = line.Substring("TILERORDER=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - order='" + Project.ORDER_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERDLOAD="))
                            {
                                Project.DLOAD_URL = line.Substring("TILERDLOAD=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - download='" + Project.DLOAD_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERUPDATE="))
                            {
                                Project.UPDATE_URL = line.Substring("TILERUPDATE=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - update='" + Project.UPDATE_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERPRIVACY="))
                            {
                                Project.PRIVACY_URL = line.Substring("TILERPRIVACY=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - privacy='" + Project.PRIVACY_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERPDA="))
                            {
                                Project.PDA_URL = line.Substring("TILERPDA=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - pda='" + Project.PDA_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERHELP="))
                            {
                                Project.HELP_FILE_URL = line.Substring("TILERHELP=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - help='" + Project.HELP_FILE_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERHDATE="))
                            {
                                string sDate = line.Substring("TILERHDATE=".Length);
                                Project.HELP_FILE_DATE = Convert.ToDateTime(sDate);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - helpFileDate='" + Project.HELP_FILE_DATE + "'");
#endif
                            }
                            else if (line.StartsWith("TILERMISC="))
                            {
                                Project.MISC_FOLDER_URL = line.Substring("TILERMISC=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - misc='" + Project.MISC_FOLDER_URL + "'");
#endif
                            }
                            else if (line.StartsWith("TILERSAMPLES="))
                            {
                                Project.SAMPLES_FOLDER_URL = line.Substring("TILERSAMPLES=".Length);
#if DEBUG
                                LibSys.StatusBar.Trace("OK: TileCache() - samples='" + Project.SAMPLES_FOLDER_URL + "'");
#endif
                            }
                            else if (line.StartsWith("MESSAGE="))
                            {
                                state = 1;
                                Project.serverMessage = "";
                            }
                            else if (line.StartsWith("UPGR"))
                            {
                                upgrVersion = line.Substring(4);
                                if (Project.PROGRAM_VERSION_RELEASEDATE.Equals(upgrVersion))
                                {
                                    ignoreUpgrade = true;
                                }
                                else
                                {
                                    Project.upgradeMessage = "\n";
                                }
                                state = 2;
                            }
                            break;

                        case 1:
                            if (line.StartsWith("ENDMESSAGE"))
                            {
                                state = 0;
                            }
                            else
                            {
                                Project.serverMessage += (line + "\n");
                            }
                            break;

                        case 2:
                            if (line.StartsWith("ENDUPGR"))
                            {
                                state = 0;
                            }
                            else
                            {
                                if (!ignoreUpgrade)
                                {
                                    Project.upgradeMessage += (line + "\n");
                                }
                            }
                            break;
                        }
                    }
                    catch {}
                }

                if (!Project.serverMessageLast.Equals(Project.serverMessage) && Project.upgradeMessage.Length == 0)
                {
                    string message = Project.serverMessage;                     // + Project.upgradeMessage;   upgrade message shows up in MainForm
                    LibSys.StatusBar.Trace(message);
                    if (greetingForm == null)
                    {
                        Project.MessageBox(null, message);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show(greetingForm, message, Project.PROGRAM_NAME_HUMAN,
                                                             System.Windows.Forms.MessageBoxButtons.OK,
                                                             MessageBoxIcon.Exclamation);
                    }
                    Project.serverMessageLast = Project.serverMessage;
                }
            }
            catch (Exception e)
            {
                LibSys.StatusBar.Error("exception: " + e.Message);
            }
        }
Esempio n. 2
0
        public static void init(string cgibinptrUrl)
        {
            m_mapsPath = Project.GetMapsTempPath();

            LibSys.StatusBar.WriteLine("Actual location for mapping cache in " + m_mapsPath);

            try
            {
            #if DEBUG
                LibSys.StatusBar.Trace("IP: reaching cgibinptr URL='" + cgibinptrUrl + "'");
            #endif
                /*
                 * this code has long uncontrolled timeout, and has been replaced with the WebDownload-based code below
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(cgibinptrUrl);
                if(Project.suspendKeepAlive)
                {
                    req.KeepAlive = false;
                }
                WebResponse res = req.GetResponse();
                Stream responseStream = res.GetResponseStream();
                StreamReader reader = new StreamReader (responseStream);
                */

                WebDownload webDL = new WebDownload(Project.webTimeoutMs);		// default 7 seconds to time out
                // Create the state object.
                DownloadInfo info = new DownloadInfo();
                info.baseName = "";
                info.strUrl = cgibinptrUrl;
                info.addMonitoredMethod = null;

                byte[] downloadedData = null;
                int tries = 1;
                int maxTries = 1;
                while (tries <= maxTries && downloadedData == null && !info.is404)
                {
                    downloadedData = webDL.Download(info, ProgressCallback);		// will timeout
            #if DEBUG
                    if(downloadedData != null)
                    {
                        LibSys.StatusBar.Trace("IP: try " + tries + " TileCache:Download() - " + cgibinptrUrl + " delivered " + downloadedData.Length + " bytes" );
                    }
                    else
                    {
                        LibSys.StatusBar.Trace("IP: try " + tries + " TileCache:Download() - " + cgibinptrUrl + " delivered null bytes" );
                    }
            #endif
                    tries++;
                }

                if(downloadedData == null || downloadedData.Length == 0)
                {
                    LibSys.StatusBar.Error("failed to reach QuakeMap.com");
                    return;		// Project.serverAvailable will be set to false, and no web attempts will take place.
                }
                LibSys.StatusBar.Trace("OK: reached QuakeMap.com");

                string responseString = Project.ByteArrayToStr(downloadedData);
                StringReader reader = new StringReader (responseString);

                string upgrVersion = "";
                bool ignoreUpgrade = false;
                int state = 0;
                string line;
                while((line=reader.ReadLine()) != null)
                {
                    try
                    {
                        switch(state)
                        {
                            case 0:
                                if(line.StartsWith("MAPSERVER="))
                                {
                                    MappingServer ms = new MappingServer(line.Substring("MAPSERVER=".Length));
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - ms='" + ms + "'");
            #endif
                                    m_mappingServers.Add(ms);
                                }
                                else if(line.StartsWith("ZIPSERVER="))
                                {
                                    ZipcodeServer zs = new ZipcodeServer(line.Substring("ZIPSERVER=".Length));
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - zs='" + zs + "'");
            #endif
                                    m_zipcodeServer = zs;
                                }
                                else if(line.StartsWith("TILERABOUT="))
                                {
                                    Project.ABOUT_URL = line.Substring("TILERABOUT=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - about='" + Project.ABOUT_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERORDER="))
                                {
                                    Project.ORDER_URL = line.Substring("TILERORDER=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - order='" + Project.ORDER_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERDLOAD="))
                                {
                                    Project.DLOAD_URL = line.Substring("TILERDLOAD=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - download='" + Project.DLOAD_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERUPDATE="))
                                {
                                    Project.UPDATE_URL = line.Substring("TILERUPDATE=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - update='" + Project.UPDATE_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERPRIVACY="))
                                {
                                    Project.PRIVACY_URL = line.Substring("TILERPRIVACY=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - privacy='" + Project.PRIVACY_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERPDA="))
                                {
                                    Project.PDA_URL = line.Substring("TILERPDA=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - pda='" + Project.PDA_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERHELP="))
                                {
                                    Project.HELP_FILE_URL = line.Substring("TILERHELP=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - help='" + Project.HELP_FILE_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERHDATE="))
                                {
                                    string sDate = line.Substring("TILERHDATE=".Length);
                                    Project.HELP_FILE_DATE = Convert.ToDateTime(sDate);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - helpFileDate='" + Project.HELP_FILE_DATE + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERMISC="))
                                {
                                    Project.MISC_FOLDER_URL = line.Substring("TILERMISC=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - misc='" + Project.MISC_FOLDER_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("TILERSAMPLES="))
                                {
                                    Project.SAMPLES_FOLDER_URL = line.Substring("TILERSAMPLES=".Length);
            #if DEBUG
                                    LibSys.StatusBar.Trace("OK: TileCache() - samples='" + Project.SAMPLES_FOLDER_URL + "'");
            #endif
                                }
                                else if(line.StartsWith("MESSAGE="))
                                {
                                    state = 1;
                                    Project.serverMessage = "";
                                }
                                else if(line.StartsWith("UPGR"))
                                {
                                    upgrVersion = line.Substring(4);
                                    if(Project.PROGRAM_VERSION_RELEASEDATE.Equals(upgrVersion))
                                    {
                                        ignoreUpgrade = true;
                                    }
                                    else
                                    {
                                        Project.upgradeMessage = "\n";
                                    }
                                    state = 2;
                                }
                                break;
                            case 1:
                                if(line.StartsWith("ENDMESSAGE"))
                                {
                                    state = 0;
                                }
                                else
                                {
                                    Project.serverMessage += (line + "\n");
                                }
                                break;
                            case 2:
                                if(line.StartsWith("ENDUPGR"))
                                {
                                    state = 0;
                                }
                                else
                                {
                                    if(!ignoreUpgrade)
                                    {
                                        Project.upgradeMessage += (line + "\n");
                                    }
                                }
                                break;
                        }
                    }
                    catch {}
                }

                if(!Project.serverMessageLast.Equals(Project.serverMessage) && Project.upgradeMessage.Length == 0)
                {
                    string message = Project.serverMessage; // + Project.upgradeMessage;   upgrade message shows up in MainForm
                    LibSys.StatusBar.Trace(message);
                    if(greetingForm == null)
                    {
                        Project.MessageBox(null, message);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show (greetingForm, message, Project.PROGRAM_NAME_HUMAN,
                                                                System.Windows.Forms.MessageBoxButtons.OK,
                                                                MessageBoxIcon.Exclamation);
                    }
                    Project.serverMessageLast = Project.serverMessage;
                }
            }
            catch (Exception e)
            {
                LibSys.StatusBar.Error("exception: " + e.Message);
            }
        }