DropBox Dll [Lua module][2017]

Plugins y todo lo relacionado para Autoplay Media Studio.
Imagen
Hi, as a ive recived lots of requests about Dropbox API for managing remote files, started coding a lua module for DropBox support using my .net integration. Module needs .net framework 4 to run as its required by official dropbox api. Also this module is compatible with any lua 5.1, luajit x86, not just AMS projects.
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.
Documentation of methods:
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.



:downvote-1417755753: DOWNLOAD + SOURCE CODE

HIDE: ON
Hidebb Message Hidden Description
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;
}
[/hide]
We are waiting for this work from a long time .. We hope you complete the project
Thank you
I can not understand where I can sign in DropBox what is the Code Can be used ? :sorry:
abood1987 escribió:I can not understand where I can sign in DropBox what is the Code Can be used ? :sorry:
Go to https://www.dropbox.com/developers

Create some app and give it permissions you want, read/write over some folders or all account and generate an oAuth token to use in Setup function
Imagen
Imagen
very very Good Pabloko
Gracias

what is the Meaning of remote_file ? is this String Path or What?
and Tell us more clarifications by the statement gave another example We look forward to further clarification :friends:
dropbox has strange issues with paths, for example if you want to use GetFolder to get the root path just use "" instead "/" as i wrote on fisrts post, everithing else will need this slash for example

err=DropBox.Upload("c:\\file.ext", "/my_file.ext")
err=DropBox.Download("/my_file.ext", "c:\\copyfile.ext")
err,files,count=DropBox.GetFolder("")
if err==nil then
for key,file in pairs(files) do
if (file.isFolder) then
print("Folder: "..file.Name)
else
print("File: "..file.Name)
end
end
end


its not very hard, also err will return a exception string if something bad occurs that will tell you waths going on.
This is very good I understand now
Gracias
are you test that :
err=DropBox.Upload(_DesktopFolder.."\\abs.txt", "/abs.txt")
This does not work :hypno:
and what about app Crash if i used more another code in other button or if i clicked again to be do another Download or upload or ......etc
Thanks
abood1987 escribió:are you test that :
err=DropBox.Upload(_DesktopFolder.."\abs.txt", "/abs.txt")
This does not work :hypno:
and what about app Crash if i used more another code in other button or if i clicked again to be do another Download or upload or ......etc
Did you checked the error string? it may have some info.

By design this plugin is single threaded you may use lanes or multithread object to non-block the main thread or use concurrent requests
Pabloko escribió:
abood1987 escribió:are you test that :
err=DropBox.Upload(_DesktopFolder.."\\abs.txt", "/abs.txt")
This does not work :hypno:
and what about app Crash if i used more another code in other button or if i clicked again to be do another Download or upload or ......etc
Did you checked the error string? it may have some info.
nil is returned .
Hoy abood, u were right, ive inserted a releasing of file after upload that seems to be wrongdoing the upload. Ive recompiled it. Tell me if everithing is good now.

Apart from that we could also do Async methods that call callback functions to allow concurrent stuff. I dont know if this could be useful at all.

Tell me if it works
HIDE: ON
Hidebb Message Hidden Description
https://puu.sh/wuzQu/8e018f75a8.dll[/hide]
that is Very good that is Very good :celeryman-1418247558: but if it have a call callback functions to View a Wait time 4 Compleate the Upload it is will be a very Good Compleate Plugin " Can You Do that ??? " callback functions 4 all Plugin functions Please. Such as if the user wants to View time through Progress or wants to do any thing through any Code He wants to Put it By himself
Gracias Pablo Imagen
abood1987 escribió:that is Very good that is Very good :celeryman-1418247558: but if it have a call callback functions to View a Wait time 4 Compleate the Upload it is will be a very Good Compleate Plugin " Can You Do that ??? " callback functions 4 all Plugin functions Please. Such as if the user wants to View time through Progress or wants to do any thing through any Code He wants to Put it By himself
Gracias Pablo Imagen
As you know by design model for plugins is non thread safe and single threaded but i will try to make it async as you request as Eid present for you. stand by some days... i will come with new release
This is a beta of async events, please test it extensively until i can release it.

Now all methods except setup have an async version,
DropBox.asyncXxxxx(..., function(err,...) --[[...]] end)
where the last argument is always a callback function that arguments are the defailt return values, for example:

DropBox.asyncGetAccount(function(err, id, country, email, name, avatar) 
print(err, name)
end)

DropBox.asyncGetFolder("", function(err, files, count)
print(err) --should be nil
end)


Each task will spawn an own thread and connect a Dropbox session so make sure its estable and dont crash while perform other tasks

HIDE: ON
Hidebb Message Hidden Description
DOWNLOAD
https://puu.sh/wwmpZ/ea2187e3fb.dll

