private void CommandBinding_RemoveFile(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            if (obj.GetType() == typeof(VM_AVDump))
            {
                VM_AVDump vid = obj as VM_AVDump;

                int dumpToRemove = -1;
                for (int i = 0; i < VM_MainListHelper.Instance.AVDumpFiles.Count; i++)
                {
                    if (VM_MainListHelper.Instance.AVDumpFiles[i].FullPath == vid.FullPath)
                    {
                        dumpToRemove = i;
                        break;
                    }
                }

                if (dumpToRemove >= 0)
                {
                    VM_MainListHelper.Instance.AVDumpFiles.RemoveAt(dumpToRemove);
                }
            }
        }
        void workerAvdump_DoWork(object sender, DoWorkEventArgs e)
        {
            List <VM_AVDump> filesToDump = e.Argument as List <VM_AVDump>;

            if (filesToDump == null)
            {
                return;
            }

            try
            {
                foreach (VM_AVDump dump in filesToDump)
                {
                    if (stopDump)
                    {
                        return;
                    }

                    // get the record from main VM
                    VM_AVDump tempDump = null;
                    foreach (VM_AVDump dm in VM_MainListHelper.Instance.AVDumpFiles)
                    {
                        if (dm.FullPath == dump.FullPath)
                        {
                            tempDump = dm;
                            break;
                        }
                    }

                    if (tempDump == null)
                    {
                        continue;
                    }

                    tempDump.IsBeingDumped = true;
                    tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Processing;

                    tempDump.AVDumpFullResult = VM_ShokoServer.Instance.ShokoServices.AVDumpFile(tempDump.VideoLocal.VideoLocalID);
                    tempDump.ED2KDump         = Utils.GetED2KDump(tempDump.AVDumpFullResult);
                    tempDump.IsBeingDumped    = false;
                    if (string.IsNullOrEmpty(tempDump.ED2KDump))
                    {
                        tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Error;
                        tempDump.HasBeenDumped = false;
                    }
                    else
                    {
                        tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Complete;
                        tempDump.HasBeenDumped = true;
                    }
                }
            }
            catch (Exception)
            {
                // ignore
            }
        }
        void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                ccDetail.Content = null;

                AnyVideosSelected      = lbVideos.SelectedItems.Count > 0;
                OneVideoSelected       = lbVideos.SelectedItems.Count == 1;
                MultipleVideosSelected = lbVideos.SelectedItems.Count > 1;

                // if only one video selected
                if (OneVideoSelected)
                {
                    VM_AVDump vid = lbVideos.SelectedItem as VM_AVDump;
                    ccDetail.Content = vid;
                }
                else if (MultipleVideosSelected)
                {
                    MultipleAvdumps mv = new MultipleAvdumps()
                    {
                        SelectedCount = lbVideos.SelectedItems.Count,
                        AVDumps       = new List <VM_AVDump>()
                    };

                    foreach (object obj in lbVideos.SelectedItems)
                    {
                        VM_AVDump vid = obj as VM_AVDump;
                        mv.AVDumps.Add(vid);
                    }

                    ccDetail.Content = mv;
                }

                var control = Utils.FindElementByName <AvdumpFileControl>(ccDetail, "FileDetails");
                control.DumpSingle   = OneVideoSelected;
                control.DumpMultiple = MultipleVideosSelected;


                //SetConfirmDetails();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Пример #4
