Fix PVS high issues

This commit is contained in:
Jaex 2019-09-20 10:48:45 +03:00
parent 74b9de085e
commit 20c83136a9
8 changed files with 22 additions and 35 deletions

View file

@ -284,12 +284,7 @@ private static Image GetImageAlternative()
{
try
{
Image img = GetDIBImage(ms);
if (img != null)
{
return img;
}
return GetDIBImage(ms);
}
catch (Exception e)
{

View file

@ -814,27 +814,21 @@ public static bool IsImageTransparent(Bitmap bmp)
public static bool AddMetadata(Image img, int id, string text)
{
PropertyItem pi;
try
{
pi = (PropertyItem)typeof(PropertyItem).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { }, null).Invoke(null);
PropertyItem pi = (PropertyItem)typeof(PropertyItem).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { }, null).Invoke(null);
pi.Id = id;
pi.Len = text.Length + 1;
pi.Type = 2;
byte[] bytesText = Encoding.ASCII.GetBytes(text + " ");
bytesText[bytesText.Length - 1] = 0;
pi.Value = bytesText;
if (pi != null)
{
img.SetPropertyItem(pi);
return true;
}
img.SetPropertyItem(pi);
return true;
}
catch (Exception e)
{
DebugHelper.WriteException(e, "Reflection failed.");
DebugHelper.WriteException(e, "AddMetadata reflection failed.");
}
return false;
@ -1142,7 +1136,7 @@ public static void Pixelate(Bitmap bmp, int pixelSize)
{
ColorBgra color = unsafeBitmap.GetPixel(x2, y2);
float pixelWeight = (float)color.Alpha / 255;
float pixelWeight = color.Alpha / 255f;
r += color.Red * pixelWeight;
g += color.Green * pixelWeight;

View file

@ -203,13 +203,14 @@ private void LoadImageUploaderSettings()
if (OAuthInfo.CheckOAuth(Config.PhotobucketOAuthInfo))
{
lblPhotobucketAccountStatus.Text = Resources.UploadersConfigForm_Login_successful;
txtPhotobucketDefaultAlbumName.Text = Config.PhotobucketAccountInfo.AlbumID;
lblPhotobucketParentAlbumPath.Text = Resources.UploadersConfigForm_LoadSettings_Parent_album_path_e_g_ + " " +
Config.PhotobucketAccountInfo.AlbumID + "/Personal/" + DateTime.Now.Year;
}
if (Config.PhotobucketAccountInfo != null)
{
txtPhotobucketDefaultAlbumName.Text = Config.PhotobucketAccountInfo.AlbumID;
lblPhotobucketParentAlbumPath.Text = Resources.UploadersConfigForm_LoadSettings_Parent_album_path_e_g_ + " " +
Config.PhotobucketAccountInfo.AlbumID + "/Personal/" + DateTime.Now.Year;
cboPhotobucketAlbumPaths.Items.Clear();
if (Config.PhotobucketAccountInfo.AlbumList.Count > 0)

View file

@ -129,9 +129,10 @@ public override UploadResult Upload(Stream stream, string fileName)
{
string photoid = xele.Value;
FlickrPhotosGetSizesResponse photos = PhotosGetSizes(photoid);
FlickrPhotosGetSizesSize photo = photos?.sizes?.size?[photos.sizes.size.Length - 1];
if (photo != null)
if (photos != null && photos.sizes != null && photos.sizes.size != null && photos.sizes.size.Length > 0)
{
FlickrPhotosGetSizesSize photo = photos.sizes.size[photos.sizes.size.Length - 1];
if (Settings.DirectLink)
{
result.URL = photo.source;

View file

@ -462,15 +462,11 @@ private void PbThumbnail_MouseMove(object sender, MouseEventArgs e)
{
if (Task.Info != null && !string.IsNullOrEmpty(Task.Info.FilePath) && File.Exists(Task.Info.FilePath))
{
Program.MainForm.AllowDrop = false;
IDataObject dataObject = new DataObject(DataFormats.FileDrop, new string[] { Task.Info.FilePath });
if (dataObject != null)
{
Program.MainForm.AllowDrop = false;
dragBoxFromMouseDown = Rectangle.Empty;
pbThumbnail.DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move);
Program.MainForm.AllowDrop = true;
}
dragBoxFromMouseDown = Rectangle.Empty;
pbThumbnail.DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move);
Program.MainForm.AllowDrop = true;
}
else
{

View file

@ -152,7 +152,7 @@ private void btnCopyLink_Click(object sender, EventArgs e)
{
url = lvClipboardFormats.Items[0].SubItems[1].Text;
}
else if (lvClipboardFormats.SelectedItems.Count > 0)
else
{
url = lvClipboardFormats.SelectedItems[0].SubItems[1].Text;
}

View file

@ -658,8 +658,8 @@ public static Icon GetProgressIcon(int percentage)
using (Font font = new Font("Arial", 10))
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
g.DrawString(percentage.ToString(), font, Brushes.Black, size.Width / 2, size.Height / 2, sf);
g.DrawString(percentage.ToString(), font, Brushes.White, size.Width / 2, (size.Height / 2) - 1, sf);
g.DrawString(percentage.ToString(), font, Brushes.Black, size.Width / 2f, size.Height / 2f, sf);
g.DrawString(percentage.ToString(), font, Brushes.White, size.Width / 2f, (size.Height / 2f) - 1, sf);
}
return Icon.FromHandle(bmp.GetHicon());

View file

@ -265,10 +265,10 @@ private static void Task_TaskCompleted(WorkerTask task)
{
try
{
task.KeepImage = false;
if (task != null)
{
task.KeepImage = false;
if (task.RequestSettingUpdate)
{
Program.MainForm.UpdateCheckStates();