From: syo68k Date: Mon, 26 Jul 2010 14:10:23 +0000 (+0000) Subject: ・画像投稿モードでファイルを設定した際にファイルサイズチェックを行うようにした ・画像投稿モードで無効なファイル形式を設定した場合にファイル名がクリアされない場合があるバグを修正 X-Git-Tag: Tween_v0.9.5.0~47 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5ed3bb9256a307ce2c246e50f39c118a723af2cb;p=opentween%2Fopen-tween.git ・画像投稿モードでファイルを設定した際にファイルサイズチェックを行うようにした ・画像投稿モードで無効なファイル形式を設定した場合にファイル名がクリアされない場合があるバグを修正 git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@622 e39ad16e-3079-482e-bb30-4b4d378143b6 --- diff --git a/Tween/Connection/TwitPic.vb b/Tween/Connection/TwitPic.vb index 90d9e442..5d0ddb2b 100644 --- a/Tween/Connection/TwitPic.vb +++ b/Tween/Connection/TwitPic.vb @@ -24,6 +24,8 @@ Public Class TwitPic ".gif", _ ".png"} + Private Const MaxFileSize As Long = 5 * 1024 * 1024 + Public Function Upload(ByVal mediaFile As FileInfo, _ ByVal message As String, _ ByRef content As String) As HttpStatusCode @@ -31,7 +33,7 @@ Public Class TwitPic If String.IsNullOrEmpty(message) Then message = "" 'Check filetype and size(Max 5MB) If Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then - If mediaFile.Length > 5242880 Then Throw New ArgumentException("File is too large.") + If mediaFile.Length > MaxFileSize Then Throw New ArgumentException("File is too large.") Else Throw New ArgumentException("Service don't support this filetype.") End If @@ -73,6 +75,13 @@ Public Class TwitPic Return type.Equals(UploadFileType.Picture) End Function + Public Function GetMaxFileSize(ByVal ext As String) As Long + If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then + Return MaxFileSize + End If + Return -1 + End Function + Public Sub New(ByVal accessToken As String, ByVal accessTokenSecret As String) MyBase.New(New Uri("http://api.twitter.com/"), _ New Uri("https://api.twitter.com/1/account/verify_credentials.json")) diff --git a/Tween/Connection/TwitVideo.vb b/Tween/Connection/TwitVideo.vb index a6c94522..d730cb43 100644 --- a/Tween/Connection/TwitVideo.vb +++ b/Tween/Connection/TwitVideo.vb @@ -24,6 +24,9 @@ Public Class TwitVideo ".gif", _ ".png"} + Private Const MaxPictureFileSize As Long = 10 * 1024 * 1024 + Private Const MaxMultiMediaFileSize As Long = 20 * 1024 * 1024 + Public Function Upload(ByVal mediaFile As FileInfo, _ ByVal message As String, _ ByVal keyword As String, _ @@ -34,9 +37,9 @@ Public Class TwitVideo If String.IsNullOrEmpty(message) Then Throw New ArgumentException("'Message' is required.") 'Check filetype and size If Array.IndexOf(multimediaExt, mediaFile.Extension.ToLower) > -1 Then - If mediaFile.Length > 20971520 Then Throw New ArgumentException("File is too large.") + If mediaFile.Length > MaxMultiMediaFileSize Then Throw New ArgumentException("File is too large.") ElseIf Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then - If mediaFile.Length > 10485760 Then Throw New ArgumentException("File is too large.") + If mediaFile.Length > MaxPictureFileSize Then Throw New ArgumentException("File is too large.") Else Throw New ArgumentException("Service don't support this filetype.") End If @@ -88,6 +91,15 @@ Public Class TwitVideo Return type.Equals(UploadFileType.Picture) OrElse type.Equals(UploadFileType.MultiMedia) End Function + Public Function GetMaxFileSize(ByVal ext As String) As Long + If Array.IndexOf(multimediaExt, ext.ToLower) > -1 Then + Return MaxMultiMediaFileSize + ElseIf Array.IndexOf(pictureExt, ext.ToLower) > -1 Then + Return MaxPictureFileSize + End If + Return -1 + End Function + Public Function GetFileOpenDialogFilter() As String Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png|" + _ "Movie Files(*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2)|*.avi;*.wmv;*.flv;*.m4v;*.mov;*.mp4;*.rm;*.mpeg;*.mpg;*.3gp;*.3g2" diff --git a/Tween/Connection/imgly.vb b/Tween/Connection/imgly.vb index a8ccb715..09d74391 100644 --- a/Tween/Connection/imgly.vb +++ b/Tween/Connection/imgly.vb @@ -23,6 +23,8 @@ Public Class imgly ".gif", _ ".png"} + Private Const MaxFileSize As Long = 4 * 1024 * 1024 + Public Function Upload(ByVal mediaFile As FileInfo, _ ByVal message As String, _ ByRef content As String) As HttpStatusCode @@ -30,7 +32,7 @@ Public Class imgly If String.IsNullOrEmpty(message) Then message = "" 'Check filetype and size(Max 4MB) If Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then - If mediaFile.Length > 4 * 1024 * 1024 Then Throw New ArgumentException("File is too large.") + If mediaFile.Length > MaxFileSize Then Throw New ArgumentException("File is too large.") Else Throw New ArgumentException("Service don't support this filetype.") End If @@ -71,6 +73,13 @@ Public Class imgly Return type.Equals(UploadFileType.Picture) End Function + Public Function GetMaxFileSize(ByVal ext As String) As Long + If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then + Return MaxFileSize + End If + Return -1 + End Function + Public Sub New(ByVal accessToken As String, ByVal accessTokenSecret As String) MyBase.New(New Uri("http://api.twitter.com/"), _ New Uri("https://api.twitter.com/1/account/verify_credentials.json")) diff --git a/Tween/PictureService.vb b/Tween/PictureService.vb index e3be0183..a9561f36 100644 --- a/Tween/PictureService.vb +++ b/Tween/PictureService.vb @@ -75,6 +75,19 @@ Public Class PictureService Return ret End Function + Public Function GetMaxFileSize(ByVal ext As String, ByVal service As String) As Long + Dim ret As Long = -1 + Select Case service + Case "TwitPic" + ret = (New TwitPic(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext) + Case "img.ly" + ret = (New imgly(tw.AccessToken, tw.AccessTokenSecret)).GetMaxFileSize(ext) + Case "TwitVideo" + ret = (New TwitVideo).GetMaxFileSize(ext) + End Select + Return ret + End Function + Private Function UpToTwitPic(ByVal file As FileInfo, ByRef message As String, ByVal resultUpload As Boolean) As String Dim content As String = "" Dim ret As HttpStatusCode diff --git a/Tween/Resources/ChangeLog.txt b/Tween/Resources/ChangeLog.txt index 16f4fbb8..1a345eab 100644 --- a/Tween/Resources/ChangeLog.txt +++ b/Tween/Resources/ChangeLog.txt @@ -29,6 +29,8 @@ * 詳細表示でCtrl+Insertキーでもコピーができるようにした * 画像投稿モードで使用する画像リソースを差し替えた また、動画をドラッグした場合は専用の画像を表示するようにした(thx @pureminami) * 読み上げソフトで問題が出ないように調整を行った + * 画像投稿モードでファイルを設定した際にファイルサイズチェックを行うようにした + * 画像投稿モードで無効なファイル形式を設定した場合にファイル名がクリアされない場合があるバグを修正 ==== Ver 0.9.4.0(2010/07/15) * 認証完了後、自分の発言が片思い表示になるバグ修正 * ユーザー変更時にフォロワー情報を取得するよう変更 diff --git a/Tween/Tween.vb b/Tween/Tween.vb index 73f03fcd..28eb25f4 100644 --- a/Tween/Tween.vb +++ b/Tween/Tween.vb @@ -9405,6 +9405,7 @@ RETRY: If String.IsNullOrEmpty(Trim(ImagefilePathText.Text)) Then ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" Exit Sub End If @@ -9413,6 +9414,16 @@ RETRY: '画像以外の形式 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" + Exit Sub + End If + + If svc.GetMaxFileSize(fl.Extension, ImageService) < fl.Length Then + ' ファイルサイズが大きすぎる + ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage + ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" + MessageBox.Show("File is too large.") Exit Sub End If @@ -9420,6 +9431,7 @@ RETRY: Case UploadFileType.Invalid ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" Case UploadFileType.Picture Using fs As New FileStream(ImagefilePathText.Text, FileMode.Open, FileAccess.Read) ImageSelectedPicture.Image = (New HttpVarious).CheckValidImage( _ @@ -9430,21 +9442,23 @@ RETRY: End Using ImageSelectedPicture.Tag = UploadFileType.Picture Case UploadFileType.MultiMedia - ''' TODO:動画アップロード用画像へ変更 ImageSelectedPicture.Image = My.Resources.MultiMediaImage ImageSelectedPicture.Tag = UploadFileType.MultiMedia Case Else ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" End Select Catch ex As FileNotFoundException ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" MessageBox.Show("File not found.") Catch ex As Exception ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage ImageSelectedPicture.Tag = UploadFileType.Invalid + ImagefilePathText.Text = "" MessageBox.Show("The type of this file is not image.") End Try End Sub