Ejemplo n.º 1
0
        private void Formsetup_Load(object sender, EventArgs e)
        {
            // ==========================================================
            // Reading XML Extension Config
            // ==========================================================
            _extConf = new ExtensionConfiguration();
            _extConf.ReadConfig();

            // ==========================================================
            // Find Pathes for Game Folders etc.
            // ==========================================================
            _pathFinder = new PathFinder();
            _pathFinder.GatherPathes();

            //Check if we know our dirs
            tb_sc1dir.Text = _pathFinder.GetPath("%SC1_INSTALL_PATH%");

            tb_sc2dir.Text = _pathFinder.GetPath("%SC2_INSTALL_PATH%");

            tb_wc3dir.Text = _pathFinder.GetPath("%WC3_INSTALL_PATH%");
        }
Ejemplo n.º 2
0
        private void LoaderForm_Load(object sender, EventArgs e)
        {
            // ==========================================================
            // Reading XML Extension Config
            // ==========================================================
            _extConf = new ExtensionConfiguration();
            _extConf.ReadConfig();

            // ==========================================================
            // Find Pathes for Game Folders etc.
            // ==========================================================
            _pathFinder = new PathFinder();
            _pathFinder.GatherPathes();

            // ==========================================================
            // Start Download
            // ==========================================================
            WebRequest wrGeturl = WebRequest.Create(_fileLink);

            var resp = (HttpWebResponse)wrGeturl.GetResponse();
            int statusCode = (int)resp.StatusCode;

            // ==========================================================
            // Check Status Code
            // ==========================================================
            if (statusCode == 200)
            {
                // Construct URI
                _fileUri = resp.ResponseUri;
                // ==========================================================
                // Check Extension
                // ==========================================================
                // TODO: Deal with encoded characters in the URL (such as %20)
                // resp.Headers('Content-Disposition')
                string fileName = _fileUri.Segments[_fileUri.Segments.Length - 1].Replace('+', ' ');
                string extension = Path.GetExtension(fileName);

                if (string.IsNullOrEmpty(extension))
                {
                    MessageBox.Show("The link you followed cannot be handled by Nibbler.", "Nibbler Error", MessageBoxButtons.OK);
                    Application.Exit();
                }

                extension = extension.ToLower().Substring(1);

                if (_extConf.IsValidExtension(extension))
                {
                    lblFilename.Text = fileName; // Display filename

                    //ask user if they want to download file
                    if (MessageBox.Show(string.Format("Do you want to download {0}?",fileName), "Confirm download", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        // a 'DialogResult.Yes' value was returned from the MessageBox
                        bgWorker.RunWorkerAsync();
                    }
                    else
                    {
                        Application.Exit();
                    }

                }

                else
                {
                    // No action for this Extension defined
                    // Either link is broken or someone tampered with the XML

                    // Quit application, maybe should do something better, like pop-up a message, but
                    // that would be annoying too.. so lets just exit here...
                    // or not. waiting for program to do nothing then quit is stupid
                    // show user a popup!
                    MessageBox.Show("Nibbler does not handle files of type " + extension.ToUpper() + ".", "Nibbler Error", MessageBoxButtons.OK);
                    Application.Exit();
                }
            }
        }