GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added merge_module function. Added text module (currently having enco… · alvsgithub/NativeScript@162dbe5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Application
    • application.android.ts
    • application.ios.ts
  • BCL.csproj
  • FileSystem
    • file_system.d.ts
    • file_system.ts
    • file_system_access.android.ts
    • file_system_access.d.ts
    • file_system_access.ios.ts
  • Utils
    • module_merge.ts
  • http
    • http.ts
  • text
    • index.ts
    • text.android.ts
    • text.d.ts
    • text.ios.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Application/application.android.ts‎

Copy file name to clipboardExpand all lines: Application/application.android.ts
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import app_common_module = require("Application/application_common");
2-
var currentApp = app_common_module.Application.current;
32

43
// merge the exports of the application_common file with the exports of this file
54
declare var exports;
6-
exports.TargetOS = app_common_module.TargetOS;
7-
exports.Application = app_common_module.Application;
5+
require("Utils/module_merge").merge(app_common_module, exports);
86

7+
var currentApp = app_common_module.Application.current;
98
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
109

1110
var initEvents = function () {
Collapse file

‎Application/application.ios.ts‎

Copy file name to clipboardExpand all lines: Application/application.ios.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ log("JavaScript loading ended.");
2121
*/
2222

2323
import app_common_module = require("Application/application_common");
24-
var currentApp = app_common_module.Application.current;
2524

2625
// merge the exports of the application_common file with the exports of this file
2726
declare var exports;
28-
exports.TargetOS = app_common_module.TargetOS;
29-
exports.Application = app_common_module.Application;
27+
require("Utils/module_merge").merge(app_common_module, exports);
28+
29+
var currentApp = app_common_module.Application.current;
3030

3131
// TODO: Declarations
3232
export var init = function (nativeApp: any) {
Collapse file

‎BCL.csproj‎

Copy file name to clipboardExpand all lines: BCL.csproj
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,22 @@
119119
<TypeScriptCompile Include="Location\location_types.ts">
120120
<DependentUpon>location.d.ts</DependentUpon>
121121
</TypeScriptCompile>
122+
<TypeScriptCompile Include="text\index.ts" />
123+
<TypeScriptCompile Include="text\text.android.ts">
124+
<DependentUpon>text.d.ts</DependentUpon>
125+
</TypeScriptCompile>
126+
<TypeScriptCompile Include="text\text.d.ts" />
127+
<TypeScriptCompile Include="text\text.ios.ts">
128+
<DependentUpon>text.d.ts</DependentUpon>
129+
</TypeScriptCompile>
122130
<TypeScriptCompile Include="UserPreferences\user_preferences.android.ts">
123131
<DependentUpon>user_preferences.d.ts</DependentUpon>
124132
</TypeScriptCompile>
125133
<TypeScriptCompile Include="UserPreferences\user_preferences.d.ts" />
126134
<TypeScriptCompile Include="UserPreferences\user_preferences.ios.ts">
127135
<DependentUpon>user_preferences.d.ts</DependentUpon>
128136
</TypeScriptCompile>
137+
<TypeScriptCompile Include="Utils\module_merge.ts" />
129138
<TypeScriptCompile Include="Utils\utils_android.ts" />
130139
<TypeScriptCompile Include="Utils\utils_ios.ts" />
131140
<TypeScriptCompile Include="http\http_request.android.ts">
Collapse file

‎FileSystem/file_system.d.ts‎

Copy file name to clipboardExpand all lines: FileSystem/file_system.d.ts
+41-41Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ export declare class File extends FileSystemEntity {
5252
public static fromPath(path: string, onError?: (error: any) => any): File;
5353

5454
/**
55-
* Creates a FileReader object over this file and locks the file until the reader is released.
55+
* Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
5656
*/
57-
public openRead(): FileReader;
57+
public readText(onSuccess: (content: string) => any, onError?: (error: any) => any, encoding?: string);
5858

5959
/**
60-
* Creates a FileWriter object over this file and locks the file until the writer is released.
60+
* Writes the provided string to the file, using the specified encoding (defaults to UTF-8).
6161
*/
62-
public openWrite(): FileWriter;
62+
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any, encoding?: string);
6363
}
6464

6565
export declare class Folder extends FileSystemEntity {
@@ -110,7 +110,7 @@ export declare class Folder extends FileSystemEntity {
110110
If the callback returns false this will mean for the iteration to stop.
111111
*/
112112
public eachEntity(onEntity: (entity: FileSystemEntity) => boolean, onError?: (error: any) => any);
113-
}
113+
}
114114

115115
/**
116116
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
@@ -127,39 +127,39 @@ export declare module knownFolders {
127127
export function temp(): Folder;
128128
}
129129

130-
/**
131-
* Base class for FileReader and FileWriter APIs.
132-
*/
133-
export declare class FileAccess {
134-
constructor(file: File);
135-
136-
/**
137-
* Unlocks the file and allows other operations over it.
138-
*/
139-
public release();
140-
141-
/**
142-
* Gets the underlying File instance.
143-
*/
144-
file: File;
145-
}
146-
147-
/**
148-
* Enables reading the content of a File entity.
149-
*/
150-
export declare class FileReader extends FileAccess {
151-
/**
152-
* Reads the content of the underlying File as a UTF8 encoded string.
153-
*/
154-
public readText(onSuccess: (content: string) => any, onError?: (error: any) => any);
155-
}
156-
157-
/**
158-
* Enables saving data to a File entity.
159-
*/
160-
export declare class FileWriter extends FileAccess {
161-
/**
162-
* Enables saving string to a File entity.
163-
*/
164-
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any);
165-
}
130+
///**
131+
// * Base class for FileReader and FileWriter APIs.
132+
// */
133+
//export declare class FileAccess {
134+
// constructor(file: File);
135+
136+
// /**
137+
// * Unlocks the file and allows other operations over it.
138+
// */
139+
// public release();
140+
141+
// /**
142+
// * Gets the underlying File instance.
143+
// */
144+
// file: File;
145+
//}
146+
147+
///**
148+
// * Enables reading the content of a File entity.
149+
// */
150+
//export declare class FileReader extends FileAccess {
151+
///**
152+
//* Reads the content of the underlying File as a UTF8 encoded string.
153+
//*/
154+
//public readText(onSuccess: (content: string) => any, onError?: (error: any) => any);
155+
//}
156+
157+
///**
158+
// * Enables saving data to a File entity.
159+
// */
160+
//export declare class FileWriter extends FileAccess {
161+
// /**
162+
// * Enables saving string to a File entity.
163+
// */
164+
// public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any);
165+
//}
Collapse file

‎FileSystem/file_system.ts‎

Copy file name to clipboardExpand all lines: FileSystem/file_system.ts
+58-70Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -162,47 +162,83 @@ export class File extends FileSystemEntity {
162162
}
163163

164164
/**
165-
* Checks whether a File with the specified path already exists.
166-
*/
165+
* Checks whether a File with the specified path already exists.
166+
*/
167167
public static exists(path: string): boolean {
168168
return getFileAccess().fileExists(path);
169169
}
170170

171171
/**
172-
* Creates a FileReader object over this file and locks the file until the reader is released.
173-
*/
174-
public openRead(): FileReader {
175-
this.checkAccess();
176-
return new FileReader(this);
172+
* Gets the extension of the entity.
173+
*/
174+
get extension(): string {
175+
return this[extensionProperty];
177176
}
178177

179178
/**
180-
* Creates a FileWriter object over this file and locks the file until the writer is released.
179+
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
181180
*/
182-
public openWrite(): FileWriter {
183-
this.checkAccess();
184-
return new FileWriter(this);
181+
get isLocked(): boolean {
182+
return this[fileLockedProperty];
185183
}
186184

187185
/**
188-
* Gets the extension of the entity.
189-
*/
190-
get extension(): string {
191-
return this[extensionProperty];
186+
* Reads the content of the file as a string using the specified encoding (defaults to UTF-8).
187+
*/
188+
public readText(onSuccess: (content: string) => any, onError?: (error: any) => any, encoding?: string) {
189+
if (!onSuccess) {
190+
return;
191+
}
192+
193+
this.checkAccess();
194+
this[fileLockedProperty] = true;
195+
196+
var that = this;
197+
var localSuccess = function (content: string) {
198+
that[fileLockedProperty] = false;
199+
onSuccess(content);
200+
}
201+
202+
var localError = function (error) {
203+
that[fileLockedProperty] = false;
204+
if (onError) {
205+
onError(error);
206+
}
207+
}
208+
209+
// TODO: Asyncronous
210+
getFileAccess().readText(this.path, localSuccess, localError, encoding);
192211
}
193212

194213
/**
195-
* Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running.
196-
*/
197-
get isLocked(): boolean {
198-
return this[fileLockedProperty];
214+
* Writes the provided string to the file, using the specified encoding. Any previous content will be overwritten.
215+
*/
216+
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any, encoding?: string) {
217+
this.checkAccess();
218+
this[fileLockedProperty] = true;
219+
220+
var that = this;
221+
var localSuccess = function () {
222+
that[fileLockedProperty] = false;
223+
if (onSuccess) {
224+
onSuccess();
225+
}
226+
};
227+
228+
var localError = function (error) {
229+
that[fileLockedProperty] = false;
230+
if (onError) {
231+
onError(error);
232+
}
233+
};
234+
235+
// TODO: Asyncronous
236+
getFileAccess().writeText(this.path, content, localSuccess, localError, encoding);
199237
}
200238

201239
private checkAccess() {
202240
if (this.isLocked) {
203-
throw {
204-
message: "Cannot access a locked file."
205-
};
241+
throw new Error("Cannot access a locked file.");
206242
}
207243
}
208244
}
@@ -371,52 +407,4 @@ export module knownFolders {
371407

372408
return _temp;
373409
}
374-
}
375-
376-
/**
377-
* Base class for FileReader and FileWriter APIs.
378-
*/
379-
export class FileAccess {
380-
private _file;
381-
382-
constructor(file: File) {
383-
this._file = file;
384-
this._file[fileLockedProperty] = true;
385-
}
386-
387-
/**
388-
* Unlocks the file and allows other operations over it.
389-
*/
390-
public release() {
391-
this._file[fileLockedProperty] = false;
392-
this._file = undefined;
393-
}
394-
395-
/**
396-
* Gets the underlying File instance.
397-
*/
398-
get file(): File {
399-
return this._file;
400-
}
401-
}
402-
403-
/**
404-
* Enables reading the content of a File entity.
405-
*/
406-
export class FileReader extends FileAccess {
407-
/**
408-
* Reads the content of the underlying File as a UTF8 encoded string.
409-
*/
410-
public readText(onSuccess: (content: string) => any, onError?: (error: any) => any) {
411-
getFileAccess().readText(this.file.path, onSuccess, onError);
412-
}
413-
}
414-
415-
/**
416-
* Enables saving data to a File entity.
417-
*/
418-
export class FileWriter extends FileAccess {
419-
public writeText(content: string, onSuccess?: () => any, onError?: (error: any) => any) {
420-
getFileAccess().writeText(this.file.path, content, onSuccess, onError);
421-
}
422410
}
Collapse file

‎FileSystem/file_system_access.android.ts‎

Copy file name to clipboardExpand all lines: FileSystem/file_system_access.android.ts
+23-13Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import app_module = require("Application/application");
2-
1+
import appModule = require("Application/application");
2+
import textModule = require("text/text");
33

44
export class FileSystemAccess {
5-
private _encoding = "UTF-8";
65
private _pathSeparator = java.io.File.separator;
76

87
public getLastModified(path: string): Date {
@@ -212,22 +211,27 @@ export class FileSystemAccess {
212211
}
213212

214213
public getDocumentsFolderPath(): string {
215-
var context = app_module.Application.current.android.context;
216-
var dir: java.io.File = context.getFilesDir();
214+
var context = appModule.Application.current.android.context;
215+
var dir = context.getFilesDir();
217216
return dir.getAbsolutePath();
218217
}
219218

220219
public getTempFolderPath(): string {
221-
var context = app_module.Application.current.android.context;
222-
var dir: java.io.File = context.getCacheDir();
220+
var context = appModule.Application.current.android.context;
221+
var dir = context.getCacheDir();
223222
return dir.getAbsolutePath();
224223
}
225224

226-
public readText(path: string, onSuccess: (content: string) => any, onError?: (error: any) => any) {
225+
public readText(path: string, onSuccess: (content: string) => any, onError?: (error: any) => any, encoding?: string) {
227226
try {
228227
var javaFile = new java.io.File(path);
229228
var stream = new java.io.FileInputStream(javaFile);
230-
var reader = new java.io.InputStreamReader(stream, this._encoding);
229+
230+
var actualEncoding = encoding;
231+
if (!actualEncoding) {
232+
actualEncoding = textModule.encoding.UTF_8;
233+
}
234+
var reader = new java.io.InputStreamReader(stream, actualEncoding);
231235
var bufferedReader = new java.io.BufferedReader(reader);
232236

233237
// TODO: We will need to read the entire file to a CharBuffer instead of reading it line by line
@@ -243,8 +247,9 @@ export class FileSystemAccess {
243247
if (result.length > 0) {
244248
// add the new line manually to the result
245249
// TODO: Try with CharBuffer at a later stage, when the Bridge allows it
246-
// result += "\n";
250+
result += "\n";
247251
}
252+
248253
result += line;
249254
}
250255

@@ -260,15 +265,20 @@ export class FileSystemAccess {
260265
}
261266
}
262267

263-
public writeText(path: string, content: string, onSuccess?: () => any, onError?: (error: any) => any) {
268+
public writeText(path: string, content: string, onSuccess?: () => any, onError?: (error: any) => any, encoding?: string) {
264269
try {
265270
var javaFile = new java.io.File(path);
266271
var stream = new java.io.FileOutputStream(javaFile);
267-
var writer = new java.io.OutputStreamWriter(stream, this._encoding);
272+
273+
var actualEncoding = encoding;
274+
if (!actualEncoding) {
275+
actualEncoding = textModule.encoding.UTF_8;
276+
}
277+
var writer = new java.io.OutputStreamWriter(stream, actualEncoding);
268278

269279
writer.write(content);
270280
writer.close();
271-
281+
272282
if (onSuccess) {
273283
onSuccess();
274284
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.