0
        void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                ccDetail.Content = null;

                AnyVideosSelected      = lbVideos.SelectedItems.Count > 0;
                OneVideoSelected       = lbVideos.SelectedItems.Count == 1;
                MultipleVideosSelected = lbVideos.SelectedItems.Count > 1;

                // if only one video selected
                if (OneVideoSelected)
                {
                    VM_AVDump vid = lbVideos.SelectedItem as VM_AVDump;
                    ccDetail.Content = vid;
                }

                // if only one video selected
                if (MultipleVideosSelected)
                {
                    MultipleAvdumps mv = new MultipleAvdumps();
                    mv.SelectedCount = lbVideos.SelectedItems.Count;
                    mv.AVDumps       = new List <VM_AVDump>();

                    foreach (object obj in lbVideos.SelectedItems)
                    {
                        VM_AVDump vid = obj as VM_AVDump;
                        mv.AVDumps.Add(vid);
                    }

                    ccDetailMultiple.Content = mv;
                }


                //SetConfirmDetails();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        private void CommandBinding_OpenFolder(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            if (obj.GetType() == typeof(VM_AVDump))
            {
                VM_AVDump vid = obj as VM_AVDump;

                if (File.Exists(vid.FullPath))
                {
                    Utils.OpenFolderAndSelectFile(vid.FullPath);
                }
                else
                {
                    MessageBox.Show(Shoko.Commons.Properties.Resources.MSG_ERR_FileNotFound, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        void AvdumpFileControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                DumpSingle   = false;
                DumpMultiple = false;

                if (DataContext == null)
                {
                    return;
                }

                if (DataContext.GetType() == typeof(VM_AVDump))
                {
                    VM_AVDump dump = DataContext as VM_AVDump;
                    if (dump != null)
                    {
                        AllAnime.Clear();
                        foreach (VM_AniDB_Anime anime in VM_AniDB_Anime.BestLevenshteinDistanceMatches(dump.VideoLocal.ClosestAnimeMatchString, 10))
                        {
                            AllAnime.Add(anime);
                        }
                        if (AllAnime.Count > 0)
                        {
                            lbAnime.SelectedIndex = 0;
                        }

                        if (string.IsNullOrEmpty(dump.AVDumpFullResult))
                        {
                            string ed2kDump = "Pre-calculated ED2K Dump string" + Environment.NewLine;
                            ed2kDump += "---------------------------" + Environment.NewLine;
                            ed2kDump += "This does not mean the data has been uploaded to AniDB yet" + Environment.NewLine;
                            ed2kDump += "---------------------------" + Environment.NewLine;
                            ed2kDump += $@"ed2k://|file|{dump.FileName}|{dump.FileSize}|{dump.VideoLocal.Hash}|/" + Environment.NewLine;

                            dump.AVDumpFullResult = ed2kDump;
                        }

                        dump.ED2KDump = Utils.GetED2KDump(dump.AVDumpFullResult);
                        SetED2KDump(dump.ED2KDump);
                    }
                    DumpSingle = true;
                }

                if (DataContext.GetType() == typeof(MultipleAvdumps))
                {
                    MultipleAvdumps dumpList = DataContext as MultipleAvdumps;
                    AllAnime.Clear();

                    foreach (VM_AniDB_Anime anime in VM_AniDB_Anime.BestLevenshteinDistanceMatches(dumpList.AVDumps[0].VideoLocal.ClosestAnimeMatchString, 10))
                    {
                        AllAnime.Add(anime);
                    }

                    if (AllAnime.Count > 0)
                    {
                        lbAnime.SelectedIndex = 0;
                    }

                    string massAvDump = "";
                    if (dumpList != null)
                    {
                        foreach (VM_AVDump dump in dumpList.AVDumps)
                        {
                            if (string.IsNullOrEmpty(dump.AVDumpFullResult))
                            {
                                string ed2kDump = "Pre-calculated ED2K Dump string" + Environment.NewLine;
                                ed2kDump += "---------------------------" + Environment.NewLine;
                                ed2kDump += "This does not mean the data has been uploaded to AniDB yet" + Environment.NewLine;
                                ed2kDump += "---------------------------" + Environment.NewLine;
                                ed2kDump += $@"ed2k://|file|{dump.FileName}|{dump.FileSize}|{dump.VideoLocal.Hash}|/" + Environment.NewLine;

                                dump.AVDumpFullResult = ed2kDump;
                            }
                            dump.ED2KDump = Utils.GetED2KDump(dump.AVDumpFullResult);
                            massAvDump   += dump.ED2KDump + Environment.NewLine;
                        }
                    }
                    SetED2KDump(massAvDump);
                    DumpMultiple = true;
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        void workerAvdump_DoWork(object sender, DoWorkEventArgs e)
        {
            List <VM_AVDump> filesToDump = e.Argument as List <VM_AVDump>;

            if (filesToDump == null)
            {
                return;
            }

            try
            {
                foreach (VM_AVDump dump in filesToDump)
                {
                    if (stopDump)
                    {
                        return;
                    }

                    // get the record from main VM
                    VM_AVDump tempDump = null;
                    foreach (VM_AVDump dm in VM_MainListHelper.Instance.AVDumpFiles)
                    {
                        if (dm.FullPath == dump.FullPath)
                        {
                            tempDump = dm;
                            break;
                        }
                    }

                    if (tempDump == null)
                    {
                        continue;
                    }

                    tempDump.IsBeingDumped = true;
                    tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Processing;

                    //Create process
                    System.Diagnostics.Process pProcess = new System.Diagnostics.Process();

                    //strCommand is path and file name of command to run
                    string appPath  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string filePath = Path.Combine(appPath, "AVDump2CL.exe");

                    if (!File.Exists(filePath))
                    {
                        tempDump.AVDumpFullResult = Shoko.Commons.Properties.Resources.AVDump_Missing + " " + filePath;
                        tempDump.ED2KDump         = Utils.GetED2KDump(tempDump.AVDumpFullResult);
                        tempDump.IsBeingDumped    = false;
                        tempDump.DumpStatus       = Shoko.Commons.Properties.Resources.AVDump_Error;
                        tempDump.HasBeenDumped    = false;

                        continue;
                    }

                    if (string.IsNullOrEmpty(Commons.Extensions.Models.GetLocalFileSystemFullPath(dump.VideoLocal)) || (!File.Exists(Commons.Extensions.Models.GetLocalFileSystemFullPath(dump.VideoLocal))))
                    {
                        tempDump.AVDumpFullResult = Shoko.Commons.Properties.Resources.AVDump_VideoMissing + " " + Commons.Extensions.Models.GetLocalFileSystemFullPath(dump.VideoLocal) ?? string.Empty;
                        tempDump.ED2KDump         = Utils.GetED2KDump(tempDump.AVDumpFullResult);
                        tempDump.IsBeingDumped    = false;
                        tempDump.DumpStatus       = Shoko.Commons.Properties.Resources.AVDump_Error;
                        tempDump.HasBeenDumped    = false;

                        return;
                    }

                    pProcess.StartInfo.FileName = filePath;

                    //strCommandParameters are parameters to pass to program
                    string fileName = (char)34 + Commons.Extensions.Models.GetLocalFileSystemFullPath(dump.VideoLocal) + (char)34;

                    pProcess.StartInfo.Arguments =
                        $@" --Auth={VM_ShokoServer.Instance.AniDB_Username}:{VM_ShokoServer.Instance.AniDB_AVDumpKey} --LPort={VM_ShokoServer.Instance.AniDB_AVDumpClientPort} --PrintEd2kLink -t {fileName}";

                    pProcess.StartInfo.UseShellExecute        = false;
                    pProcess.StartInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                    pProcess.StartInfo.RedirectStandardOutput = true;
                    pProcess.StartInfo.CreateNoWindow         = true;
                    pProcess.Start();
                    string strOutput = pProcess.StandardOutput.ReadToEnd();

                    //Wait for process to finish
                    pProcess.WaitForExit();

                    tempDump.AVDumpFullResult = strOutput;
                    tempDump.ED2KDump         = Utils.GetED2KDump(tempDump.AVDumpFullResult);

                    if (string.IsNullOrEmpty(tempDump.ED2KDump))
                    {
                        tempDump.IsBeingDumped = false;
                        tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Error;
                        tempDump.HasBeenDumped = false;
                    }
                    else
                    {
                        tempDump.IsBeingDumped = false;
                        tempDump.DumpStatus    = Shoko.Commons.Properties.Resources.AVDump_Complete;
                        tempDump.HasBeenDumped = true;
                    }
                }
            }
            catch (Exception)
            {
                //Utils.ShowErrorMessage(ex);
            }
        }