Skip to content

Commit 224985e

Browse files
committed
Added TKLiveSync library
1 parent 44a9c90 commit 224985e

File tree

147 files changed

+19222
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+19222
-7
lines changed

TKLiveSync/TKLiveSync.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef TKLiveSync_h
2+
#define TKLiveSync_h
3+
4+
void TNSInitializeLiveSync(void);
5+
6+
#endif /* TKLiveSync_h */

TKLiveSync/TKLiveSync.m

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <Foundation/Foundation.h>
2+
#include "TKLiveSync.h"
3+
#include "unzip.h"
4+
5+
static void tryExtractLiveSyncArchive() {
6+
NSFileManager* fileManager = [NSFileManager defaultManager];
7+
8+
NSString* libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
9+
NSString* liveSyncPath = [NSString pathWithComponents:@[ libraryPath, @"Application Support", @"LiveSync" ]];
10+
NSString* syncZipPath = [NSString pathWithComponents:@[ liveSyncPath, @"sync.zip" ]];
11+
NSString* appPath = [NSString pathWithComponents:@[ liveSyncPath, @"app" ]];
12+
13+
NSError* err;
14+
15+
if ([fileManager fileExistsAtPath:syncZipPath]) {
16+
if ([fileManager fileExistsAtPath:appPath]) {
17+
[fileManager removeItemAtPath:appPath error:&err];
18+
if (err) {
19+
NSLog(@"Can't remove %@: %@", appPath, err);
20+
}
21+
}
22+
23+
NSLog(@"Unzipping LiveSync folder. This could take a while...");
24+
NSDate* startDate = [NSDate date];
25+
int64_t unzippedFilesCount = unzip(syncZipPath.UTF8String, liveSyncPath.UTF8String);
26+
NSLog(@"Unzipped %lld entries in %fms.", unzippedFilesCount, -[startDate timeIntervalSinceNow] * 1000);
27+
28+
[fileManager removeItemAtPath:syncZipPath error:&err];
29+
if (err) {
30+
NSLog(@"Can't remove %@: %@", syncZipPath, err);
31+
}
32+
}
33+
34+
NSString* tnsModulesPath = [appPath stringByAppendingPathComponent:@"tns_modules"];
35+
36+
// TRICKY: Check if real dir tns_modules exists. If it does not, or it is a symlink, the symlink has to be recreated.
37+
if ([fileManager fileExistsAtPath:appPath] && ![fileManager fileExistsAtPath:tnsModulesPath]) {
38+
NSLog(@"tns_modules folder not livesynced. Using tns_modules from the already deployed bundle...");
39+
40+
// If tns_modules were a symlink, delete it so it can be linked again, this is necessary when relaunching the app from Xcode after lifesync, the app bundle seems to move.
41+
[fileManager removeItemAtPath:tnsModulesPath error:nil];
42+
43+
NSError* error;
44+
NSString* bundleNativeScriptModulesPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"app/tns_modules"];
45+
if (![fileManager createSymbolicLinkAtPath: tnsModulesPath withDestinationPath: bundleNativeScriptModulesPath error:&error]) {
46+
NSLog(@"Failed to symlink tns_modules folder: %@", error);
47+
}
48+
}
49+
}
50+
51+
static void trySetLiveSyncApplicationPath() {
52+
NSFileManager* fileManager = [NSFileManager defaultManager];
53+
54+
NSString* libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
55+
NSString* liveSyncPath = [NSString pathWithComponents:@[ libraryPath, @"Application Support", @"LiveSync" ]];
56+
NSString* appPath = [NSString pathWithComponents:@[ liveSyncPath, @"app" ]];
57+
58+
if (![fileManager fileExistsAtPath:appPath]) {
59+
return; // Don't change the app root folder
60+
}
61+
62+
if (setenv("TNSApplicationPath", liveSyncPath.UTF8String, 0) == -1) {
63+
perror("Could not set application path");
64+
}
65+
}
66+
67+
void TNSInitializeLiveSync() {
68+
tryExtractLiveSyncArchive();
69+
trySetLiveSyncApplicationPath();
70+
}

