/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { BrowseResult browseResult = new BrowseResult(); DriveType driveType; foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) { driveType = driveInfo.DriveType; if (driveType != DriveType.NoRootDirectory && driveType != DriveType.Ram && driveType != DriveType.Unknown && driveType != DriveType.Network && driveInfo.IsReady) { if (browseResult.TotalCount >= startIndex) { browseResult.Entries.Add(new Folder() { UsePathAsId = true, Label = (String.IsNullOrWhiteSpace(driveInfo.VolumeLabel) ? driveInfo.Name : String.Format("{0} ({1})", driveInfo.VolumeLabel, driveInfo.Name)), Path = driveInfo.RootDirectory.FullName }); } browseResult.TotalCount += 1; } } return(browseResult); }
private void AddFolder(BrowseResult browseResult, uint startIndex, uint requestedCount, string label, string path) { if (browseResult.TotalCount >= startIndex && browseResult.Entries.Count < requestedCount) { browseResult.Entries.Add(new Shutdown() { UsePathAsId = true, Label = label, Path = path }); } browseResult.TotalCount += 1; }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { try { string path = Path; BrowseResult browseResult = new BrowseResult(); using (StreamReader streamReader = new StreamReader(path, Encoding.GetEncoding(1252))) { GetMediaFiles(streamReader, System.IO.Path.GetDirectoryName(path), browseResult.Entries, startIndex, requestedCount); } return(browseResult); } catch (Exception ex) { Utils.WriteException(ex); } return(null); }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { if (Path == null) { BrowseResult browseResult = new BrowseResult(); AddFolder(browseResult, startIndex, requestedCount, Resources.Cancel, "ShutdownCancel"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 30), "Shutdown30"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 60), "Shutdown60"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 90), "Shutdown90"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 120), "Shutdown120"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 180), "Shutdown180"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 240), "Shutdown240"); AddFolder(browseResult, startIndex, requestedCount, Resources.ShutdownImmediatly, "Shutdown"); AddFolder(browseResult, startIndex, requestedCount, Resources.Restart, "Restart"); return(browseResult); } ShutdownTimer.Stop(); TickCount = null; switch (Path) { case "ShutdownCancel": break; case "Shutdown": OnShutdown(); break; case "Restart": OnShutdown(true); break; default: ShutdownTimer.Interval = Int32.Parse(Path.Substring(8)) * 60000; TickCount = Environment.TickCount; ShutdownTimer.Start(); break; } return(null); }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { var browseResult = new BrowseResult(); var defaultEntries = Settings.Default.Entries; browseResult.TotalCount = defaultEntries.Count(); int i = 0; foreach (var entry in defaultEntries) { if (i >= startIndex) { browseResult.Entries.Add(entry); if (browseResult.Entries.Count == requestedCount) { break; } } i += 1; } return(browseResult); }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { var entries = new EntryCollection(); entries.AddRange(Children); if (!String.IsNullOrWhiteSpace(Path)) { try { bool isFreeboxV5 = (userAgent == UserAgent.FreeboxV5); foreach (var file in Directory.GetFiles(Path, "*.*", SearchOption.TopDirectoryOnly)) { try { var f = FileFactory.CreateFile(file); if (f is IContainer) { var entry = ((IContainer)f).GetContent(isFreeboxV5); if (entry == null) { continue; } if (!(entry is IMedia)) { entries.Add(entry); continue; } f = (IMedia)entry; } if (f.MediaKind != null && (f.MediaKind & MediaKind) > 0) { entries.Add((Entry)f); } } catch (Exception ex) { Utils.WriteException(ex); } } } catch (Exception ex) { Utils.WriteException(ex); } try { foreach (var directory in Directory.GetDirectories(Path, "*.*", SearchOption.TopDirectoryOnly)) { try { var folder = new Folder() { UsePathAsId = true, Path = directory }; if (!folder.IsHidden) { entries.Add(folder); } } catch (Exception ex) { Utils.WriteException(ex); } } } catch (Exception ex) { Utils.WriteException(ex); } } entries.Sort(new Comparison <Entry>((e1, e2) => { if (e1 is FolderBase && !(e2 is FolderBase)) { return(-1); } if (e2 is FolderBase && !(e1 is FolderBase)) { return(1); } if (e1.Label == null) { return(e2.Label == null ? 0 : -1); } return(e1.Label.CompareTo(e2.Label)); })); var browseResult = new BrowseResult() { TotalCount = entries.Count }; int i = 0; foreach (Entry entry in entries) { if (i == startIndex) { if (browseResult.Entries.Count < requestedCount) { browseResult.Entries.Add(entry); } else { break; } } else { i += 1; } } return(browseResult); }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { Uri uri; MimeType.IsLiveStream(Path, out uri); var xml = GetDataFromUri(uri); string nodeName, url = null, mimeType = null, length = null, title; XmlElement urlXmlElement, titleXmlElement, dateXmlElement; int index; DateTime? date; DateTime parsedDate; bool isFreeboxV5 = (userAgent == UserAgent.FreeboxV5); bool isFreeboxV6 = (userAgent == UserAgent.FreeboxV6); var browseResult = new BrowseResult(); if (requestedCount > 200) { requestedCount = 200; } int filesCount = 0; foreach (XmlNode node in xml.GetElementsByTagName("channel")) { foreach (XmlNode subNode in node) { nodeName = subNode.Name.ToLowerInvariant(); if (nodeName == "item") { titleXmlElement = subNode["title"]; if (titleXmlElement == null || String.IsNullOrWhiteSpace(titleXmlElement.InnerText)) { continue; } title = titleXmlElement.InnerText.Trim(); dateXmlElement = subNode["pubDate"]; date = ((dateXmlElement != null && DateTime.TryParse(dateXmlElement.InnerText, out parsedDate)) ? parsedDate : (DateTime?)null); urlXmlElement = subNode["enclosure"]; if (urlXmlElement != null) { url = GetAttributeValue(urlXmlElement, "url"); length = GetAttributeValue(urlXmlElement, "length"); mimeType = GetAttributeValue(urlXmlElement, "type"); } else { urlXmlElement = subNode["guid"]; if (urlXmlElement != null) { url = urlXmlElement.InnerText; } else { urlXmlElement = subNode["link"]; if (urlXmlElement != null) { if (GetAttributeValue(urlXmlElement, "freeboxV5") != "false" || !isFreeboxV5) { if (browseResult.TotalCount >= startIndex) { browseResult.Entries.Add(new Podcast() { UsePathAsId = true, Label = title, Path = urlXmlElement.InnerText, CreationDate = date }); } browseResult.TotalCount += 1; if (browseResult.Entries.Count == requestedCount) { break; } continue; } } } } if (String.IsNullOrWhiteSpace(url)) { continue; } long l = 0; if (!String.IsNullOrWhiteSpace(length)) { long.TryParse(length, out l); } if (l == -1) { l = 0; } url = HttpUtility.UrlDecode(url); index = url.IndexOf("media_url="); if (index == -1) { index = url.LastIndexOf("http://"); if (index != url.IndexOf("http://")) { url = url.Substring(index); } } else { url = url.Substring(index + 10, url.Length - index - 10); } string mimeTypeFromFileName = MimeType.GetMimeTypeFromFileName(url, null); if (mimeTypeFromFileName != null) { mimeType = mimeTypeFromFileName; } if (browseResult.TotalCount >= startIndex) { browseResult.Entries.Add(new File() { Path = url, Label = title, CreationDate = date, MimeType = mimeType, Length = l }); filesCount += 1; } browseResult.TotalCount += 1; if (browseResult.Entries.Count == requestedCount) { break; } } } if (browseResult.Entries.Count == requestedCount) { break; } } if (isFreeboxV6 && filesCount > 0) { // Workaround on Freebox V6 to keep the order of the files uint i = startIndex + 1; File file; string format = GetLinesNumberingFormat(filesCount); foreach (var entry in browseResult.Entries) { file = entry as File; if (file != null) { file.Label = String.Format(format, i, file.Label); } i += 1; } } return(browseResult); }