public MainWindow() { Dictionary <string, object> defaultvals = new Dictionary <string, object>(); defaultvals.Add("SaveLocation", Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)); defaultvals.Add("SourceURL", "http://konachan.net"); defaultvals.Add("Tags", new List <string>()); defaultvals.Add("GoToID", ""); settingsmanager = new SettingsManager(defaultvals, EXT); string[] args = Environment.GetCommandLineArgs(); /* 0 - FileLocation of executable * 1 - (optional) FileLocation of file to open with app */ if (args.Length > 1) { settingsmanager.Load(new FileInfo(args[1])); } flow = new ImageFlowClient(new DirectoryInfo(settingsmanager.Get <string>("SaveLocation"))); InitializeComponent(); optSaveLocation.Text = settingsmanager.Get <string>("SaveLocation"); optSourceURL.Text = settingsmanager.Get <string>("SourceURL"); foreach (string s in settingsmanager.Get <List <string> >("Tags")) { addTag(s); } optGoToID.Text = settingsmanager.Get <string>("GoToID"); timer.Elapsed += timer_Elapsed; timer.Interval = 3 * 1000; timer.AutoReset = false; this.WindowState = System.Windows.WindowState.Normal; if (!settingsmanager.IsFileAssociationRegisterd && System.Windows.Forms.MessageBox.Show(String.Format( "Möchten Sie die Dateierweiterung '.{0}' mit diesem Programm verknüpfen?" , EXT ), "Filextension", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { settingsmanager.RegisterFileAssociation(); } init(); }
public FlowImage(XElement descr, ImageFlowClient parent) { Tags = new List <string>(); Parent = parent; ID = descr.Attribute(XName.Get("id")).Value; string sourcelnk = descr.Attribute(XName.Get("source")).Value; if (sourcelnk.CompareTo(string.Empty) != 0 && Uri.IsWellFormedUriString(sourcelnk, UriKind.Absolute)) { Lnk = new Uri(sourcelnk); } Tags.AddRange(descr.Attribute(XName.Get("tags")).Value.Split(' ')); sampleURI = descr.Attribute(XName.Get("sample_url")).Value; if (descr.Attribute(XName.Get("jpeg_url")).Value.CompareTo(string.Empty) == 0) { downloadURI = new Uri(descr.Attribute(XName.Get("jpeg_url")).Value); } else { downloadURI = new Uri(descr.Attribute(XName.Get("file_url")).Value); } string r = descr.Attribute(XName.Get("rating")).Value; if (r.ToLower().CompareTo("s") == 0) { Rating |= FlowImage.rating.Safe; } else if (r.ToLower().CompareTo("e") == 0) { Rating |= FlowImage.rating.Explicit; } else if (r.ToLower().CompareTo("q") == 0) { Rating |= FlowImage.rating.Questionable; } else { Rating |= FlowImage.rating.Other; } fileName = Path.GetInvalidFileNameChars().Aggregate( System.IO.Path.GetFileName(Path.GetInvalidPathChars().Aggregate(downloadURI.LocalPath, (current, c) => current.Replace(c.ToString(), string.Empty))) , (current, c) => current.Replace(c.ToString(), string.Empty)); savePath = Path.Combine(Parent.CacheLocation.ToString(), fileName); }