OpenTween.MediaSelector.ImageFromSelectedFile C# (CSharp) Method

ImageFromSelectedFile() private method

private ImageFromSelectedFile ( int index, IMediaItem item, bool noMsgBox ) : void
index int
item IMediaItem
noMsgBox bool
return void
        private void ImageFromSelectedFile(int index, IMediaItem item, bool noMsgBox)
        {
            var valid = false;

            try
            {
                var imageService = this.SelectedService;
                if (imageService == null) return;

                var selectedIndex = ImagePageCombo.SelectedIndex;
                if (index < 0) index = selectedIndex;

                if (index >= ImagePageCombo.Items.Count)
                    throw new ArgumentOutOfRangeException(nameof(index));

                var isSelectedPage = (index == selectedIndex);

                if (isSelectedPage)
                    this.ClearImageSelectedPicture();

                if (item == null || string.IsNullOrEmpty(item.Path)) return;

                try
                {
                    var ext = item.Extension;
                    var size = item.Size;

                    if (!imageService.CheckFileExtension(ext))
                    {
                        //画像以外の形式
                        if (!noMsgBox)
                        {
                            MessageBox.Show(
                                string.Format(Properties.Resources.PostPictureWarn3, this.ServiceName, MakeAvailableServiceText(ext, size), ext, item.Name),
                                Properties.Resources.PostPictureWarn4,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        }
                        return;
                    }

                    if (!imageService.CheckFileSize(ext, size))
                    {
                        // ファイルサイズが大きすぎる
                        if (!noMsgBox)
                        {
                            MessageBox.Show(
                                string.Format(Properties.Resources.PostPictureWarn5, this.ServiceName, MakeAvailableServiceText(ext, size), item.Name),
                                Properties.Resources.PostPictureWarn4,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        }
                        return;
                    }

                    if (item.IsImage)
                    {
                        if (isSelectedPage)
                            ImageSelectedPicture.Image = item.CreateImage();
                        SetImagePage(index, item, MyCommon.UploadFileType.Picture);
                    }
                    else
                    {
                        SetImagePage(index, item, MyCommon.UploadFileType.MultiMedia);
                    }

                    valid = true;  //正常終了
                }
                catch (FileNotFoundException)
                {
                    if (!noMsgBox) MessageBox.Show("File not found.");
                }
                catch (Exception)
                {
                    if (!noMsgBox) MessageBox.Show("The type of this file is not image.");
                }
            }
            finally
            {
                if (!valid)
                {
                    ClearImagePage(index);
                    DisposeMediaItem(item);
                }
            }
        }

Same methods

MediaSelector::ImageFromSelectedFile ( IMediaItem item, bool noMsgBox ) : void