Ejemplo n.º 1
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                AppendProgress(Color.Black, "Download canceled.");
            }
            else
            {
                AppendProgress(Color.Black, "Download completed.");
                Tease tease = e.Result as Tease;
                if (tease != null)
                {
                    string teaseXml = new TeaseSerializer().ConvertToXmlString(tease);
                    File.WriteAllText(teaseFile.FullName, teaseXml);

                    if (tease.Pages.Exists(page => !String.IsNullOrEmpty(page.Errors)))
                    {
                        AppendProgress(Color.Crimson, "There are some errors. Try to correct the errors in the script using a text editor.");
                    }
                    else
                    {
                        AppendProgress(Color.Black, "Select the tease from the list and press start.");
                        OnDownloadCompleted(new DownloadCompletedEventArgs { Success = true, TeaseName = Path.GetFileNameWithoutExtension(teaseFile.Name) });
                    }
                }
            }

            cancelButton.Enabled = false;
            loadButton.Enabled = true;
        }
Ejemplo n.º 2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (SelectedTease == null)
            {
                return;
            }

            SaveNewScriptDialog.InitialDirectory = teaseLibrary.TeasesFolder;
            SaveNewScriptDialog.FileName = SelectedTease.Title;
            if (DialogResult.OK == SaveNewScriptDialog.ShowDialog())
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    var saveFile = new FileInfo(SaveNewScriptDialog.FileName);

                    SelectedTease.MediaDirectory = saveFile.Name.BeforeLast(saveFile.Extension);

                    string downloadDirectory = Path.Combine(saveFile.DirectoryName, SelectedTease.MediaDirectory);

                    using (var webClient = new WebClient())
                    {
                        foreach (var page in SelectedTease.Pages)
                        {
                            if (page.Image != null)
                            {
                                string url = String.Format("http://www.milovana.com/media/get.php?folder={0}/{1}&name={2}", SelectedTease.Author.Id, SelectedTease.Id, page.Image.Id);
                                if (DownloadImagesCheckBox.Checked)
                                {
                                    if (page.Image.Id.Contains("*"))
                                    {
                                        page.Errors = String.Format("Warning: random images are not fully supported, the conversion picked a random one and gave it a name. {0}", page.Errors);
                                        page.Image.Id = page.Image.Id.Replace("*", Guid.NewGuid().ToString());

                                    }

                                    string fileName = Path.Combine(downloadDirectory, page.Image.Id);
                                    if (!File.Exists(fileName))
                                    {
                                        if (!Directory.Exists(downloadDirectory))
                                        {
                                            Directory.CreateDirectory(downloadDirectory);
                                        }
                                        webClient.DownloadFile(url, fileName);
                                    }
                                }
                                else
                                {
                                    page.Image.Id = url;
                                }
                            }
                            if (page.Audio != null)
                            {
                                string url = String.Format("http://www.milovana.com/media/get.php?folder={0}/{1}&name={2}", SelectedTease.Author.Id, SelectedTease.Id, page.Audio.Id);
                                if (DownloadImagesCheckBox.Checked)
                                {
                                    if (page.Audio.Id.Contains("*"))
                                    {
                                        page.Errors = String.Format("Warning: random audio is not fully supported, the conversion picked a random one and gave it a name. {0}", page.Errors);
                                        page.Audio.Id = page.Audio.Id.Replace("*", Guid.NewGuid().ToString());
                                    }
                                    string fileName = Path.Combine(downloadDirectory, page.Audio.Id);
                                    if (!File.Exists(fileName))
                                    {
                                        if (!Directory.Exists(downloadDirectory))
                                        {
                                            Directory.CreateDirectory(downloadDirectory);
                                        }
                                        webClient.DownloadFile(url, fileName);
                                    }
                                }
                                else
                                {
                                    page.Audio.Id = url;
                                }
                            }
                        }
                    }

                    if (SelectedTease.Pages.Exists(page => !String.IsNullOrEmpty(page.Errors)))
                    {
                        MessageBox.Show("Download completed.\n\nTry to correct the errors in the script using a text editor.");
                    }
                    else
                    {
                        MessageBox.Show("Download completed. \n\nSelect the tease from the list and press start.");
                    }

                    string teaseXml = new TeaseSerializer().ConvertToXmlString(SelectedTease);
                    File.WriteAllText(saveFile.FullName, teaseXml);

                    FillTeaseListView();
                    var listviewItem = TeaseListView.FindItemWithText(saveFile.Name.BeforeLast(saveFile.Extension));
                    if (listviewItem != null)
                    {
                        listviewItem.Selected = true;
                        TeaseListView.Focus();
                    }

                    Cursor = Cursors.Default;
                }
                catch (Exception err)
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show(err.Message, "Error while saving tease.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                // Check the errors again as the downloaded media may contain errors.
                ConverionErrorTextBox.Visible = SelectedTease.Pages.Exists(page => !String.IsNullOrEmpty(page.Errors));
            }
        }