+++ /dev/null
-Imports System.Drawing
-Imports System.IO
-
-Public Class ImageCacheDictionary
- Implements IDictionary(Of String, Image), IDisposable
-
- Private ReadOnly lockObject As New Object()
-
- Private cacheDiractoryPath As String
- Private memoryCacheCount As Integer
- Private innerDictionary As Dictionary(Of String, CachedImage)
- Private sortedKeyList As List(Of String) '古いもの順
- Private fileCacheProcList As New Queue(Of Threading.ThreadStart)()
-
- Public Sub New(ByVal cacheDirectory As String, ByVal memoryCacheCount As Integer)
- SyncLock Me.lockObject
- Me.innerDictionary = New Dictionary(Of String, CachedImage)(memoryCacheCount + 1)
- Me.sortedKeyList = New List(Of String)(memoryCacheCount + 1)
- Me.memoryCacheCount = memoryCacheCount
- Me.cacheDiractoryPath = cacheDirectory
- If Not Directory.Exists(Me.cacheDiractoryPath) Then
- Directory.CreateDirectory(Me.cacheDiractoryPath)
- End If
- End SyncLock
- End Sub
-
- Public Sub Add(ByVal item As System.Collections.Generic.KeyValuePair(Of String, Image)) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).Add
- Me.Add(item.Key, item.Value)
- End Sub
-
- Public Sub Add(ByVal key As String, ByVal value As Image) Implements System.Collections.Generic.IDictionary(Of String, Image).Add
- SyncLock Me.lockObject
- Me.innerDictionary.Add(key, New CachedImage(value, Me.cacheDiractoryPath))
- Me.sortedKeyList.Add(key)
-
- If Me.innerDictionary.Count > Me.memoryCacheCount Then
- Me.innerDictionary(Me.sortedKeyList(Me.sortedKeyList.Count - Me.memoryCacheCount - 1)).Cache()
- End If
- End SyncLock
-
- While Me.fileCacheProcList.Count > 0
- Me.fileCacheProcList.Dequeue().Invoke()
- End While
- End Sub
-
- Public Function Remove(ByVal item As System.Collections.Generic.KeyValuePair(Of String, Image)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).Remove
- Return Me.Remove(item.Key)
- End Function
-
- Public Function Remove(ByVal key As String) As Boolean Implements System.Collections.Generic.IDictionary(Of String, Image).Remove
- SyncLock Me.lockObject
- Me.sortedKeyList.Remove(key)
- Me.innerDictionary(key).Dispose()
- Return Me.innerDictionary.Remove(key)
- End SyncLock
- End Function
-
- Default Public Property Item(ByVal key As String) As Image Implements System.Collections.Generic.IDictionary(Of String, Image).Item
- Get
- SyncLock Me.lockObject
- Me.sortedKeyList.Remove(key)
- Me.sortedKeyList.Add(key)
- If Me.sortedKeyList.Count > Me.memoryCacheCount Then
- Dim imgObj As CachedImage = Me.innerDictionary(Me.sortedKeyList(Me.sortedKeyList.Count - Me.memoryCacheCount - 1))
- If Not imgObj.Cached Then
- Me.fileCacheProcList.Enqueue(Sub()
- If Me.innerDictionary.ContainsValue(imgObj) Then
- imgObj.Cache()
- End If
- End Sub)
- End If
- End If
- Return Me.innerDictionary(key).Image
- End SyncLock
- End Get
- Set(ByVal value As Image)
- SyncLock Me.lockObject
- Me.sortedKeyList.Remove(key)
- Me.sortedKeyList.Add(key)
- If Me.sortedKeyList.Count > Me.memoryCacheCount Then
- Me.innerDictionary(Me.sortedKeyList(Me.sortedKeyList.Count - Me.memoryCacheCount - 1)).Cache()
- End If
- Me.innerDictionary(key).Dispose()
- Me.innerDictionary(key) = New CachedImage(value, Me.cacheDiractoryPath)
- End SyncLock
- End Set
- End Property
-
- Public Sub Clear() Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).Clear
- SyncLock Me.lockObject
- For Each value As CachedImage In Me.innerDictionary.Values
- value.Dispose()
- Next
-
- Me.innerDictionary.Clear()
- Me.sortedKeyList.Clear()
- End SyncLock
- End Sub
-
- Public Function Contains(ByVal item As System.Collections.Generic.KeyValuePair(Of String, Image)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).Contains
- SyncLock Me.lockObject
- Return Me.innerDictionary.ContainsKey(item.Key) AndAlso Me.innerDictionary(item.Key) Is item.Value
- End SyncLock
- End Function
-
- Public Sub CopyTo(ByVal array() As System.Collections.Generic.KeyValuePair(Of String, Image), ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).CopyTo
- SyncLock Me.lockObject
- Dim index As Integer = arrayIndex
- For Each Item As KeyValuePair(Of String, CachedImage) In Me.innerDictionary
- If array.Length - 1 < index Then
- Exit For
- End If
-
- array(index) = New KeyValuePair(Of String, Image)(Item.Key, Item.Value.Image)
- index += 1
- Next
- End SyncLock
- End Sub
-
- Public ReadOnly Property Count As Integer Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).Count
- Get
- SyncLock Me.lockObject
- Return Me.innerDictionary.Count
- End SyncLock
- End Get
- End Property
-
- Public ReadOnly Property IsReadOnly As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of String, Image)).IsReadOnly
- Get
- Return False
- End Get
- End Property
-
- Public Function ContainsKey(ByVal key As String) As Boolean Implements System.Collections.Generic.IDictionary(Of String, Image).ContainsKey
- Return Me.innerDictionary.ContainsKey(key)
- End Function
-
- Public ReadOnly Property Keys As System.Collections.Generic.ICollection(Of String) Implements System.Collections.Generic.IDictionary(Of String, Image).Keys
- Get
- SyncLock Me.lockObject
- Return Me.innerDictionary.Keys
- End SyncLock
- End Get
- End Property
-
- Public Function TryGetValue(ByVal key As String, ByRef value As Image) As Boolean Implements System.Collections.Generic.IDictionary(Of String, Image).TryGetValue
- SyncLock Me.lockObject
- If Me.innerDictionary.ContainsKey(key) Then
- value = Me.innerDictionary(key).Image
- Return True
- Else
- Return False
- End If
- End SyncLock
- End Function
-
- Public ReadOnly Property Values As System.Collections.Generic.ICollection(Of Image) Implements System.Collections.Generic.IDictionary(Of String, Image).Values
- Get
- SyncLock Me.lockObject
- Dim imgList As New List(Of Image)(Me.memoryCacheCount)
- For Each value As CachedImage In Me.innerDictionary.Values
- imgList.Add(value.Image)
- Next
- Return imgList
- End SyncLock
- End Get
- End Property
-
- Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of System.Collections.Generic.KeyValuePair(Of String, Image)) Implements System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of String, Image)).GetEnumerator
- Throw New NotImplementedException()
- End Function
-
- Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
- Throw New NotImplementedException()
- End Function
-
- Public Sub Dispose() Implements IDisposable.Dispose
- SyncLock Me.lockObject
- For Each item As CachedImage In Me.innerDictionary.Values
- If item.img IsNot Nothing Then
- item.img.Dispose()
- End If
- Next
-
- Dim di As New DirectoryInfo(Me.cacheDiractoryPath)
- di.Delete(True)
- End SyncLock
- End Sub
-
- Public Function GetItemCopy(ByVal key As String) As Image
- SyncLock Me.lockObject
- Me.sortedKeyList.Remove(key)
- Me.sortedKeyList.Add(key)
- If Me.sortedKeyList.Count > Me.memoryCacheCount Then
- Dim imgObj As CachedImage = Me.innerDictionary(Me.sortedKeyList(Me.sortedKeyList.Count - Me.memoryCacheCount - 1))
- If Not imgObj.Cached Then
- Me.fileCacheProcList.Enqueue(Sub()
- If Me.innerDictionary.ContainsValue(imgObj) Then
- imgObj.Cache()
- End If
- End Sub)
- End If
- End If
-
- If Me.innerDictionary(key).Image IsNot Nothing Then
- Return New Bitmap(Me.innerDictionary(key).Image)
- Else
- Return Nothing
- End If
- End SyncLock
- End Function
-
- Private Class CachedImage
- Implements IDisposable
-
- Private ReadOnly lockObject As New Object()
-
- Public img As Image = Nothing
- Private tmpFilePath As String = Nothing
- Private cacheDirectoryPath As String
-
- Public Sub New(ByVal img As Image, ByVal cacheDirectory As String)
- SyncLock Me.lockObject
- Me.img = img
- Me.cacheDirectoryPath = cacheDirectory
- End SyncLock
- End Sub
-
- Public ReadOnly Property Image As Image
- Get
- SyncLock Me.lockObject
- If Me.img Is Nothing AndAlso Me.tmpFilePath IsNot Nothing Then
- Try
- Dim tempImage As Image = Nothing
- Using fs As New FileStream(Me.tmpFilePath, FileMode.Open, FileAccess.Read)
- tempImage = Bitmap.FromStream(fs)
- End Using
- Me.img = New Bitmap(tempImage)
- Catch ex As OutOfMemoryException
- Dim filePath As String = Path.Combine(Application.StartupPath, Path.GetFileName(Me.tmpFilePath))
- File.Copy(Me.tmpFilePath, filePath)
- Throw ex
- End Try
- End If
-
- Return Me.img
- End SyncLock
- End Get
- End Property
-
- Public Sub Cache()
- SyncLock Me.lockObject
- If Me.tmpFilePath Is Nothing AndAlso Me.img IsNot Nothing Then
- Dim tmpFile As String = Nothing
-
- Dim err As Boolean = False
- Do
- Try
- err = False
- tmpFile = Path.Combine(Me.cacheDirectoryPath, Path.GetRandomFileName().Remove(8, 1))
-
- Using fs As New FileStream(tmpFile, FileMode.CreateNew, FileAccess.Write)
- Me.img.Save(fs, Imaging.ImageFormat.Bmp)
- fs.Flush()
- End Using
- Catch ex As InvalidOperationException
- err = True
- Catch ex As IOException
- err = True
- Catch ex As Exception
- File.Delete(tmpFile)
- Me.tmpFilePath = Nothing
- Exit Sub
- End Try
- Loop While err
- Me.tmpFilePath = tmpFile
- End If
- If Me.img IsNot Nothing Then
- Me.img.Dispose()
- Me.img = Nothing
- End If
- End SyncLock
- End Sub
-
- Public ReadOnly Property Cached As Boolean
- Get
- SyncLock Me.lockObject
- Return Me.tmpFilePath IsNot Nothing
- End SyncLock
- End Get
- End Property
-
- Public Sub Dispose() Implements IDisposable.Dispose
- SyncLock Me.lockObject
- If Me.img IsNot Nothing Then
- Me.img.Dispose()
- End If
-
- If Me.tmpFilePath IsNot Nothing Then
- File.Delete(Me.tmpFilePath)
- End If
- End SyncLock
- End Sub
- End Class
-End Class
\ No newline at end of file
fDialog.Dispose()
UrlDialog.Dispose()
_spaceKeyCanceler.Dispose()
+ If TIconDic IsNot Nothing AndAlso TIconDic.Keys.Count > 0 Then
+ For Each value As Image In TIconDic.Values
+ value.Dispose()
+ Next
+ End If
If NIconAt IsNot Nothing Then NIconAt.Dispose()
If NIconAtRed IsNot Nothing Then NIconAtRed.Dispose()
If NIconAtSmoke IsNot Nothing Then NIconAtSmoke.Dispose()
If _bwFollower IsNot Nothing Then
_bwFollower.Dispose()
End If
- DirectCast(TIconDic, IDisposable).Dispose()
End Sub
Private Sub LoadIcon(ByRef IconInstance As Icon, ByVal FileName As String)
End If
'アイコンリスト作成
- TIconDic = New ImageCacheDictionary(Path.Combine(Path.GetTempPath(), "Tween" + Environment.TickCount.ToString()), 3000)
+ TIconDic = New Dictionary(Of String, Image)
tw.DetailIcon = TIconDic
AddHandler _listCustom.CacheVirtualItems, AddressOf MyList_CacheVirtualItems
AddHandler _listCustom.RetrieveVirtualItem, AddressOf MyList_RetrieveVirtualItem
AddHandler _listCustom.DrawSubItem, AddressOf MyList_DrawSubItem
- AddHandler _listCustom.Scrolled, AddressOf MyList_Scrolled
InitColumnText()
_colHd1.Text = ColumnText(0)
RemoveHandler _listCustom.CacheVirtualItems, AddressOf MyList_CacheVirtualItems
RemoveHandler _listCustom.RetrieveVirtualItem, AddressOf MyList_RetrieveVirtualItem
RemoveHandler _listCustom.DrawSubItem, AddressOf MyList_DrawSubItem
- RemoveHandler _listCustom.Scrolled, AddressOf MyList_Scrolled
TabDialog.RemoveTab(TabName)
Catch ex As Exception
'不正な要求に対する間に合わせの応答
Dim sitem() As String = {"", "", "", "", "", "", "", ""}
- e.Item = New ImageListViewItem(sitem, "")
+ e.Item = New ListViewItem(sitem, "")
End Try
End If
End Sub
If Post.IsMark Then mk += "♪"
If Post.IsProtect Then mk += "Ю"
If Post.InReplyToId > 0 Then mk += "⇒"
- Dim itm As ImageListViewItem
+ Dim itm As ListViewItem
If Post.RetweetedId = 0 Then
Dim sitem() As String = {"", Post.Nickname, Post.Data, Post.PDate.ToString(SettingDialog.DateTimeFormat), Post.Name, "", mk, Post.Source}
- itm = New ImageListViewItem(sitem, Post.ImageUrl)
+ itm = New ListViewItem(sitem, Post.ImageUrl)
Else
Dim sitem() As String = {"", Post.Nickname, Post.Data, Post.PDate.ToString(SettingDialog.DateTimeFormat), Post.Name + "(RT:" + Post.RetweetedBy + ")", "", mk, Post.Source}
- itm = New ImageListViewItem(sitem, Post.ImageUrl)
- End If
-
- If tw.DetailIcon.ContainsKey(Post.ImageUrl) Then
- itm.Image = DirectCast(tw.DetailIcon, ImageCacheDictionary).GetItemCopy(Post.ImageUrl)
+ itm = New ListViewItem(sitem, Post.ImageUrl)
End If
Dim read As Boolean = Post.IsRead
End Sub
Private Sub DrawListViewItemIcon(ByVal e As DrawListViewSubItemEventArgs)
- Dim item As ImageListViewItem = DirectCast(e.Item, ImageListViewItem)
-
- If item.Image IsNot Nothing Then
+ If Not String.IsNullOrEmpty(e.Item.ImageKey) AndAlso Me.TIconDic.ContainsKey(e.Item.ImageKey) Then
'e.Bounds.Leftが常に0を指すから自前で計算
- Dim itemRect As Rectangle = item.Bounds
+ Dim itemRect As Rectangle = e.Item.Bounds
itemRect.Width = e.Item.ListView.Columns(0).Width
For Each clm As ColumnHeader In e.Item.ListView.Columns
End If
Next
- Dim iconRect As Rectangle = Rectangle.Intersect(item.GetBounds(ItemBoundsPortion.Icon), itemRect)
+ Dim iconRect As Rectangle = Rectangle.Intersect(e.Item.GetBounds(ItemBoundsPortion.Icon), itemRect)
If iconRect.Width > 0 Then
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High
- e.Graphics.DrawImage(item.Image, iconRect)
+ e.Graphics.DrawImage(Me.TIconDic(e.Item.ImageKey), iconRect)
End If
End If
End Sub
'End If
End Sub
- Private Sub MyList_Scrolled(ByVal sender As Object, ByVal e As EventArgs)
- Dim listView As DetailsListView = DirectCast(sender, DetailsListView)
- listView.Refresh()
- End Sub
-
Public Function WebBrowser_GetSelectionText(ByRef ComponentInstance As WebBrowser) As String
'発言詳細で「選択文字列をコピー」を行う
'WebBrowserコンポーネントのインスタンスを渡す