|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sat Jan 21, 2017 11:51 pm Post subject: |
|
|
Thank Corroder, find some error in my functions from your example, hopefully fixed now.
1. '\' inside "" or '' quoted string need to be escaped.
2. test "d:test.txt" on my machine, where d is a hard disk,
test.txt does not exist in d: (current directory of lua, ie. the os see d: as relative path) at the moment,
the notepad should open a new edit called "test.txt"
3. test "e:test.txt" on my machine, where e is a cd-rom without cd,
notepad show "device is not ready" and open an edit called "untitled"
bye~
_________________
- Retarded. |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 22, 2017 4:52 am Post subject: |
|
|
@Panraven bo,
I've combined Zanzer script and your :
Code: | -- sample template format: extension -> app cmd, app param
defaultExt2App = {
txt = {'notepad', '"^F"'},
bat = {'cmd','/c "^F"'},
cmd = {'cmd','/c "^F"'},
[''] = {'explorer','/select,"^F"'}, -- handle if extension is empty string
}
-- added double quote to handle filename with space etc.
function fileSplit(f)--return dir,name,ext,original_input
return string.match(f, "(.-)([^\\]-([^\\%.]+))$")
end
function file2RunApp(f,Ext2app)
local ext2app = {}
for k,v in pairs(Ext2app or {}) do if not ext2app[k] then ext2app[k]=v end end
for k,v in pairs(defaultExt2App or {}) do if not ext2app[k] then ext2app[k]=v end end
local dir,name,ext = fileSplit(f)
local appParam = ext2app[ext:lower()]
if not appParam then return nil,'Application Not known: '..tostring(file)end
local cmd,param = appParam[1],appParam[2]
local ctx = cmd and {D = dir, N = name, E = ext, F = f }
cmd = cmd and cmd:gsub("%^([DNEF])",ctx)
param = param and param:gsub("%^([DNEF])",ctx) or nil
return cmd and pcall(shellExecute, cmd, param)
end
--- test
f = "E:/corroder/testdata/MakeFileLua.txt"
file2RunApp(f)
Conclusion result :
1. f = "e:/corroder/testdata/MakeFileLua.txt" --> file open correctly (e: or E: give same result)
2. f = "e:corroder/testdata/MakeFileLua.txt" --> file open correctly
3. f = "e:other.txt --> notepad open while prompted ask to creating new txt file (other.txt is not exist)
4. f = "e:/newdir/test.txt --> prompted directory not exist and return (newdir is not exist on my machine)
5. f = "e:\corroder\testdata\MakeFileLua.txt --> syntax error because "/" need escape
|
So, last problem is how fix it that we allow use "/" instead "\" ?. As windows directory or path structure "Dir Letter\Dir Name\Path Name \ Sub Path ... \ Filename + extension
Same like this function to get file name extension :
Code: | function fileGetName(f)
local str = f
local temp = ""
local result = ""
for i = str:len(), 1, -1 do
if str:sub(i,i) ~= "/" then ----- Why can't change to "\", give error unfinish "" or error "if"...without "then"
temp = temp..str:sub(i,i)
else
break
end
end
for j = temp:len(), 1, -1 do
result = result..temp:sub(j,j)
end
return result
end |
Regards..
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jan 22, 2017 7:39 am Post subject: |
|
|
Code: | function fileSplit(f)--return dir,name,ext,original_input
return string.match(f, "(.-)([^\\/]-([^\\/%.]+))$")
end |
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 22, 2017 9:12 am Post subject: |
|
|
Zanzer sir,
Code: | return string.match(f, "(.-)([^\\/]-([^\\/%.]+))$")
-- with
f = "E:\test.txt" --> The filename, dir name, or vol label syntax is incorrect
-- with
f = "E:test.txt" --> Notepad open (and creating new txt file if test.txt not exist)
-- with
f = "E:\\test.txt" --> Notepad open (and creating new txt file if test.txt not exist)
|
Still not allow use "slah"
Regards
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jan 22, 2017 9:44 am Post subject: |
|
|
The problem is with your string. \t is a tab character.
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 22, 2017 8:18 pm Post subject: |
|
|
Yes, Zanzer sir
of course Lua does not like those unescaped backslash at all. If I am fine with "\" then I need delimit my string with [[ and ]]
Code: | f = [[E:\test.txt]] |
will work fine
Regards
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|