
Documentation of methods:All methods return as first value an exception that will be nil in case of success or a text explaining the exception in case of failure.
Load the module by using require.
Make sure you put DropBox.dll in your scripts path and the others in the exe path (cd_root)
require("DropBox")
err = DropBox.Setup(token)
This function is needed to be called after anithing else, pass to it the oauth token generated on dropbox developer app.
err, id, country, email, name, avatar_url = DropBox.GetAccount()
This function returns info about the account.
err, files, count = DropBox.GetFolder(folder_path)
This function returns a table of files on some path. for home path use an empty string "" instead a slash "/".
The files table returned should have members string "Name", bool "isFolder", string "Path" for example, files[1].Name
err = DropBox.Delete(file)
This function deletes a file from dropbox
err = DropBox.Upload(local_file, remote_file)
This function uploads a local file to dropbox
err = DropBox.Download(remote_file, local_file)
This function downloads a file from dropbox to a local file
err = DropBox.CreateFolder(path)
This function created a folder on dropbox
err, link = DropBox.GetTempLink(path)
This function return a link for a dropbox file that can be downloaded.
err = DropBox.Rename(path_from, path_to)
This function renames a file or folder on dropbox
err = DropBox.Copy(path_source, path_dest)
This function copies a file on dropbox
err, files, count = DropBox.Search(path, search_query)
This function has same return as GetFolder, but allows to search by some text pattern.