TKLiveSync/libzip/compat.h

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#ifndef _HAD_LIBZIP_COMPAT_H
2+
#define _HAD_LIBZIP_COMPAT_H
3+
4+
/*
5+
compat.h -- compatibility defines.
6+
Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
7+
8+
This file is part of libzip, a library to manipulate ZIP archives.
9+
The authors can be contacted at <libzip@nih.at>
10+
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions
13+
are met:
14+
1. Redistributions of source code must retain the above copyright
15+
notice, this list of conditions and the following disclaimer.
16+
2. Redistributions in binary form must reproduce the above copyright
17+
notice, this list of conditions and the following disclaimer in
18+
the documentation and/or other materials provided with the
19+
distribution.
20+
3. The names of the authors may not be used to endorse or promote
21+
products derived from this software without specific prior
22+
written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
25+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
28+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
*/
36+
37+
#include "zipconf.h"
38+
39+
#ifdef HAVE_CONFIG_H
40+
#include "config.h"
41+
#endif
42+
43+
/* to have *_MAX definitions for all types when compiling with g++ */
44+
#define __STDC_LIMIT_MACROS
45+
46+
#ifdef _WIN32
47+
#ifndef ZIP_EXTERN
48+
#ifndef ZIP_STATIC
49+
#define ZIP_EXTERN __declspec(dllexport)
50+
#endif
51+
#endif
52+
/* for dup(), close(), etc. */
53+
#include <io.h>
54+
#endif
55+
56+
#ifdef HAVE_STDBOOL_H
57+
#include <stdbool.h>
58+
#else
59+
typedef char bool;
60+
#define true 1
61+
#define false 0
62+
#endif
63+
64+
#include <errno.h>
65+
66+
/* at least MinGW does not provide EOPNOTSUPP, see
67+
* http://sourceforge.net/p/mingw/bugs/263/
68+
*/
69+
#ifndef EOPNOTSUPP
70+
#define EOPNOTSUPP EINVAL
71+
#endif
72+
73+
/* at least MinGW does not provide EOVERFLOW, see
74+
* http://sourceforge.net/p/mingw/bugs/242/
75+
*/
76+
#ifndef EOVERFLOW
77+
#define EOVERFLOW EFBIG
78+
#endif
79+
80+
#ifdef _WIN32
81+
#if defined(HAVE__CHMOD)
82+
#define chmod _chmod
83+
#endif
84+
#if defined(HAVE__CLOSE)
85+
#define close _close
86+
#endif
87+
#if defined(HAVE__DUP)
88+
#define dup _dup
89+
#endif
90+
/* crashes reported when using fdopen instead of _fdopen on Windows/Visual Studio 10/Win64 */
91+
#if defined(HAVE__FDOPEN)
92+
#define fdopen _fdopen
93+
#endif
94+
#if !defined(HAVE_FILENO) && defined(HAVE__FILENO)
95+
#define fileno _fileno
96+
#endif
97+
/* Windows' open() doesn't understand Unix permissions */
98+
#if defined(HAVE__OPEN)
99+
#define open(a, b, c) _open((a), (b))
100+
#endif
101+
#if defined(HAVE__SNPRINTF)
102+
#define snprintf _snprintf
103+
#endif
104+
#if defined(HAVE__STRDUP)
105+
#if !defined(HAVE_STRDUP) || defined(_WIN32)
106+
#undef strdup
107+
#define strdup _strdup
108+
#endif
109+
#endif
110+
#if !defined(HAVE__SETMODE) && defined(HAVE_SETMODE)
111+
#define _setmode setmode
112+
#endif
113+
#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
114+
#define strtoll _strtoi64
115+
#endif
116+
#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
117+
#define strtoull _strtoui64
118+
#endif
119+
#if defined(HAVE__UMASK)
120+
#define umask _umask
121+
#endif
122+
#if defined(HAVE__UNLINK)
123+
#define unlink _unlink
124+
#endif
125+
#endif
126+
127+
#ifndef HAVE_FSEEKO
128+
#define fseeko(s, o, w) (fseek((s), (long int)(o), (w)))
129+
#endif
130+
131+
#ifndef HAVE_FTELLO
132+
#define ftello(s) ((long)ftell((s)))
133+
#endif
134+
135+
#ifndef HAVE_MKSTEMP
136+
int _zip_mkstemp(char *);
137+
#define mkstemp _zip_mkstemp
138+
#endif
139+
140+
#if !defined(HAVE_STRCASECMP)
141+
#if defined(HAVE__STRICMP)
142+
#define strcasecmp _stricmp
143+
#elif defined(HAVE_STRICMP)
144+
#define strcasecmp stricmp
145+
#endif
146+
#endif
147+
148+
#if SIZEOF_OFF_T == 8
149+
#define ZIP_OFF_MAX ZIP_INT64_MAX
150+
#define ZIP_OFF_MIN ZIP_INT64_MIN
151+
#elif SIZEOF_OFF_T == 4
152+
#define ZIP_OFF_MAX ZIP_INT32_MAX
153+
#define ZIP_OFF_MIN ZIP_INT32_MIN
154+
#elif SIZEOF_OFF_T == 2
155+
#define ZIP_OFF_MAX ZIP_INT16_MAX
156+
#define ZIP_OFF_MIN ZIP_INT16_MIN
157+
#else
158+
#error unsupported size of off_t
159+
#endif
160+
161+
#if defined(HAVE_FTELLO) && defined(HAVE_FSEEKO)
162+
#define ZIP_FSEEK_MAX ZIP_OFF_MAX
163+
#define ZIP_FSEEK_MIN ZIP_OFF_MIN
164+
#else
165+
#include <limits.h>
166+
#define ZIP_FSEEK_MAX LONG_MAX
167+
#define ZIP_FSEEK_MIN LONG_MIN
168+
#endif
169+
170+
#ifndef SIZE_MAX
171+
#if SIZEOF_SIZE_T == 8
172+
#define SIZE_MAX ZIP_INT64_MAX
173+
#elif SIZEOF_SIZE_T == 4
174+
#define SIZE_MAX ZIP_INT32_MAX
175+
#elif SIZEOF_SIZE_T == 2
176+
#define SIZE_MAX ZIP_INT16_MAX
177+
#else
178+
#error unsupported size of size_t
179+
#endif
180+
#endif
181+
182+
#ifndef PRId64
183+
#ifdef _MSC_VER
184+
#define PRId64 "I64d"
185+
#else
186+
#define PRId64 "lld"
187+
#endif
188+
#endif
189+
190+
#ifndef PRIu64
191+
#ifdef _MSC_VER
192+
#define PRIu64 "I64u"
193+
#else
194+
#define PRIu64 "llu"
195+
#endif
196+
#endif
197+
198+
#ifndef S_ISDIR
199+
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
200+
#endif
201+
202+
#endif /* compat.h */

0 commit comments

Comments
 (0)