Skip to content

Commit

Permalink
Revert "Attempted to fix issues with creating config with non latin c…
Browse files Browse the repository at this point in the history
…haracters in username"

Sadly this didn't help the issue and is causing other issues
Revering it for now, might look more into it later
Other changes have made --portable more reliable on systems that otherwise would have problems
This reverts commit 93ca1c8.
  • Loading branch information
Cruor committed Nov 1, 2023
1 parent 599cc2e commit 75cde13
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 72 deletions.
2 changes: 1 addition & 1 deletion src/file_locations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function fileLocations.getStorageDir()
local linuxFolderName = fileLocations.loennLinuxFolderName

if userOS == "Windows" then
return filesystem.joinpath(utils.getenv("LocalAppData"), simpleFolderName)
return filesystem.joinpath(os.getenv("LocalAppData"), simpleFolderName)

elseif userOS == "Linux" then
local xdgConfig = os.getenv("XDG_CONFIG_HOME")
Expand Down
67 changes: 0 additions & 67 deletions src/utils/filesystem.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local lfs = require("lib.lfs_ffi")
local ffi = require("ffi")
local nfd = require("nfd")
local physfs = require("lib.physfs")
local requireUtils = require("utils.require")
Expand Down Expand Up @@ -479,70 +478,4 @@ function filesystem.unzip(zipPath, outputDir)
love.filesystem.unmount("temp")
end

if osUtils.getOS() ~= "Windows" then
local function identity(value)
return value
end

filesystem.codepageUtf8ToSys = identity
filesystem.codepageSysToUtf8 = identity

else
ffi.cdef[[
int MultiByteToWideChar(
unsigned int CodePage,
int dwFlags,
char* lpMultiByteStr,
int cbMultiByte,
wchar_t* lpWideCharStr,
int cchWideChar
);
int WideCharToMultiByte(
unsigned int CodePage,
int dwFlags,
wchar_t* lpWideCharStr,
int cchWideChar,
char* lpMultiByteStr,
int cbMultiByte,
char* lpDefaultChar,
bool* lpUsedDefaultChar
);
]]

local codepageSys = 0
local codepageUtf8 = 65001

local function convert(from, to, orig)
local length = #orig + 1
local valueC = ffi.new("char[?]", length)
ffi.copy(valueC, orig)
valueC[#orig] = 0

-- char from -> wchar_t
local size = ffi.C.MultiByteToWideChar(from, 0, valueC, length, nil, 0)
assert(size ~= 0)
local valueW = ffi.new("wchar_t[?]", size)
length = ffi.C.MultiByteToWideChar(from, 0, valueC, length, valueW, size)
assert(size == length)

-- wchar_t -> char to
length = ffi.C.WideCharToMultiByte(to, 0, valueW, size, nil, 0, nil, nil)
assert(length ~= 0)
valueC = ffi.new("char[?]", length + 1)
length = ffi.C.WideCharToMultiByte(to, 0, valueW, size, valueC, length, nil, nil)
assert(length == size)
valueC[length + 1] = 0

return ffi.string(valueC)
end

function filesystem.codepageUtf8ToSys(value)
return convert(codepageUtf8, codepageSys, value)
end

function filesystem.codepageSysToUtf8(value)
return convert(codepageSys, codepageUtf8, value)
end
end

return filesystem
4 changes: 0 additions & 4 deletions src/utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,6 @@ for k, v <- filesystem do
utils[k] = v
end

function utils.getenv(key)
return filesystem.codepageSysToUtf8(os.getenv(key))
end

-- Add filesystem specific helper methods
local osFilename = utils.getOS():lower():gsub(" ", "_")
local hasOSHelper, osHelper = requireUtils.tryrequire("utils.system." .. osFilename)
Expand Down

0 comments on commit 75cde13

Please sign in to comment.