mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-02-04 12:47:48 +01:00
ファイルヘッダからJPEGかどうか判断する際に先頭4バイトではなく3バイトだけ確認する
This commit is contained in:
parent
2d5f20a4f5
commit
84410e701a
@ -114,12 +114,18 @@ class ActPost : AppCompatActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val imageHeaderList = arrayOf(
|
private val imageHeaderList = arrayOf(
|
||||||
Pair("image/jpeg", intArrayOf(0xff, 0xd8, 0xff, 0xe0).toByteArray()),
|
Pair(
|
||||||
|
"image/jpeg",
|
||||||
|
intArrayOf(0xff, 0xd8, 0xff ).toByteArray()
|
||||||
|
),
|
||||||
Pair(
|
Pair(
|
||||||
"image/png",
|
"image/png",
|
||||||
intArrayOf(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A).toByteArray()
|
intArrayOf(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A).toByteArray()
|
||||||
),
|
),
|
||||||
Pair("image/gif", charArrayOf('G', 'I', 'F').toByteArray())
|
Pair(
|
||||||
|
"image/gif",
|
||||||
|
charArrayOf('G', 'I', 'F').toLowerByteArray()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun checkImageHeaderList(contentResolver : ContentResolver, uri : Uri) : String? {
|
private fun checkImageHeaderList(contentResolver : ContentResolver, uri : Uri) : String? {
|
||||||
@ -1962,7 +1968,7 @@ class ActPost : AppCompatActivity(),
|
|||||||
opener.open().use { inData ->
|
opener.open().use { inData ->
|
||||||
val tmp = ByteArray(4096)
|
val tmp = ByteArray(4096)
|
||||||
while(true) {
|
while(true) {
|
||||||
val r = inData.read(tmp, 0, tmp.size)
|
val r = inData.read(tmp, 0, tmp.size)
|
||||||
if(r <= 0) break
|
if(r <= 0) break
|
||||||
sink.write(tmp, 0, r)
|
sink.write(tmp, 0, r)
|
||||||
}
|
}
|
||||||
@ -2394,12 +2400,12 @@ class ActPost : AppCompatActivity(),
|
|||||||
json.put(DRAFT_POLL_TYPE, spEnquete.selectedItemPosition.toPollTypeString())
|
json.put(DRAFT_POLL_TYPE, spEnquete.selectedItemPosition.toPollTypeString())
|
||||||
|
|
||||||
json.put(DRAFT_POLL_MULTIPLE, cbMultipleChoice.isChecked)
|
json.put(DRAFT_POLL_MULTIPLE, cbMultipleChoice.isChecked)
|
||||||
json.put(DRAFT_POLL_HIDE_TOTALS, cbHideTotals.isChecked )
|
json.put(DRAFT_POLL_HIDE_TOTALS, cbHideTotals.isChecked)
|
||||||
json.put(DRAFT_POLL_EXPIRE_DAY,etExpireDays.text.toString())
|
json.put(DRAFT_POLL_EXPIRE_DAY, etExpireDays.text.toString())
|
||||||
json.put(DRAFT_POLL_EXPIRE_HOUR,etExpireHours.text.toString())
|
json.put(DRAFT_POLL_EXPIRE_HOUR, etExpireHours.text.toString())
|
||||||
json.put(DRAFT_POLL_EXPIRE_MINUTE,etExpireMinutes.text.toString())
|
json.put(DRAFT_POLL_EXPIRE_MINUTE, etExpireMinutes.text.toString())
|
||||||
|
|
||||||
json.put(DRAFT_ENQUETE_ITEMS, JSONArray().apply{
|
json.put(DRAFT_ENQUETE_ITEMS, JSONArray().apply {
|
||||||
for(s in str_choice) {
|
for(s in str_choice) {
|
||||||
put(s)
|
put(s)
|
||||||
}
|
}
|
||||||
@ -2419,13 +2425,13 @@ class ActPost : AppCompatActivity(),
|
|||||||
"friendsNico" -> 2
|
"friendsNico" -> 2
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Int?.toPollTypeString() = when(this) {
|
private fun Int?.toPollTypeString() = when(this) {
|
||||||
1->"mastodon"
|
1 -> "mastodon"
|
||||||
2->"friendsNico"
|
2 -> "friendsNico"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun openDraftPicker() {
|
private fun openDraftPicker() {
|
||||||
|
|
||||||
DlgDraftPicker().open(this) { draft -> restoreDraft(draft) }
|
DlgDraftPicker().open(this) { draft -> restoreDraft(draft) }
|
||||||
@ -2565,21 +2571,20 @@ class ActPost : AppCompatActivity(),
|
|||||||
|
|
||||||
cbQuoteRenote.isChecked = draft.optBoolean(DRAFT_QUOTED_RENOTE)
|
cbQuoteRenote.isChecked = draft.optBoolean(DRAFT_QUOTED_RENOTE)
|
||||||
|
|
||||||
val sv = draft.optString(DRAFT_POLL_TYPE,null)
|
val sv = draft.optString(DRAFT_POLL_TYPE, null)
|
||||||
if(sv!=null){
|
if(sv != null) {
|
||||||
spEnquete.setSelection( sv.toPollTypeIndex() )
|
spEnquete.setSelection(sv.toPollTypeIndex())
|
||||||
}else{
|
} else {
|
||||||
// old draft
|
// old draft
|
||||||
val bv = draft.optBoolean(DRAFT_IS_ENQUETE, false)
|
val bv = draft.optBoolean(DRAFT_IS_ENQUETE, false)
|
||||||
spEnquete.setSelection( if(bv) 2 else 0)
|
spEnquete.setSelection(if(bv) 2 else 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
cbMultipleChoice.isChecked = draft.optBoolean(DRAFT_POLL_MULTIPLE)
|
cbMultipleChoice.isChecked = draft.optBoolean(DRAFT_POLL_MULTIPLE)
|
||||||
cbHideTotals.isChecked = draft.optBoolean(DRAFT_POLL_HIDE_TOTALS)
|
cbHideTotals.isChecked = draft.optBoolean(DRAFT_POLL_HIDE_TOTALS)
|
||||||
etExpireDays.setText( draft.optString(DRAFT_POLL_EXPIRE_DAY,"1"))
|
etExpireDays.setText(draft.optString(DRAFT_POLL_EXPIRE_DAY, "1"))
|
||||||
etExpireHours.setText( draft.optString(DRAFT_POLL_EXPIRE_HOUR,""))
|
etExpireHours.setText(draft.optString(DRAFT_POLL_EXPIRE_HOUR, ""))
|
||||||
etExpireMinutes.setText( draft.optString(DRAFT_POLL_EXPIRE_MINUTE,""))
|
etExpireMinutes.setText(draft.optString(DRAFT_POLL_EXPIRE_MINUTE, ""))
|
||||||
|
|
||||||
|
|
||||||
val array = draft.optJSONArray(DRAFT_ENQUETE_ITEMS)
|
val array = draft.optJSONArray(DRAFT_ENQUETE_ITEMS)
|
||||||
if(array != null) {
|
if(array != null) {
|
||||||
|
@ -77,7 +77,7 @@ fun IntArray.toByteArray() : ByteArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 各要素の下位8ビットを使ってバイト配列を作る
|
// 各要素の下位8ビットを使ってバイト配列を作る
|
||||||
fun CharArray.toByteArray() : ByteArray {
|
fun CharArray.toLowerByteArray() : ByteArray {
|
||||||
val dst = ByteArray(this.size)
|
val dst = ByteArray(this.size)
|
||||||
for(i in 0 until this.size) {
|
for(i in 0 until this.size) {
|
||||||
dst[i] = this[i].toByte()
|
dst[i] = this[i].toByte()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user