public SparkleFetcher(SparkleFetcherInfo info) : base(info) { if (RemoteUrl.ToString().StartsWith("ssh+")) { RemoteUrl = new Uri("ssh" + RemoteUrl.ToString().Substring(RemoteUrl.ToString().IndexOf("://"))); } Uri uri = RemoteUrl; if (!uri.Scheme.Equals("ssh") && !uri.Scheme.Equals("https") && !uri.Scheme.Equals("http") && !uri.Scheme.Equals("git")) { uri = new Uri("ssh://" + uri); } if (uri.Host.Equals("gitorious.org") && !uri.Scheme.StartsWith("http")) { if (!uri.AbsolutePath.Equals("/") && !uri.AbsolutePath.EndsWith(".git")) { uri = new Uri("ssh://[email protected]" + uri.AbsolutePath + ".git"); } else { uri = new Uri("ssh://[email protected]" + uri.AbsolutePath); } } else if (uri.Host.Equals("github.com") && !uri.Scheme.StartsWith("http")) { uri = new Uri("ssh://[email protected]" + uri.AbsolutePath); } else if (uri.Host.Equals("bitbucket.org") && !uri.Scheme.StartsWith("http")) { // Nothing really } else { if (string.IsNullOrEmpty(uri.UserInfo) && !uri.Scheme.StartsWith("http")) { if (uri.Port == -1) { uri = new Uri(uri.Scheme + "://storage@" + uri.Host + uri.AbsolutePath); } else { uri = new Uri(uri.Scheme + "://storage@" + uri.Host + ":" + uri.Port + uri.AbsolutePath); } } this.use_git_bin = false; // TODO } RemoteUrl = uri; }
///<summary>Writes this UpdateFile to an XML element for an update manifest.</summary> public XElement ToXml() { return(new XElement("File", new XAttribute("RelativePath", RelativePath), new XAttribute("Url", RemoteUrl.ToString()), new XAttribute("Size", Length.ToString(CultureInfo.InvariantCulture)), new XAttribute("Timestamp", DateModifiedUtc.ToString("o", CultureInfo.InvariantCulture)), new XElement("Hash", Convert.ToBase64String(hash)), signatures.Select(s => new XElement("Signature", Convert.ToBase64String(s))) )); }
internal String BuildRelativeURLString(String relativePath) { // the following code is a band-aid for a system problem in the codebase // where it is appending "relative paths" that start with a slash, eg: // http://dotcom/db/ + /relpart == http://dotcom/db/relpart // which is not compatible with the way the java url concatonation works. var remoteUrlString = RemoteUrl.ToString(); if (remoteUrlString.EndsWith("/", StringComparison.InvariantCultureIgnoreCase) && relativePath.StartsWith("/", StringComparison.InvariantCultureIgnoreCase)) { remoteUrlString = remoteUrlString.Substring(0, remoteUrlString.Length - 1); } return(remoteUrlString + relativePath); }
private void Play() { try { IDownloadInfo dInfo = _downloadInfo; IUrl ui = null; VideoInfo[] vInfos = new VideoInfo[] { new VideoInfo(dInfo.VideoId, dInfo.StreamId, dInfo.VideoName) }; if (!new DirectoryInfo(Path.Combine(dInfo.DownloadPath, $"{dInfo.VideoId}_{dInfo.StreamId}")).Exists) { //throw new FileNotFoundException("未找到该视频!"); vInfos = null; } ui = new RemoteUrl(dInfo.SourceIp, dInfo.SourcePort, dInfo.BeginTime, dInfo.EndTime, vInfos, dInfo.DownloadPath); string fileName = @"D:\Workspace\CCTV\CCTVReplay\CCTVReplay\bin\Debug\CCTVReplay.exe"; if (!new System.IO.FileInfo(fileName).Exists) { fileName = @"F:\CCTV\CCTVReplay\CCTVReplay\bin\Debug\CCTVReplay.exe"; } if (!new System.IO.FileInfo(fileName).Exists) { fileName = @"CCTVReplay.exe"; } if (!new FileInfo(fileName).Exists) { throw new FileNotFoundException("未找到播放软件!"); } Process.Start(fileName, ui.ToString()); Console.WriteLine("\n\n" + ui.ToString() + "\n\n"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void TestRemoteUrl() { VideoInfo[] vInfos = new VideoInfo[] { new VideoInfo("video1", 2, "Name1"), new VideoInfo("video2", 2), }; IUrl url = new RemoteUrl("127.0.0.1", 10000, new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), vInfos, @"d:\path"); string urlString = url.ToString(); Console.WriteLine(urlString); var urlNew = RemoteUrl.Parse(urlString); Assert.AreEqual(url.LocalPath, urlNew.LocalPath); Assert.AreEqual(url.VideoInfos.Length, urlNew.VideoInfos.Length); (url as RemoteUrl).CheckValid(); }
// Create an initial change set when the // user has fetched an empty remote folder public void CreateInitialChangeSet() { string file_path = Path.Combine(TargetFolder, "SparkleShare.txt"); string n = Environment.NewLine; UriBuilder uri_builder = new UriBuilder(RemoteUrl); if (RemoteUrl.Scheme.StartsWith("http")) { uri_builder.UserName = ""; uri_builder.Password = ""; } // TODO: Find better way to determine if folder should have crypto setup bool repo_is_encrypted = RemoteUrl.ToString().Contains("-crypto"); string text; if (repo_is_encrypted) { text = GenerateCryptoSalt() + " Secret project! " + GenerateCryptoSalt(); } else { text = "Congratulations, you've successfully created a SparkleShare repository!" + n + n + "Any files you add or change in this folder will be automatically synced to " + n + uri_builder.ToString() + " and everyone connected to it." + n + n + "SparkleShare is an Open Source software program that helps people " + n + "collaborate and share files. If you like what we do, please consider a small " + n + "donation to support the project: http://www.sparkleshare.org/" + n + n + "Have fun! :)" + n; } File.WriteAllText(file_path, text); }
public void Start() { IsActive = true; Started(); SparkleLogger.LogInfo("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl); if (Directory.Exists(TargetFolder)) { Directory.Delete(TargetFolder, true); } string host = RemoteUrl.Host; string host_key = GetHostKey(); if (string.IsNullOrEmpty(host) || host_key == null) { Failed(); return; } bool warn = true; if (RequiredFingerprint != null) { string host_fingerprint = GetFingerprint(host_key); if (host_fingerprint == null || !RequiredFingerprint.Equals(host_fingerprint)) { SparkleLogger.LogInfo("Auth", "Fingerprint doesn't match"); this.errors.Add("error: Host fingerprint doesn't match"); Failed(); return; } warn = false; SparkleLogger.LogInfo("Auth", "Fingerprint matches"); } else { SparkleLogger.LogInfo("Auth", "Skipping fingerprint check"); } AcceptHostKey(host_key, warn); this.thread = new Thread(() => { if (Fetch()) { Thread.Sleep(500); SparkleLogger.LogInfo("Fetcher", "Finished"); IsActive = false; // TODO: Find better way to determine if folder should have crypto setup bool repo_is_encrypted = RemoteUrl.ToString().Contains("crypto"); Finished(repo_is_encrypted, IsFetchedRepoEmpty, Warnings); } else { Thread.Sleep(500); SparkleLogger.LogInfo("Fetcher", "Failed"); IsActive = false; Failed(); } }); this.thread.Start(); }