Пример #1
0
        /// <summary>
        /// Handles the Click event of the tsbChooseImage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void tsbChooseImage_Click(object sender, EventArgs e)
        {
            try
            {
                //Make sure a size has been filled out
                try
                {
                    Convert.ToInt32(txtWidth.Text);
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Please enter in the desired width.");
                    txtWidth.SelectAll();
                    txtWidth.Focus();
                    return;
                }

                try
                {
                    Convert.ToInt32(txtHeight.Text);
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Please enter in the desired height.");
                    txtHeight.SelectAll();
                    txtHeight.Focus();
                    return;
                }

                resizeImage();
            }

            catch (Exception ex)
            {
                logError Err = new logError();
                Err.ErrorLog(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads the latest app version.
        /// </summary>
        private void loadLatestAppVer()
        {
            try
            {
                XmlTextReader reader = new XmlTextReader(xmlUrl);
                reader.MoveToContent();

                string elementName = "";

                if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "imageresize"))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            elementName = reader.Name;
                        }

                        else
                        {
                            if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                            {
                                switch (elementName)
                                {
                                    case "version":
                                        newVersion = new Version(reader.Value);
                                        break;
                                    case "url":
                                        appUrl = reader.Value;
                                        break;
                                }
                            }
                        }
                    }
                }

                reader.Close();
            }

            catch (Exception ex)
            {
                logError Err = new logError();
                Err.ErrorLog(ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Resizes the folder.
        /// </summary>
        private void resizeFolder()
        {
            try
            {
                //Get the folder of where the images are stored
                this.Invoke(new SelectFolderCallback(this.openFolderDialog), new object[] { "Choose a folder to resize." });
                string strDirectory = folderPath;

                if (Directory.Exists(strDirectory) != true)
                {
                    return;
                }

                //Get the folder on where to save the new images to
                this.Invoke(new SelectFolderCallback(this.openFolderDialog), new object[] { "Choose a folder to save the new images to.\nWarning: Do not select the source folder." });
                string strSaveDirectory = folderPath;

                //Make sure they are not the same folder
                if (strSaveDirectory == strDirectory)
                {
                    MessageBox.Show("You cannot save the new images to the orginal image folder.");
                    return;
                }

                //Get the directory info
                DirectoryInfo dirInfo = new DirectoryInfo(strDirectory);

                FileInfo[] fileInfo;
                fileInfo = dirInfo.GetFiles();
                int totalImages = 0;
                int fileSaveCount = 0;

                //We have to get the total number of valid images we are resizing
                foreach (FileInfo file in fileInfo)
                {
                    if (ImageUtilities.IsImageFile(file.Name.ToLower()))
                    {
                        totalImages++;
                    }
                }

                if (totalImages > 0)
                {
                    this.Invoke(new MethodInvoker(delegate { panelResize.Visible = true; }));
                }

                //Now lets resize the images and save them
                foreach (FileInfo file in fileInfo)
                {
                    //Make sure the file is an image
                    if (ImageUtilities.IsImageFile(file.Name.ToLower()))
                    {
                        //Create the resized version
                        Bitmap bm = ImageUtilities.createBitmap(strDirectory + @"\" + file.Name);

                        //Save the file
                        switch (ImageUtilities.fileType(file.Name.ToLower()))
                        {
                            case "jpg":
                                bm.Save(strSaveDirectory + @"\" + file.Name, System.Drawing.Imaging.ImageFormat.Jpeg);
                                break;
                            case "gif":
                                bm.Save(strSaveDirectory + @"\" + file.Name, System.Drawing.Imaging.ImageFormat.Gif);
                                break;
                            case "bmp":
                                bm.Save(strSaveDirectory + @"\" + file.Name, System.Drawing.Imaging.ImageFormat.Bmp);
                                break;
                        }

                        bm.Dispose();
                        fileSaveCount++;
                        this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { fileSaveCount, totalImages });
                    }
                }

                if (totalImages > 0)
                {
                    this.Invoke(new MethodInvoker(delegate { panelResize.Visible = false; }));
                }

                MessageBox.Show("Total of " + fileSaveCount.ToString() + " images resized and saved.");
            }

            catch (Exception ex)
            {
                logError Err = new logError();
                Err.ErrorLog(ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// Checks for a latest version and will download + install if update is available.
        /// </summary>
        private void Download()
        {
            using (WebClient wcDownload = new WebClient())
            {
                try
                {
                    updateCheck update = new updateCheck();
                    bool updateAvailable = update.checkForUpdates();
                    string updateUrl = "";

                    if (updateAvailable)
                    {
                        string title = "New application version detected";
                        string question = "Download the new version?\nWarning: The program will close after the download is complete.";

                        if (DialogResult.Yes ==
                            MessageBox.Show(question, title,
                                            MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question))
                        {
                            updateUrl = update.appUrl;
                        }
                    }

                    else
                    {
                        MessageBox.Show("No Updates available");
                    }

                    if (updateUrl == "")
                    {
                        this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                        return;
                    }

                    webRequest = (HttpWebRequest)WebRequest.Create(updateUrl);
                    webRequest.Credentials = CredentialCache.DefaultCredentials;
                    webResponse = (HttpWebResponse)webRequest.GetResponse();

                    //Find out the filesize and store it
                    Int64 fileSize = webResponse.ContentLength;

                    //Open the url for downloading
                    strResponse = wcDownload.OpenRead(updateUrl);

                    //Create a new file stream
                    this.Invoke(new SaveDialogCallback(this.saveDialog), new object[] { "Please choose a location to save the update", Path.GetFileName(updateUrl) });

                    if (filename == null)
                    {
                        MessageBox.Show("You must choose a location to save the update");
                        this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                        return;
                    }

                    strLocal = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);

                    //Store the current number of bytes recieved from the server
                    int byteSize = 0;

                    //A bugger for storing and writing the data retrived from the server
                    byte[] downBuffer = new byte[2048];

                    while ((byteSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
                    {
                        strLocal.Write(downBuffer, 0, byteSize);
                        this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize });
                    }

                    strResponse.Close();
                    strLocal.Close();

                    Process.Start(filename);
                    Application.Exit();
                }

                catch (Exception ex)
                {
                    logError Err = new logError();
                    Err.ErrorLog(ex.Message);
                }
            }
        }