Firefox Addon SDK - How to get a list of files in a directory, and get a file - firefox-addon

I am using the SDK to build a Firefox addon. In the addon options, the user can specify a directory of images for my addon to use (these will be added to a webpage).
I cannot figure out how to obtain a list of the files in the directory the user specified (Note that I know how to get this directory using simple-prefs). I also need to know how to get a specific file.
The file I get will be sent to a contentScriptFile to add to a webpage (as a background-image) using pageMod, via worker.port.emit(...).
So my question: How do I obtain a list of files in a directory, and how to get one of those files to send to a contentScriptFile?

I have found out how to do it, using the Low-Level API io/file
After you require() it using var fileIO = require("sdk/io/file"); you can do the following:
List files and directories in a directory using fileIO.list(path), where path is the path to the directory
Read a file using fileIO.read(path), this returns a string with the contents of the file

Related

How can I access the contents of a folder selected from Files app?

Basically my app works like a iCloud-based note app (for example, logseq). Users first select a folder in Files app, then my app starts downloading/updating the contents of the folder.
So I implemented folder selection via UIDocumentPickerViewController, after I got the folder path in Files app. I tried downloading a hardcoded file like (<the folder path user just selected>/fileList.json) via FileManager.startDownloadingUbiquitousItem, got 257 permission error (the file does exist in my icloud drive). Then I followed the answer from this answer to call startAccessingSecurityScopedResource. It always returns false and the same 257 error returned.
Perhaps, I cannot access a random file from a selected folder? but how can those note apps work by simply letting users selecting a root folder?
Answering my own question after some debugging. Call startAccessingSecurityScopedResource on the folder path you grabbed from picker, not its subfiles. After that, you can start downloading its subfiles via startDownloadingUbiquitousItem

Hyperlink to a file in the current folder regardless of its location on the drive

Putting together a .doc file with a table of content with links to external files. The challenge is: how to make them so that it points to the given file in the current folder regardless of its location on the disk.
Context: I will be sending the set of files to another person, so I can't put the path on my machine, nor on a server since they will be working offline. They will be working on Remarkable device and I want them to be able to use the major overview file with the links to access each of the files, rather than having to browse the folders.

Show Content of app file after unzipping the iPA, and opening exec shows my local path

I've developed an application and I need to remove my computer local path from the generated iPA file.
I did the following:
unzipping iPA file.
click on show package content.
open exec(appname.exec) file with text editor.
Now I can see some binary stuff, and strings with my computer local path (with my mac name).
I have to remove these paths from the exec file, due to security issues. How can I do so?
As Accessing Files and Directories says:
Although you can open any file and read its contents as a stream of bytes, doing so is not always the right choice. OS X and iOS provide built-in support that makes opening many types of standard file formats (such as text files, images, sounds, and property lists) much easier. For these standard file formats, you should use the higher-level options for reading and writing the file contents. Table 2-1 lists the common file types supported by the system along with information about how you access them.
You have many ways to save your data:
Specifying the Path to a File or Directory
Locating Items in Your App Bundle
Locating Items in the Standard Directories
Locating Files Using Bookmarks
You have chosen to Specifying the Path to a File or Directory,as #Droppy says
Firstly it will break the code signature and secondly it's time consuming and error prone.
You'd better choose to Locating Items in the Standard Directories
Here is why you should choose the way:
Locating Items in the Standard Directories
When you need to locate a file in one of the standard directories, use the system frameworks to locate the directory first and then use the resulting URL to build a path to the file. The Foundation framework includes several options for locating the standard system directories. By using these methods, the paths will be correct whether your app is sandboxed or not:
The URLsForDirectory:inDomains: method of the NSFileManager class returns a directory’s location packaged in an NSURL object. The directory to search for is an NSSearchPathDirectory constant. These constants provide URLs for the user’s home directory, as well as most of the standard directories.
The NSSearchPathForDirectoriesInDomains function behaves like the URLsForDirectory:inDomains: method but returns the directory’s location as a string-based path. You should use the URLsForDirectory:inDomains: method instead.
The NSHomeDirectory function returns the path to either the user’s or app’s home directory. (Which home directory is returned depends on the platform and whether the app is in a sandbox.) When an app is sandboxed the home directory points to the app’s sandbox, otherwise it points to the User’s home directory on the file system. If constructing a file to a subdirectory of a user’s home directory, you should instead consider using the URLsForDirectory:inDomains: method instead.
You can use the URL or path-based string you receive from the preceding routines to build new objects with the locations of the files you want. Both the NSURL and NSString classes provide path-related methods for adding and removing path components and making changes to the path in general. Listing 2-1 shows an example that searches for the standard Application Support directory and creates a new URL for a directory containing the app’s data files.
You cannot do it this way. Firstly it will break the code signature and secondly it's time consuming and error prone.
The correct approach is to not use the complete path in your code and instead use methods like NSSearchPathForDirectoriesInDomains to get the Documents folder, or whatever directory you want to use.

How do you apply relative paths for locally developed HTML files

I know the subject line must sound really stupid. Of course you would locally develop HTML files - didn't know how to phrase it better since I'm a beginner at HTML+CSS.
So to get to the point:
I'm linking to images and pages on the HTML file I'm editing. However, when I open the HTML file in my browser locally the links are broken because I'm not using an absolute path. My preference is to use relative path because I'll be able to simply move my project file folder onto my server without having to change the URL paths in my HTML files.
My question is: How do I get the relative paths to point to where I want without having to list the entire drive directory?
Ex. My local HTML has the following line:
<img src="/images/logo.jpg">
But opening the local HTML file in my browser, the image is broken since it points to: file:///D:/images/logo.jpg
How do I get it to point to {local root}/images/logo.jpg instead?
What I did was to install a local development server such as EasyPHP, and setting the proper root folder within my project folder. Setting the root folder tells the local server where the root is, and so any relative paths work as expected.

test a webworks blackberry app

I have four files (config.xml, index.html, scripts.js, and styles.css). The html has a canvas and a form for users input. I want to run on blackberry simulator (Torch version 6...). I create a zip file of all those files. Then create a bin folder. Now when I run the simulator and load the application, I have either blanc screen, either the following error: Resource does not exist.
Here is the config file code:
BlackberryTest
I had the same problem. You need to use local:/// prefix before the name of the local resource to access it.

Resources