-
Автор темы
- #1
Не видит файлы, в чем проблема?
C++:
ffi.cdef[[
int CopyFileA(const char* lpExistingFileName, const char* lpNewFileName, int bFailIfExists);
bool CreateDirectoryA(const char *path, void *lpSecurityAttributes);
]]
local path, index, files = "./nix/vcplayer", 0, {}
ffi.C.CreateDirectoryA(path, nil)
for line in io.popen("dir \"" .. path .. "\" /a /b", "r"):lines() do
if string.find(line, ".wav") then
files[index] = line index = index + 1
end
end
if #files == 0 then
client.notify("no sounds were found.");
return
end
local misc_files = ui.add_combo_box("files", "misc_files", files, 0)
local misc_playfile = ui.add_check_box("play", "misc_playfile", false)
local misc_stopfile = ui.add_check_box("stop", "misc_stopfile", false)
local voice_inputfromfile = se.get_convar("voice_inputfromfile")
local voice_loopback = se.get_convar("voice_loopback")
local estimated_end_time = -1
local function estimate_length(filename)
local file = io.open(filename)
local estimated_time = file:seek("end") / 44100
file:close()
return estimated_time
end
local function replace_file(with, at)
ffi.C.CopyFileA(with, at, 0)
end
local function play_file(filename)
replace_file(filename, "voice_input.wav")
voice_inputfromfile:set_int(1)
engine.execute_client_cmd("+voicerecord")
voice_loopback:set_int(1)
estimated_end_time = globalvars.get_current_time() + estimate_length("voice_input.wav")
end
local function on_paint()
if misc_playfile:get_value() == true then
play_file(path .. "\\" .. files[misc_files:get_value()])
misc_playfile:set_value(false)
end
if misc_stopfile:get_value() == true then
estimated_end_time = 0
misc_stopfile:set_value(false)
end
if estimated_end_time ~= -1 and globalvars.get_current_time() > estimated_end_time then
voice_inputfromfile:set_int(0)
engine.execute_client_cmd("-voicerecord")
voice_loopback:set_int(0)
os.remove("./voice_input.wav")
estimated_end_time = -1
end
end
client.register_callback("paint", on_paint)