Implemented right-click menu to remove or download loot (files/screenshots).
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import strutils, system, terminal, tiny_sqlite, pixie
|
||||
import stb_image/write as stbiw
|
||||
import system, terminal, tiny_sqlite
|
||||
import ../core/logger
|
||||
import ../../common/[types, utils]
|
||||
import ../../common/types
|
||||
|
||||
proc dbStoreLoot*(cq: Conquest, loot: LootItem): bool =
|
||||
try:
|
||||
@@ -19,31 +18,6 @@ proc dbStoreLoot*(cq: Conquest, loot: LootItem): bool =
|
||||
|
||||
return true
|
||||
|
||||
proc createThumbnail*(data: string, maxWidth: int = 1024, quality: int = 90): string =
|
||||
let img: Image = decodeImage(data)
|
||||
|
||||
let aspectRatio = img.height.float / img.width.float
|
||||
let
|
||||
width = min(maxWidth, img.width)
|
||||
height = int(width.float * aspectRatio)
|
||||
|
||||
# Resize image
|
||||
let thumbnail = img.resize(width, height)
|
||||
|
||||
# Convert to JPEG image for smaller file size
|
||||
var rgbaData = newSeq[byte](width * height * 4)
|
||||
var i = 0
|
||||
for y in 0..<height:
|
||||
for x in 0..<width:
|
||||
let color = thumbnail[x, y]
|
||||
rgbaData[i] = color.r
|
||||
rgbaData[i + 1] = color.g
|
||||
rgbaData[i + 2] = color.b
|
||||
rgbaData[i + 3] = color.a
|
||||
i += 4
|
||||
|
||||
return Bytes.toString(stbiw.writeJPG(width, height, 4, rgbaData, quality))
|
||||
|
||||
proc dbGetLoot*(cq: Conquest): seq[LootItem] =
|
||||
var loot: seq[LootItem] = @[]
|
||||
|
||||
@@ -53,7 +27,7 @@ proc dbGetLoot*(cq: Conquest): seq[LootItem] =
|
||||
for row in conquestDb.iterate("SELECT lootId, itemType, agentId, host, path, timestamp, size FROM loot;"):
|
||||
let (lootId, itemType, agentId, host, path, timestamp, size) = row.unpack((string, int, string, string, string, int64, int))
|
||||
|
||||
var l = LootItem(
|
||||
let l = LootItem(
|
||||
lootId: lootId,
|
||||
itemType: cast[LootItemType](itemType),
|
||||
agentId: agentId,
|
||||
@@ -63,15 +37,40 @@ proc dbGetLoot*(cq: Conquest): seq[LootItem] =
|
||||
size: size
|
||||
)
|
||||
|
||||
if l.itemType == SCREENSHOT:
|
||||
l.data = createThumbnail(readFile(path)) # Create a smaller thumbnail version of the screenshot for better transportability
|
||||
elif l.itemType == DOWNLOAD:
|
||||
l.data = readFile(path) # Read downloaded file
|
||||
|
||||
loot.add(l)
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.error(getCurrentExceptionMsg())
|
||||
|
||||
return loot
|
||||
return loot
|
||||
|
||||
proc dbGetLootById*(cq: Conquest, lootId: string): LootItem =
|
||||
try:
|
||||
let conquestDb = openDatabase(cq.dbPath, mode=dbReadWrite)
|
||||
for row in conquestDb.iterate("SELECT lootId, itemType, agentId, host, path, timestamp, size FROM loot WHERE lootId = ?;", lootId):
|
||||
let (id, itemType, agentId, host, path, timestamp, size) = row.unpack((string, int, string, string, string, int64, int))
|
||||
result = LootItem(
|
||||
lootId: id,
|
||||
itemType: cast[LootItemType](itemType),
|
||||
agentId: agentId,
|
||||
host: host,
|
||||
path: path,
|
||||
timestamp: timestamp,
|
||||
size: size
|
||||
)
|
||||
conquestDb.close()
|
||||
except:
|
||||
cq.error(getCurrentExceptionMsg())
|
||||
|
||||
proc dbDeleteLootById*(cq: Conquest, lootId: string): bool =
|
||||
try:
|
||||
let conquestDb = openDatabase(cq.dbPath, mode=dbReadWrite)
|
||||
|
||||
conquestDb.exec("DELETE FROM loot WHERE lootId = ?", lootId)
|
||||
|
||||
conquestDb.close()
|
||||
except:
|
||||
return false
|
||||
|
||||
return true
|
||||
Reference in New Issue
Block a user