private void GenerateMetadataButton_Click(object sender, RoutedEventArgs e) { nfoFileType nfotype = nfoFileType.Unknown; string _tmpPath = Helpers.GetUniqueFilename(".jpg"); try { MovieSheetsGenerator _gen = new MovieSheetsGenerator(SheetType.Main, fsMovieFile.Filepath); _gen.SelectedTemplate = this.TemplateSelector.TemplatesCombobox.SelectedItem as TemplateItem; if (_gen.CreateMoviesheetFromCustomData(this.fsBackdrop.Filepath, this.fsCover.Filepath, this.fsFanart1.Filepath, this.fsFanart2.Filepath, this.fsFanart3.Filepath, this.fsNfo.Filepath, this.fsMovieFile.Filepath, _tmpPath, false)) { SaveFileDialog _sfd = new SaveFileDialog(); _sfd.Title = "Select target metadata file name"; _sfd.Filter = this.FindResource("metadataFilter") as string; _sfd.DefaultExt = ".tgmd"; if ((bool)_sfd.ShowDialog()) { MoviesheetsUpdateManager _man = MoviesheetsUpdateManager.CreateManagerFromMetadata(_sfd.FileName, fsMovieFile.Filepath); MoviesheetsUpdateManagerParams _params = new MoviesheetsUpdateManagerParams(fsBackdrop.Filepath, fsFanart1.Filepath, fsFanart2.Filepath, fsFanart3.Filepath, nfoHelper.LoadNfoFile(fsMovieFile.Filepath, fsNfo.Filepath, out nfotype), fsCover.Filepath, _gen.MovieSheetPreviewTempPath); _man.GenerateUpdateFile(_params, _gen.SelectedTemplate.TemplateName); _man = null; } } else { MessageBox.Show(_gen.LastError); } } finally { try { File.Delete(_tmpPath); } catch { } } }
public void GenerateUpdateFile(MoviesheetsUpdateManagerParams parameters, string templateName) { /* update file * contains: * - info * - background * - .nfo file * - fanart1 * - fanart2 * - fanart3 * - cover */ string _backup = null; try { if (!string.IsNullOrEmpty(TargetFilename) && File.Exists(TargetFilename)) { // backup current .tgmd file by renaming it to .tgmdbackup _backup = Path.ChangeExtension(TargetFilename, ".tgmdbackup"); File.Move(TargetFilename, _backup); } // make new one MoviesheetInfo _info = new MoviesheetInfo(); _info.FileVersion = "1"; _info.TemplateName = templateName; _info.MovieName = string.IsNullOrEmpty(m_movieFilename) ? string.Empty : HttpUtility.HtmlEncode(Path.GetFileName(m_movieFilename)); try { _info.MovieHash = Subtitles.SubtitlesManager.GetMovieHash(m_movieFilename); } catch { } try { AddPart(BACKGROUND_STREAM_NAME, parameters.BackgroundPath); _info.BackgroundExtension = Path.GetExtension(parameters.BackgroundPath); AddPart(COVER_STREAM_NAME, parameters.CoverPath); _info.CoverExtension = Path.GetExtension(parameters.CoverPath); AddPart(FANART1_STREAM_NAME, parameters.Fanart1Path); _info.Fanart1Extension = Path.GetExtension(parameters.Fanart1Path); AddPart(FANART2_STREAM_NAME, parameters.Fanart2Path); _info.Fanart2Extension = Path.GetExtension(parameters.Fanart2Path); AddPart(FANART3_STREAM_NAME, parameters.Fanart3Path); _info.Fanart3Extension = Path.GetExtension(parameters.Fanart3Path); AddPart(PREVIEW_STREAM_NAME, parameters.PreviewPath); _info.PreviewExtension = Path.GetExtension(parameters.PreviewPath); using (MemoryStream _ms = new MemoryStream()) { parameters.nfo.Save(_ms, this.m_movieFilename, true); AddPart(NFO_STREAM_NAME, _ms); } } finally { using (MemoryStream _ms = new MemoryStream()) { _info.SaveInfo(_ms); AddPart(INFO_STREAM_NAME, _ms); } } } finally { if (_backup != null) { // remove the old file Helpers.RemoveFile(_backup); } } }