Skip to content

Commit

Permalink
fix samba callback functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lessica committed Jul 7, 2022
1 parent dc9ceec commit 0a361e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion device/logos__LogosDeviceConfigurator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define _LOGOS_RETURN_RETAINED
#endif

@class AXMotionController; @class SBRingerControl; @class SBDisplayBrightnessController; @class BBServer;
@class SBDisplayBrightnessController; @class BBServer; @class SBRingerControl; @class AXMotionController;


#line 10 "LogosDeviceConfigurator.xm"
Expand Down
2 changes: 1 addition & 1 deletion hid/logos__HIDRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)preventIdleSleep;
#define _LOGOS_RETURN_RETAINED
#endif

@class SBBacklightController; @class SpringBoard;
@class SpringBoard; @class SBBacklightController;


#line 12 "HIDRecorder.x"
Expand Down
2 changes: 1 addition & 1 deletion monkey/logos__LogosTamperMonkey.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (id)_hostAppBundleId;
#define _LOGOS_RETURN_RETAINED
#endif

@class UIWebView; @class BrowserWindowController; @class _UILayerHostView; @class SFSafariView; @class BrowserController; @class TabController; @class SFBrowserServiceViewController; @class WKFormColorControl; @class WKSelectSinglePicker; @class WKDateTimePicker; @class WKMultipleSelectPicker; @class WKDateTimeInputControl; @class WKFormSelectControl;
@class SFBrowserServiceViewController; @class WKMultipleSelectPicker; @class BrowserWindowController; @class WKDateTimeInputControl; @class _UILayerHostView; @class TabController; @class UIWebView; @class WKFormSelectControl; @class WKSelectSinglePicker; @class BrowserController; @class WKFormColorControl; @class WKDateTimePicker; @class SFSafariView;


#line 36 "LogosTamperMonkey.xm"
Expand Down
37 changes: 18 additions & 19 deletions samba/bridge/KxSMBLuaBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ NS_INLINE BOOL isSambaConfig(lua_State *L, int index)
}
}

NS_INLINE NSDictionary *dictionaryFromItem(KxSMBItem *item)
NS_INLINE NSDictionary *dictionaryFromItem(KxSMBItem *item, BOOL withStat)
{
if (!withStat) {
return @{
@"path": item.path,
@"name": item.path.lastPathComponent ?: @"",
@"type": stringFromItemType(item.type),
};
}
return @{
@"path": item.path,
@"name": item.path.lastPathComponent ?: @"",
Expand Down Expand Up @@ -382,7 +389,7 @@ static int SambaConfig_ListDirectory(lua_State *L)

NSMutableArray <NSDictionary *> *itemList = [NSMutableArray arrayWithCapacity:((NSArray <KxSMBItem *> *)items).count];
for (KxSMBItem *item in (NSArray <KxSMBItem *> *)items) {
[itemList addObject:dictionaryFromItem(item)];
[itemList addObject:dictionaryFromItem(item, YES)];
}

lua_pushNSArray(L, itemList);
Expand Down Expand Up @@ -415,7 +422,7 @@ static int SambaConfig_CreateDirectory(lua_State *L)
return 2;
}

lua_pushNSDictionary(L, dictionaryFromItem((KxSMBItemTree *)item));
lua_pushNSDictionary(L, dictionaryFromItem((KxSMBItemTree *)item, YES));
lua_pushnil(L);
return 2;
}
Expand Down Expand Up @@ -583,8 +590,6 @@ static int SambaConfig_DownloadItem(lua_State *L)
{
return luaL_argerror(L, 4, "callback function expected");
}

lua_pushvalue(L, 4);
}

[[KxSMBProvider sharedSmbProvider] setConfig:copyConfigFromSambaConfig(smbConfig)];
Expand All @@ -598,7 +603,8 @@ static int SambaConfig_DownloadItem(lua_State *L)
auth:copyAuthFromSambaConfig(smbConfig) progress:^(KxSMBItem * _Nonnull item, long transferred, BOOL * _Nonnull stop) {
if (argc > 3)
{
lua_pushNSDictionary(L, dictionaryFromItem(item));
lua_pushvalue(L, 4);
lua_pushNSDictionary(L, dictionaryFromItem(item, NO));
lua_pushinteger(L, transferred);

int ret = lua_pcall(L, 2, 1, 0);
Expand All @@ -609,6 +615,8 @@ static int SambaConfig_DownloadItem(lua_State *L)
}

int shouldStop = lua_isboolean(L, -1) ? lua_toboolean(L, -1) : false;
lua_pop(L, 1);

if (shouldStop)
{
*stop = YES;
Expand All @@ -620,11 +628,6 @@ static int SambaConfig_DownloadItem(lua_State *L)
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

if (argc > 3)
{
lua_pop(L, 1);
}

if ([item isKindOfClass:[NSError class]])
{
lua_pushboolean(L, false);
Expand Down Expand Up @@ -659,8 +662,6 @@ static int SambaConfig_UploadItem(lua_State *L)
{
return luaL_argerror(L, 4, "callback function expected");
}

lua_pushvalue(L, 4);
}

[[KxSMBProvider sharedSmbProvider] setConfig:copyConfigFromSambaConfig(smbConfig)];
Expand All @@ -675,7 +676,8 @@ static int SambaConfig_UploadItem(lua_State *L)
progress:^(KxSMBItem * _Nonnull item, long transferred, BOOL * _Nonnull stop) {
if (argc > 3)
{
lua_pushNSDictionary(L, dictionaryFromItem(item));
lua_pushvalue(L, 4);
lua_pushNSDictionary(L, dictionaryFromItem(item, NO));
lua_pushinteger(L, transferred);

int ret = lua_pcall(L, 2, 1, 0);
Expand All @@ -686,6 +688,8 @@ static int SambaConfig_UploadItem(lua_State *L)
}

int shouldStop = lua_isboolean(L, -1) ? lua_toboolean(L, -1) : false;
lua_pop(L, 1);

if (shouldStop)
{
*stop = YES;
Expand All @@ -697,11 +701,6 @@ static int SambaConfig_UploadItem(lua_State *L)
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

if (argc > 3)
{
lua_pop(L, 1);
}

if ([item isKindOfClass:[NSError class]])
{
lua_pushboolean(L, false);
Expand Down

0 comments on commit 0a361e5

Please sign in to comment.