OSDN Git Service

・画像投稿モードでファイルを設定した際にファイルサイズチェックを行うようにした ・画像投稿モードで無効なファイル形式を設定した場合にファイル名がクリアされない場合があるバグを修正
authorsyo68k <syo68k@users.sourceforge.jp>
Mon, 26 Jul 2010 14:10:23 +0000 (14:10 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:14:17 +0000 (23:14 +0900)
git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@622 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/Connection/TwitPic.vb
Tween/Connection/TwitVideo.vb
Tween/Connection/imgly.vb
Tween/PictureService.vb
Tween/Resources/ChangeLog.txt
Tween/Tween.vb

index 90d9e44..5d0ddb2 100644 (file)
@@ -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"))
index a6c9452..d730cb4 100644 (file)
@@ -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"
index a8ccb71..09d7439 100644 (file)
@@ -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"))
index e3be018..a9561f3 100644 (file)
@@ -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
index 16f4fbb..1a345ea 100644 (file)
@@ -29,6 +29,8 @@
  * 詳細表示でCtrl+Insertキーでもコピーができるようにした
  * 画像投稿モードで使用する画像リソースを差し替えた また、動画をドラッグした場合は専用の画像を表示するようにした(thx @pureminami)
  * 読み上げソフトで問題が出ないように調整を行った
+ * 画像投稿モードでファイルを設定した際にファイルサイズチェックを行うようにした
+ * 画像投稿モードで無効なファイル形式を設定した場合にファイル名がクリアされない場合があるバグを修正
 ==== Ver 0.9.4.0(2010/07/15)
  * 認証完了後、自分の発言が片思い表示になるバグ修正
  * ユーザー変更時にフォロワー情報を取得するよう変更
index 73f03fc..28eb25f 100644 (file)
@@ -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