/// <summary> /// Reset to default state /// </summary> internal static void Unload() { ConfigureWindows.GetMainWindow.TitleText.ToolTip = ConfigureWindows.GetMainWindow.TitleText.Text = Application.Current.Resources["NoImage"] as string; ConfigureWindows.GetMainWindow.Title = Application.Current.Resources["NoImage"] as string + " - " + UILogic.SetTitle.AppName; CanNavigate = false; ConfigureWindows.GetMainWindow.MainImage.Source = null; FreshStartup = true; if (Pics != null) { Pics.Clear(); } Preloader.Clear(); GalleryFunctions.Clear(); ConfigureWindows.GetMainWindow.MainImage.Width = ConfigureWindows.GetMainWindow.Scroller.Width = ConfigureWindows.GetMainWindow.Scroller.Height = ConfigureWindows.GetMainWindow.MainImage.Height = double.NaN; ScaleImage.xWidth = ScaleImage.xHeight = 0; if (!string.IsNullOrWhiteSpace(ArchiveExtraction.TempZipPath)) { DeleteTempFiles(); ArchiveExtraction.TempZipPath = string.Empty; } SystemIntegration.Taskbar.NoProgress(); }
/// <summary> /// Refresh the current list of pics and reload them if there is some missing or changes. /// </summary> internal static void Reload(bool fromBackup = false) { if (fromBackup && string.IsNullOrWhiteSpace(BackupPath)) { Unload(); return; } string s; if (Pics != null && Pics.Count > 0) { s = fromBackup ? BackupPath : Pics[FolderIndex]; } else { // TODO extract url from path or get alternative method s = Path.GetFileName(ConfigureWindows.GetMainWindow.TitleText.Text); } if (File.Exists(s)) { // Force reloading values by setting freshStartup to true FreshStartup = true; // Clear Preloader, to avoid errors by FolderIndex changing location because of re-sorting Preloader.Clear(); // Need a sort method instead GalleryFunctions.Clear(); Pic(s); // Reset if (Flipped) { Flip(); } if (Rotateint != 0) { Rotate(0); } } else if (Clipboard.ContainsImage() || Base64.IsBase64String(s)) { return; } else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web { LoadFromWeb.PicWeb(s); } else { Unload(); ShowTooltipMessage(Application.Current.Resources["UnexpectedError"]); } }
/// <summary> /// Clears data, to free objects no longer necessary to store in memory and allow changing folder without error. /// </summary> internal static void ChangeFolder(bool backup = false) { if (Pics.Count > 0 && backup) { // Make a backup of xPicPath and FolderIndex if (!string.IsNullOrWhiteSpace(Pics[FolderIndex])) { BackupPath = Pics[FolderIndex]; } } Pics.Clear(); GalleryFunctions.Clear(); Preloader.Clear(); FreshStartup = true; DeleteTempFiles(); }
/// <summary> /// Goes to next, previous, first or last file in folder /// </summary> /// <param name="next">Whether it's forward or not</param> /// <param name="end">Whether to go to last or first, /// depending on the next value</param> internal static void Pic(bool next = true, bool end = false) { // Exit if not intended to change picture if (!CanNavigate) { return; } // exit if browsing PicGallery if (GetPicGallery != null) { if (Properties.Settings.Default.PicGallery == 1) { if (GalleryFunctions.IsOpen) { return; } } } // Make backup var indexBackup = FolderIndex; if (!end) // Go to next or previous { if (next) { // loop next if (Properties.Settings.Default.Looping || Slideshow.SlideTimer != null && Slideshow.SlideTimer.Enabled) { FolderIndex = FolderIndex == Pics.Count - 1 ? 0 : FolderIndex + 1; } else { // Go to next if able if (FolderIndex + 1 == Pics.Count) { return; } FolderIndex++; } Reverse = false; } else { // Loop prev if (Properties.Settings.Default.Looping || Slideshow.SlideTimer != null && Slideshow.SlideTimer.Enabled) { FolderIndex = FolderIndex == 0 ? Pics.Count - 1 : FolderIndex - 1; } else { // Go to prev if able if (FolderIndex - 1 < 0) { return; } FolderIndex--; } Reverse = true; } } else // Go to first or last { FolderIndex = next ? Pics.Count - 1 : 0; indexBackup = FolderIndex; // Reset preloader values to prevent errors if (Pics.Count > 20) { Preloader.Clear(); } } // Go to the image! Pic(FolderIndex); // Update PicGallery selected item, if needed if (GetPicGallery != null) { if (GetPicGallery.Container.Children.Count > FolderIndex && GetPicGallery.Container.Children.Count > indexBackup) { if (indexBackup != FolderIndex) { GalleryFunctions.SetUnselected(indexBackup); } GalleryFunctions.SetSelected(FolderIndex); GalleryScroll.ScrollTo(); } else { // TODO Find way to get PicGalleryItem an alternative way... } } CloseToolTipMessage(); }
private void ProcessUpload(AsyncFileUploadEventArgs e) { if (e.FileName == null) { return; } ModConfigBase controller = (ModConfigBase)ConfigHelper.ModClass("UploadConfig"); string types = ""; if (AllowAttachments) { types += controller.ModConfiguration.Settings["AllowedAttachmentTypes"].ToString(); } if (AllowImageUploads) { if (types != "") { types += ","; } types += controller.ModConfiguration.Settings["AllowedImageTypes"].ToString(); } string[] allowedTypes = types.Split(','); //int fileSizeLimit = 10; //Convert.ToInt32(controller.ModConfiguration.Settings["FileSizeLimit"].ToString()); string uploadpath = controller.ModConfiguration.Settings["FileUploadLocation"].ToString(); string filext = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName).Replace(".", ""); string contentType = AsyncFileUpload1.PostedFile.ContentType; bool allowed = false; if (contentType.Contains("image") && !AllowImageUploads) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "prohibited", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Image upload prohibited';});", true); AsyncFileUpload1.FailedValidation = true; return; } if (!contentType.Contains("image") && !AllowAttachments) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "prohibited", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'File attachments prohibited';});", true); AsyncFileUpload1.FailedValidation = true; return; } foreach (string allowedType in allowedTypes) { if (filext == allowedType) { allowed = true; break; } } if (!allowed || (int.Parse(e.FileSize) > (FileSizeLimit * (1024 * 1024)))) { AsyncFileUpload1.FailedValidation = true; return; } var name = Path.GetFileName(e.FileName); if (contentType.Contains("image")) { uploadpath = "/Gallery"; } string savePath = Page.MapPath(String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+"))); if (File.Exists(savePath)) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "exists", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'File already exists';});", true); AsyncFileUpload1.FailedValidation = true; return; } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "$(function() {top.$get(\"" + uploadResult.ClientID + "\").innerHTML = 'Uploaded size: " + e.FileSize + "';});", true); if (!Directory.Exists(Page.MapPath(String.Format("{0}/{1}", uploadpath, HttpContext.Current.User.Identity.Name)))) { Directory.CreateDirectory( Page.MapPath(String.Format("{0}/{1}", uploadpath, HttpContext.Current.User.Identity.Name))); } if (contentType.Contains("image")) { if (e.FileName != null && AllowImageUploads) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tag", "$(function() {top.$get(\"" + imageTag.ClientID + "\").innerHTML = '[img]" + String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+")) + "[/img]';});", true); } } else { if (e.FileName != null && AllowAttachments) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tag", "$(function() {top.$get(\"" + imageTag.ClientID + "\").innerHTML = '[file=" + e.FileName + "]" + String.Format("{0}/{1}/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+")) + "[/file]';});", true); } } AsyncFileUpload1.SaveAs(savePath); if (contentType.Contains("image")) { string thumbPath = Page.MapPath(String.Format("{0}/{1}/thumbnail/{2}", uploadpath, HttpContext.Current.User.Identity.Name, name.Replace(" ", "+"))); if (!Directory.Exists(Page.MapPath(String.Format("{0}/{1}/thumbnail", uploadpath, HttpContext.Current.User.Identity.Name)))) { Directory.CreateDirectory(Page.MapPath(String.Format("{0}/{1}/thumbnail", uploadpath, HttpContext.Current.User.Identity.Name))); } GalleryFunctions.CreateThumbnail(savePath, thumbPath, 100); } }
private void SetupDynamicControls() { _editmode = _editmode || IsMyProfile; if (_editmode) { //Quote var tbxQuote = new TextBox { ID = "tbxQuote", TextMode = TextBoxMode.MultiLine, CssClass = "QRMsgArea", Height = new Unit(99, UnitType.Pixel), Text = _user.FavouriteQuote }; phQuote.Controls.Add(tbxQuote); var tbxSig = new TextBox { ID = "tbxSig", CssClass = "QRMsgArea", TextMode = TextBoxMode.MultiLine, Height = new Unit(99, UnitType.Pixel), Text = _user.Signature.Replace(">", "]").Replace("<", "[") }; phSig.Controls.Add(tbxSig); var tbxBiog = new TextBox { ID = "tbxBiog", TextMode = TextBoxMode.MultiLine, CssClass = "QRMsgArea", Height = new Unit(99, UnitType.Pixel), Text = _user.Biography }; phBiog.Controls.Add(tbxBiog); var tbxHobby = new TextBox { ID = "tbxHobby", TextMode = TextBoxMode.MultiLine, CssClass = "QRMsgArea", Height = new Unit(99, UnitType.Pixel), Text = _user.Hobbies }; phHobby.Controls.Add(tbxHobby); var tbxNews = new TextBox { ID = "tbxNews", TextMode = TextBoxMode.MultiLine, CssClass = "QRMsgArea", Height = new Unit(99, UnitType.Pixel), Text = _user.LatestNews }; phNews.Controls.Add(tbxNews); lblHomePage.Visible = true; lblHomePage.AssociatedControlID = "tbxHomePage"; var tbxHomePage = new TextBox { ID = "tbxHomePage", TextMode = TextBoxMode.SingleLine, Text = _user.HomePage }; phHomePage.Controls.Add(tbxHomePage); } else { var tbxQuote = new Label { ID = "lblQuote", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), Text = _user.FavouriteQuote }; phQuote.Controls.Add(tbxQuote); var tbxSig = new Label { ID = "lblSig", CssClass = "bbcode", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), Text = @"<hr/>" + _user.Signature }; phSig.Controls.Add(tbxSig); var tbxBiog = new Label { ID = "lblBiog", CssClass = "bbcode", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), Text = _user.Biography }; phBiog.Controls.Add(tbxBiog); var tbxHobby = new Label { ID = "lblHobby", CssClass = "bbcode", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), Text = _user.Hobbies }; phHobby.Controls.Add(tbxHobby); var tbxNews = new Label { ID = "lblNews", CssClass = "bbcode", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), Text = _user.LatestNews }; phNews.Controls.Add(tbxNews); if (_user.HomePage != null) { _user.HomePage = _user.HomePage.Trim(); } string link = _user.HomePage; if (link != "") { lblHomePage.Visible = false; var tbxHomePage = new HyperLink { ID = "lnkHomePage", Width = new Unit(100, UnitType.Percentage), Height = new Unit(), NavigateUrl = _user.HomePage, Text = webResources.lblVisitHomePage }; phHomePage.Controls.Add(tbxHomePage); } else { lblHomePage.Text = webResources.NoHomePage; } } repFavLinks.DataSource = _weblinks; repFavLinks.DataBind(); if (Config.UserGallery) { TabGallery.Visible = true; TabGallery.HeaderText = "Images"; dlImages.DataSource = GalleryFunctions.GetImages(_profileUser); dlImages.DataBind(); } else { TabGallery.Visible = false; TabGallery.HeaderText = "Images"; } }
private void BindImages() { rptImage.DataSource = GalleryFunctions.GetImages(_currentGallery); rptImage.DataBind(); }