예제 #1
0
        /// <summary>
        /// Create Recording filename based on RTSP url, UNC or real path.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetFileNameForRecording(Recording rec)
        {
            bool   useRTSP  = TVHome.UseRTSP();
            string fileName = "";

            if (!useRTSP) //SMB mode
            {
                bool fileExists = File.Exists(rec.FileName);
                if (!fileExists)
                // fileName does not exist b/c it points to the local folder on the tvserver, which is ofcourse invalid on the tv client.
                {
                    if (TVHome.RecordingPath().Length > 0)
                    {
                        //use user defined recording folder as either UNC or network drive
                        fileName = Path.GetFileName(rec.FileName);
                        string fileNameSimple = TVHome.RecordingPath() + "\\" + fileName;

                        fileExists = File.Exists(fileNameSimple);

                        if (!fileExists)
                        //maybe file exist in folder, schedules recs often appear in folders, no way to intelligently determine this.
                        {
                            DirectoryInfo dirInfo = Directory.GetParent(rec.FileName);

                            if (dirInfo != null)
                            {
                                string parentFolderName = dirInfo.Name;
                                fileName = TVHome.RecordingPath() + "\\" + parentFolderName + "\\" + fileName;
                            }
                        }
                        else
                        {
                            fileName = fileNameSimple;
                        }
                    }
                    else // use automatic UNC path
                    {
                        fileName = rec.FileName.Replace(":", "");
                        fileName = "\\\\" + RemoteControl.HostName + "\\" + fileName;
                    }
                }
                else //file exists, return it.
                {
                    fileName = rec.FileName;
                }
            }
            else //RTSP mode, get RTSP url for file.
            {
                fileName = TVHome.TvServer.GetStreamUrlForFileName(rec.IdRecording);
            }

            return(fileName);
        }
예제 #2
0
        /// <summary>
        /// Create Recording filename based on RTSP url, UNC or real path.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetFileNameForRecording(Recording rec)
        {
            bool   useRTSP  = TVHome.UseRTSP();
            string fileName = "";

            if (!useRTSP) //SMB mode
            {
                bool fileExists = File.Exists(rec.FileName);
                if (!fileExists)
                // fileName does not exist b/c it points to the local folder on the tvserver, which is ofcourse invalid on the tv client.
                {
                    if (TVHome.RecordingPath().Length > 0)
                    {
                        //use user defined recording folder as either UNC or network drive
                        fileName = Path.GetFileName(rec.FileName);
                        string fileNameSimple = TVHome.RecordingPath() + "\\" + fileName;

                        fileExists = File.Exists(fileNameSimple);

                        if (!fileExists)
                        //maybe file exist in folder, schedules recs often appear in folders, no way to intelligently determine this.
                        {
                            DirectoryInfo dirInfo = Directory.GetParent(rec.FileName);

                            if (dirInfo != null)
                            {
                                string parentFolderName = dirInfo.Name;
                                fileName = TVHome.RecordingPath() + "\\" + parentFolderName + "\\" + fileName;
                            }

                            fileExists = File.Exists(fileName);

                            //check with foldername from set UNC Path
                            if (!fileExists)
                            {
                                //Get last foldername of RecordingPath
                                string parentFolderNameRecording =
                                    Path.GetFileName(TVHome.RecordingPath().TrimEnd(Path.DirectorySeparatorChar));
                                parentFolderNameRecording = @"\" + parentFolderNameRecording.Replace(@"\", "\"\"") + @"\";
                                //Replace "\" with "" and add a "\" at the beginning and end (good for searching the path in the recording filename)

                                //Search the last folder of the set recording path in var rec.FileName
                                int iPos = rec.FileName.IndexOf(parentFolderNameRecording);
                                if (iPos != -1)
                                {
                                    //We have found the last Folder of the set recording path in var rec.FileName

                                    //Cut the first string (ussaly the TV Server Local Path) and remove the last Recording Folder from string
                                    fileName = rec.FileName.Substring(iPos).Replace(parentFolderNameRecording, "");

                                    //Add the recording path
                                    fileName = TVHome.RecordingPath() + "\\" + fileName;
                                }
                            }
                        }
                        else
                        {
                            fileName = fileNameSimple;
                        }
                    }
                    else // use automatic UNC path
                    {
                        fileName = rec.FileName.Replace(":", "");
                        fileName = "\\\\" + RemoteControl.HostName + "\\" + fileName;
                    }
                }
                else //file exists, return it.
                {
                    fileName = rec.FileName;
                }
            }
            else //RTSP mode, get RTSP url for file.
            {
                fileName = TVHome.TvServer.GetStreamUrlForFileName(rec.IdRecording);
            }

            return(fileName);
        }