All dlls on original package are still needed at exe path until i work a method to manage ilmerge before msbuild task for exported unmanaged methods.

SOURCE
  public class DropBoxLua
{
static DropBoxLua()
{

}

/*static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//return EmbeddedAssembly.Get(args.Name);
}*/

public static IntPtr L = IntPtr.Zero;
public static DropboxClient dropbox = null;
public static string token = null;
public static string BASE = "DropBox";

private static DropboxClient GetDropBoxInstance()
{
if (token == null) throw new Exception("Error in DropBox. No OAuth token set. Please use DropBox.Setup(token)");
return new DropboxClient(token);
}

[DllExport(CallingConvention = CallingConvention.Cdecl)]
public static int you_are_dumb_hehe(IntPtr ls)
{
string haha = "Its ok! you will live with your deficiency.";
haha.Remove(0);
return 0;
}

[DllExport(CallingConvention = CallingConvention.Cdecl)]
public static int luaopen_DropBox(IntPtr ls)
{
//EmbeddedAssembly.Load("DropBox.Dropbox.Api.dll", "Dropbox.Api.dll");
//AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
L = ls;
Lua.register_lua_function(L, BASE, "Setup", lua_dropbox_setup);

Lua.register_lua_function(L, BASE, "GetAccount", lua_dropbox_getaccount);
Lua.register_lua_function(L, BASE, "GetFolder", lua_dropbox_getfolder);
Lua.register_lua_function(L, BASE, "Delete", lua_dropbox_delete);
Lua.register_lua_function(L, BASE, "Upload", lua_dropbox_upload);
Lua.register_lua_function(L, BASE, "Download", lua_dropbox_download);
Lua.register_lua_function(L, BASE, "CreateFolder", lua_dropbox_createfolder);
Lua.register_lua_function(L, BASE, "GetTempLink", lua_dropbox_gettemplink);
Lua.register_lua_function(L, BASE, "Rename", lua_dropbox_rename);
Lua.register_lua_function(L, BASE, "Copy", lua_dropbox_copy);
Lua.register_lua_function(L, BASE, "Search", lua_dropbox_search);

Lua.register_lua_function(L, BASE, "asyncGetAccount", lua_dropbox_asyncgetaccount);
Lua.register_lua_function(L, BASE, "asyncGetFolder", lua_dropbox_asyncgetfolder);
Lua.register_lua_function(L, BASE, "asyncDelete", lua_dropbox_asyncdelete);
Lua.register_lua_function(L, BASE, "asyncUpload", lua_dropbox_asyncupload);
Lua.register_lua_function(L, BASE, "asyncDownload", lua_dropbox_asyncdownload);
Lua.register_lua_function(L, BASE, "asyncCreateFolder", lua_dropbox_asynccreatefolder);
Lua.register_lua_function(L, BASE, "asyncGetTempLink", lua_dropbox_asyncgettemplink);
Lua.register_lua_function(L, BASE, "asyncRename", lua_dropbox_asyncrename);
Lua.register_lua_function(L, BASE, "asyncCopy", lua_dropbox_asynccopy);
Lua.register_lua_function(L, BASE, "asyncSearch", lua_dropbox_asyncsearch);

return 0;
}

public static int lua_dropbox_setup(IntPtr ls)
{
string err = null;
try
{
token = Lua.lua_tostring(L, 1);
dropbox = new DropboxClient(token);
}
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_asyncgetaccount(IntPtr ls)
{
string exception = null;
string[] ret = new string[] { null, null, null, null, null };
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
try
{
FullAccount userdata = GetDropBoxInstance().Users.GetCurrentAccountAsync().Result;
ret[0] = userdata.AccountId;
ret[1] = userdata.Country;
ret[2] = userdata.Email;
ret[3] = userdata.Name.DisplayName;
ret[4] = userdata.ProfilePhotoUrl;
//mydropbox.Dispose();
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
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]);
Lua.lua_pcall(L, 6, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asyncgetfolder(IntPtr lua_State)
{
ListFolderResult folderdata = null;
string path = Lua.lua_tostring(L, 1);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
folderdata = GetDropBoxInstance().Files.ListFolderAsync(path).Result;
}
catch (Exception e)
{
exception = e.ToString();
}

if (folderdata != null && folderdata.Entries.Count == 0 && exception == null)
{
exception = "No files found";
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
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);
Lua.lua_pcall(L, 3, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();

return 0;
}

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_asyncdelete(IntPtr lua_State)
{
string file_to_delete = Lua.lua_tostring(L, 1);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
var k = GetDropBoxInstance().Files.DeleteAsync(file_to_delete).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

private static int lua_dropbox_upload(IntPtr lua_State)
{
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
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_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();

return 0;
}

private static int lua_dropbox_asyncupload(IntPtr lua_State)
{
string exception = null;
string local_file = Lua.lua_tostring(L, 1);
string remote_file = Lua.lua_tostring(L, 2);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
if (!File.Exists(local_file))
exception = "The local file doesn't exists";
else
{
try
{
Stream fs = File.OpenRead(local_file);
var k = GetDropBoxInstance().Files.UploadAsync(remote_file, null, false, null, false, fs).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asyncdownload(IntPtr lua_State)
{
string REMOTE_FILE = Lua.lua_tostring(L, 1);
string LOCAL_FILE = Lua.lua_tostring(L, 2);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
var fm = GetDropBoxInstance().Files.DownloadAsync(REMOTE_FILE, null).Result;
Stream strm = fm.GetContentAsStreamAsync().Result;

using (var fileStream = File.Create(LOCAL_FILE))
{
strm.CopyTo(fileStream);
}
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asynccreatefolder(IntPtr lua_State)
{
string REMOTE_PATH = Lua.lua_tostring(L, 1);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
var k = GetDropBoxInstance().Files.CreateFolderAsync(REMOTE_PATH, true).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asyncgettemplink(IntPtr lua_State)
{
string REMOTE_LINK = Lua.lua_tostring(L, 1);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string ret = null;
string exception = null;
try
{
var filedata = GetDropBoxInstance().Files.GetTemporaryLinkAsync(REMOTE_LINK).Result;
ret = filedata.Link;
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pushstring(L, ret);
Lua.lua_pcall(L, 2, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asyncrename(IntPtr lua_State)
{
string REMOTE_PATH1 = Lua.lua_tostring(L, 1);
string REMOTE_PATH2 = Lua.lua_tostring(L, 2);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
var movefile = GetDropBoxInstance().Files.MoveAsync(REMOTE_PATH1, REMOTE_PATH2, true, true).Result;
}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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_asynccopy(IntPtr lua_State)
{
string REMOTE_PATH1 = Lua.lua_tostring(L, 1);
string REMOTE_PATH2 = Lua.lua_tostring(L, 2);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
try
{
var movefile = GetDropBoxInstance().Files.CopyAsync(REMOTE_PATH1, REMOTE_PATH2, true, true).Result;

}
catch (Exception e)
{
exception = e.ToString();
}
Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_pcall(L, 1, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();
return 0;
}

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;
}

private static int lua_dropbox_asyncsearch(IntPtr lua_State)
{
string REMOTE_PATH1 = Lua.lua_tostring(L, 1);
string REMOTE_PATH2 = Lua.lua_tostring(L, 2);
int pFn = Lua.luaL_ref(L, Lua.LUA_REGISTRYINDEX);
new Thread(new ThreadStart(delegate()
{
string exception = null;
int filecount = 0;
SearchResult searchresult = null;
try
{
searchresult = GetDropBoxInstance().Files.SearchAsync(REMOTE_PATH1, REMOTE_PATH2).Result;
}
catch (Exception e)
{
exception = e.ToString();
}

if (searchresult != null && searchresult.Matches.Count == 0 && exception == null)
{
exception = "No files found";
}

Lua.lua_rawgeti(L, Lua.LUA_REGISTRYINDEX, pFn);
if (Lua.lua_isfunction(L, -1))
{
Lua.lua_pushstring(L, exception);
Lua.lua_newtable(L);

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);
Lua.lua_pcall(L, 3, 0, 0);
}
Lua.luaL_unref(L, Lua.LUA_REGISTRYINDEX, pFn);
})).Start();

return 0;
}

}
[/hide]
crash Still Found is i used any function more than 1 time or if i used Different functions sequentially in different buttons

may be all dells Where is found in CD_Root needed to be ReUpload again ?? i do't Know :hypno:

and another question is this Code by this way is Right ?

Código: Seleccionar todo

function abood()
     Progress.SetCurrentPos("Progress1", 70);
end

DropBox.asyncUpload(_DesktopFolder.."\\Untitled.png", "/Untitled.png",abood);



if this Code have an CallBack Function what is arg ? or not have any arg

by any way all function is work very good Imagen only 1 code you can used on the run Application Mor time Or another Code will be crash app
if this Code have an CallBack Function what is arg ? or not have any arg
The args are the normal results, of each method. In this case "err" should be an argument.

DropBox.Upload(x,y, function(err) 
      --err will be nil if success, if not error msg
end)


ive posted examples lately take a better look at the post.

The crashing stuff, idk its not happening to me but as im breaking the threadsafeness of the system i could expect it... maybe i will think about some fix to join spawned thread to main one...
Pabloko escribió:
The crashing stuff, idk its not happening to me but as im breaking the threadsafeness of the system i could expect it
i used windows 7
Gracias Pablo, lo mejor es que soporta otros interpretes de lua aparte de ams :) :) :) :) :) :)
is there any new news ?