https://mega.nz/#!QcZhjbzT!uNQvDMeQThCw ... SKFB2KNbZM
[DllExport(CallingConvention = CallingConvention.Cdecl)]
public static int luaopen_DropBox(IntPtr ls)
{
L = ls;
Lua.register_lua_function(L, "DropBox", "Setup", lua_dropbox_setup);
Lua.register_lua_function(L, "DropBox", "GetAccount", lua_dropbox_getaccount);
Lua.register_lua_function(L, "DropBox", "GetFolder", lua_dropbox_getfolder);
Lua.register_lua_function(L, "DropBox", "Delete", lua_dropbox_delete);
Lua.register_lua_function(L, "DropBox", "Upload", lua_dropbox_upload);
Lua.register_lua_function(L, "DropBox", "Download", lua_dropbox_download);
Lua.register_lua_function(L, "DropBox", "CreateFolder", lua_dropbox_createfolder);
Lua.register_lua_function(L, "DropBox", "GetTempLink", lua_dropbox_gettemplink);
Lua.register_lua_function(L, "DropBox", "Rename", lua_dropbox_rename);
Lua.register_lua_function(L, "DropBox", "Copy", lua_dropbox_copy);
Lua.register_lua_function(L, "DropBox", "Search", lua_dropbox_search);
return 0;
}
public static int lua_dropbox_setup(IntPtr ls)
{
string err = null;
try
{
dropbox = new DropboxClient(Lua.lua_tostring(L, 1));
}
catch (Exception e)
{
err = e.ToString();
}
Lua.lua_pushstring(L, err);
return 1;
}
private static bool CheckDropBox()
{
if (dropbox == null) return false;
return true;
}
public static int lua_dropbox_getaccount(IntPtr ls)
{
string exception = null;
string[] ret = new string[] { null, null, null, null, null };
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
FullAccount userdata = dropbox.Users.GetCurrentAccountAsync().Result;
ret[0] = userdata.AccountId;
ret[1] = userdata.Country;
ret[2] = userdata.Email;
ret[3] = userdata.Name.DisplayName;
ret[4] = userdata.ProfilePhotoUrl;
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
Lua.lua_pushstring(L, ret[0]);
Lua.lua_pushstring(L, ret[1]);
Lua.lua_pushstring(L, ret[2]);
Lua.lua_pushstring(L, ret[3]);
Lua.lua_pushstring(L, ret[4]);
return 6;
}
public static int lua_dropbox_getfolder(IntPtr ls)
{
string exception = null;
if (!CheckDropBox())
{
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
Lua.lua_pushstring(L, exception);
Lua.lua_pushnil(L);
Lua.lua_pushnil(L);
return 3;
}
ListFolderResult folderdata = null;
try
{
folderdata = dropbox.Files.ListFolderAsync(Lua.lua_tostring(L, 1)).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
if (folderdata != null && folderdata.Entries.Count == 0 && exception == null)
{
exception = "No files found";
}
Lua.lua_pushstring(L, exception);
Lua.lua_newtable(L);
int filecount = 0;
foreach (Metadata metadata in folderdata.Entries)
{
if (metadata.IsDeleted) continue;
Lua.lua_newtable(L);
Lua.lua_pushstring(L, metadata.Name);
Lua.lua_setfield(L, -2, "Name");
Lua.lua_pushstring(L, metadata.PathDisplay);
Lua.lua_setfield(L, -2, "Path");
Lua.lua_pushboolean(L, metadata.IsFolder);
Lua.lua_setfield(L, -2, "isFolder");
filecount++;
Lua.lua_rawseti(L, -2, filecount);
}
Lua.lua_pushnumber(L, filecount);
return 3;
}
private static int lua_dropbox_delete(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
dropbox.Files.DeleteAsync(Lua.lua_tostring(L, 1));
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_upload(IntPtr lua_State)
{
string exception = null;
string local_file = Lua.lua_tostring(L, 1);
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
if (!File.Exists(local_file))
exception = "The local file doesn't exists";
else
{
try
{
Stream fs = File.OpenRead(local_file);
dropbox.Files.UploadAsync(Lua.lua_tostring(L, 2), null, false, null, false, fs);
fs.Close();
}
catch (Exception e)
{
exception = e.ToString();
}
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_download(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
var fm = dropbox.Files.DownloadAsync(Lua.lua_tostring(L, 1), null).Result;
Stream strm = fm.GetContentAsStreamAsync().Result;
using (var fileStream = File.Create(Lua.lua_tostring(L, 2)))
{
strm.CopyTo(fileStream);
}
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_createfolder(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
dropbox.Files.CreateFolderAsync(Lua.lua_tostring(L, 1), true);
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_gettemplink(IntPtr lua_State)
{
string ret = null;
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
var filedata = dropbox.Files.GetTemporaryLinkAsync(Lua.lua_tostring(L, 1)).Result;
ret = filedata.Link;
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
Lua.lua_pushstring(L, ret);
return 2;
}
private static int lua_dropbox_rename(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
var movefile = dropbox.Files.MoveAsync(Lua.lua_tostring(L, 1), Lua.lua_tostring(L, 2), true, true).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_copy(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
else
{
try
{
var movefile = dropbox.Files.CopyAsync(Lua.lua_tostring(L, 1), Lua.lua_tostring(L, 2), true, true).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_pushstring(L, exception);
return 1;
}
private static int lua_dropbox_search(IntPtr lua_State)
{
string exception = null;
if (!CheckDropBox())
{
exception = "Error in DropBox. No OAuth logon. Please use DropBox.Setup(token)";
Lua.lua_pushstring(L, exception);
Lua.lua_pushnil(L);
Lua.lua_pushnil(L);
return 3;
}
SearchResult searchresult = null;
try
{
searchresult = dropbox.Files.SearchAsync(Lua.lua_tostring(L, 1), Lua.lua_tostring(L, 2)).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
if (searchresult != null && searchresult.Matches.Count == 0 && exception == null)
{
exception = "No files found";
}
Lua.lua_pushstring(L, exception);
Lua.lua_newtable(L);
int filecount = 0;
foreach (SearchMatch metadata in searchresult.Matches)
{
if (metadata.Metadata.IsDeleted) continue;
Lua.lua_newtable(L);
Lua.lua_pushstring(L, metadata.Metadata.Name);
Lua.lua_setfield(L, -2, "Name");
Lua.lua_pushstring(L, metadata.Metadata.PathDisplay);
Lua.lua_setfield(L, -2, "Path");
Lua.lua_pushboolean(L, metadata.Metadata.IsFolder);
Lua.lua_setfield(L, -2, "isFolder");
filecount++;
Lua.lua_rawseti(L, -2, filecount);
}
Lua.lua_pushnumber(L, filecount);
return 3;
}