From 07694cdb1fb75d0b6347208f645125a61269a140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 5 Sep 2014 11:41:39 +0200 Subject: [PATCH 1/2] Added sanity check in player inventory layouting code for GUIs, fixes #541. --- src/main/scala/li/cil/oc/common/container/Player.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/container/Player.scala b/src/main/scala/li/cil/oc/common/container/Player.scala index 88ab357cf..b9b9a966e 100644 --- a/src/main/scala/li/cil/oc/common/container/Player.scala +++ b/src/main/scala/li/cil/oc/common/container/Player.scala @@ -12,10 +12,10 @@ import scala.collection.convert.WrapAsScala._ abstract class Player(val playerInventory: InventoryPlayer, val otherInventory: IInventory) extends Container { /** Number of player inventory slots to display horizontally. */ - protected val playerInventorySizeX = InventoryPlayer.getHotbarSize + protected val playerInventorySizeX = math.min(9, InventoryPlayer.getHotbarSize) /** Subtract four for armor slots. */ - protected val playerInventorySizeY = (playerInventory.getSizeInventory - 4) / playerInventorySizeX + protected val playerInventorySizeY = math.min(4, (playerInventory.getSizeInventory - 4) / playerInventorySizeX) /** Render size of slots (width and height). */ protected val slotSize = 18 @@ -116,7 +116,7 @@ abstract class Player(val playerInventory: InventoryPlayer, val otherInventory: // Show the quick slot bar below the internal inventory. val quickBarSpacing = 4 - for (index <- 0 until InventoryPlayer.getHotbarSize) { + for (index <- 0 until playerInventorySizeX) { val x = left + index * slotSize val y = top + slotSize * (playerInventorySizeY - 1) + quickBarSpacing addSlotToContainer(new Slot(playerInventory, index, x, y)) From 827f6ad4d8a2a24f89c44ee3e1588022df027cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 5 Sep 2014 12:03:18 +0200 Subject: [PATCH 2/2] Made edit create a temporary backup of the file being edited when saving, to avoid losing data when erroring while saving (e.g. out of memory). Closes #534. --- .../assets/opencomputers/loot/OpenOS/bin/edit.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua index 4cedd12d4..7c9d540ed 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua @@ -445,6 +445,17 @@ local keyBindHandlers = { save = function() if readonly then return end local new = not fs.exists(filename) + local backup + if not new then + backup = filename .. "~" + for i = 1, math.huge do + if not fs.exists(backup) then + break + end + backup = filename .. "~" .. i + end + fs.copy(filename, backup) + end local f, reason = io.open(filename, "w") if f then local chars, firstLine = 0, true @@ -467,6 +478,9 @@ local keyBindHandlers = { else setStatus(reason) end + if not new then + fs.remove(backup) + end end, close = function() -- TODO ask to save if changed