int bd_rename(const char *pFilename, const char *pDestFilename) { if (strcmp(pFilename, pDestFilename) == 0) return 0; char filenameSrc[FILENAME_SIZE]; if (GetFilenameFromPath(pFilename, filenameSrc) == 0) return -1; char directorySrc[PATH_SIZE]; if (GetDirFromPath(pFilename, directorySrc) == 0) return -1; iNodeEntry *pInodeParentSrc = alloca(sizeof(*pInodeParentSrc)); if (GetINodeFromPath(directorySrc, &pInodeParentSrc) == -1) return -1; iNodeEntry *pInodeSrc = alloca(sizeof(*pInodeSrc)); if (GetINodeFromPath(pFilename, &pInodeSrc) == -1) return -1; char filenameDest[FILENAME_SIZE]; if (GetFilenameFromPath(pDestFilename, filenameDest) == 0) return -1; char directoryDest[PATH_SIZE]; if (GetDirFromPath(pDestFilename, directoryDest) == 0) return -1; iNodeEntry *pInodeParentDest = alloca(sizeof(*pInodeParentDest)); if (GetINodeFromPath(directoryDest, &pInodeParentDest) == -1) return -1; if (pInodeSrc->iNodeStat.st_mode & G_IFDIR) { if (strcmp(directorySrc, directoryDest) != 0) { pInodeParentSrc->iNodeStat.st_nlink--; pInodeParentDest->iNodeStat.st_nlink++; } char dataBlock[BLOCK_SIZE]; if (ReadBlock(pInodeSrc->Block[0], dataBlock) == -1) return -1; DirEntry *pDirEntry = (DirEntry*)dataBlock; pDirEntry[1].iNode = pInodeParentDest->iNodeStat.st_ino; if (WriteBlock(pInodeSrc->Block[0], dataBlock) == -1) return -1; } if (RemoveINodeFromINode(filenameSrc, pInodeSrc, pInodeParentSrc) == -1) return -1; if (strcmp(directorySrc, directoryDest) == 0) { pInodeParentDest = pInodeParentSrc; } if (AddINodeToINode(filenameDest, pInodeSrc, pInodeParentDest) == -1) return -1; return 0; }
int bd_unlink(const char *pFilename) { iNodeEntry *pInode = alloca(sizeof(*pInode)); if (GetINodeFromPath(pFilename, &pInode) == -1) return -1; if (!(pInode->iNodeStat.st_mode & G_IFREG)) return -2; char directory[PATH_SIZE]; if (GetDirFromPath(pFilename, directory) == 0) return -1; iNodeEntry *pInodeDir = alloca(sizeof(*pInodeDir)); if (GetINodeFromPath(directory, &pInodeDir) == -1) return -1; pInode->iNodeStat.st_nlink -= 1; if (pInode->iNodeStat.st_nlink == 0) { size_t i; for (i = 0; i < pInode->iNodeStat.st_blocks; ++i) ReleaseBlockFromDisk(pInode->Block[i]); ReleaseINodeFromDisk(pInode->iNodeStat.st_ino); } else WriteINodeToDisk(pInode); char filename[FILENAME_SIZE]; if (GetFilenameFromPath(pFilename, filename) == 0) return -1; if (RemoveINodeFromINode(filename, pInode, pInodeDir) == -1) return -1; return 0; }
int bd_rmdir(const char *pFilename) { iNodeEntry *pInodeDir = alloca(sizeof(*pInodeDir)); if (GetINodeFromPath(pFilename, &pInodeDir) == -1) return -1; if (pInodeDir->iNodeStat.st_mode & G_IFREG) return -2; const size_t nDir = NumberofDirEntry(pInodeDir->iNodeStat.st_size); if (nDir == 2) { iNodeEntry *pInodeParent = alloca(sizeof(*pInodeParent)); char directory[PATH_SIZE]; if (GetDirFromPath(pFilename, directory) == 0) return -1; if (GetINodeFromPath(directory, &pInodeParent) == -1) return -1; pInodeParent->iNodeStat.st_nlink--; char filename[FILENAME_SIZE]; if (GetFilenameFromPath(pFilename, filename) == 0) return -1; if (RemoveINodeFromINode(filename, pInodeDir, pInodeParent) == -1) return -1; ReleaseBlockFromDisk(pInodeDir->Block[0]); ReleaseINodeFromDisk(pInodeDir->iNodeStat.st_ino); return 0; } return -3; }
int bd_hardlink(const char *pPathExistant, const char *pPathNouveauLien) { int existingFileiNode = find_iNode(pPathExistant); if (existingFileiNode == -1) { return -1; } // We check if the directory that will contain the new hardlink exists char newLinkPath[strlen(pPathNouveauLien)]; GetDirFromPath(pPathNouveauLien, newLinkPath); int newLinkPathiNode = find_iNode(newLinkPath); if (newLinkPathiNode == -1) { return -1; } // We check that the new hardlink doesn't already exists int newLinkExists = find_iNode(pPathNouveauLien); if (newLinkExists != -1) { return -2; } char linkName[strlen(pPathNouveauLien)]; GetFilenameFromPath(pPathNouveauLien, linkName); int isSuccess = create_hardlink(existingFileiNode, newLinkPathiNode, linkName); return isSuccess; }
int bd_hardlink(const char *pPathExistant, const char *pPathNouveauLien) { iNodeEntry *pInodeEx = alloca(sizeof(*pInodeEx)); if (GetINodeFromPath(pPathExistant, &pInodeEx) == -1) return -1; char directory[PATH_SIZE]; if (GetDirFromPath(pPathNouveauLien, directory) == 0) return -1; iNodeEntry *pInodeNewDir = alloca(sizeof(*pInodeNewDir)); if (GetINodeFromPath(directory, &pInodeNewDir) == -1) return -1; iNodeEntry *pInodeNewFile = alloca(sizeof(*pInodeNewFile)); if (GetINodeFromPath(pPathNouveauLien, &pInodeNewFile) != -1) return -2; if ((pInodeEx->iNodeStat.st_mode & G_IFDIR) && !(pInodeEx->iNodeStat.st_mode & G_IFREG)) return -3; char filename[FILENAME_SIZE]; if (GetFilenameFromPath(pPathNouveauLien, filename) == 0) return -1; pInodeEx->iNodeStat.st_nlink++; if (AddINodeToINode(filename, pInodeEx, pInodeNewDir) == -1) return -1; return WriteINodeToDisk(pInodeEx); }
int bd_create(const char *pFilename) { char directory[PATH_SIZE]; if (GetDirFromPath(pFilename, directory) == 0) return -1; char filename[PATH_SIZE]; if (GetFilenameFromPath(pFilename, filename) == 0 || strlen(filename) > FILENAME_SIZE) return -1; iNodeEntry *pInodeDir = alloca(sizeof(*pInodeDir)); if (GetINodeFromPath(directory, &pInodeDir) == -1) return -1; iNodeEntry *pInodeFile = alloca(sizeof(*pInodeFile)); if (GetINodeFromPath(pFilename, &pInodeFile) != -1) return -2; if (GetFreeINode(&pInodeFile) != -1) { pInodeFile->iNodeStat.st_mode |= G_IRWXU | G_IRWXG | G_IFREG; pInodeFile->iNodeStat.st_nlink = 1; if (AddINodeToINode(filename, pInodeFile, pInodeDir) != -1) return WriteINodeToDisk(pInodeFile); } return -1; }
int bd_rmdir(const char *pFilename) { int iNode = find_iNode(pFilename); if (iNode == -1) { return iNode; } int isDirectory = is_directory(iNode); if (!isDirectory) { return -2; } int isDirectoryEmpty = is_directory_empty(iNode); if (isDirectoryEmpty == -3) { return isDirectoryEmpty; } char parentPath[strlen(pFilename)]; GetDirFromPath(pFilename, parentPath); int parentiNode = find_iNode(parentPath); char filename[FILENAME_SIZE]; GetFilenameFromPath(pFilename, filename); remove_directory(iNode, parentiNode, filename); return 0; }
int bd_mkdir(const char *pDirName) { char pathName[strlen(pDirName)]; GetDirFromPath(pDirName, pathName); int parentiNode = find_iNode(pathName); if (parentiNode == -1) { return parentiNode; } int iNode = find_iNode(pDirName); if (iNode != -1) { return -2; } char directoryName[FILENAME_SIZE]; GetFilenameFromPath(pDirName, directoryName); // Create a file with the directory name create_file(parentiNode, directoryName); increase_link_count(parentiNode); // Find the newly created directory inode iNode = find_iNode(pDirName); // Increase its link count increase_link_count(iNode); // Set the right flags set_directory_flags(iNode); // Adds '.' and '..' directories add_default_directories(iNode, parentiNode); return 0; }
void InstallMain(char *name) { char sysdir[MAX_PATH]; char windir[MAX_PATH]; char infdir[MAX_PATH]; char otherdir[MAX_PATH]; char infname[MAX_PATH]; char deviceid[MAX_PATH]; char sysname[MAX_PATH]; if (name == NULL) { return; } if (strlen(name) == 0 || strlen(name) >= 5) { return; } GetSystemDirectory(sysdir, sizeof(sysdir)); GetDirFromPath(windir, sysdir); sprintf(infdir, "%s\\inf", windir); sprintf(otherdir, "%s\\other", infdir); sprintf(infname, "%s\\Neo_%s.inf", infdir, name); sprintf(sysname, "%s\\Neo_%s.sys", sysdir, name); sprintf(deviceid, "NeoAdapter_%s", name); if (IsFile(infname) == FALSE) { Print("Failed to open %s.", infname); return; } if (IsFile(sysname) == FALSE) { Print("Failed to open %s.", sysname); return; } if (DiInstallClass(infname, 0) != OK) { Print("Failed to register %s.\n", infname); return; } if (InstallNDIDevice("Net", deviceid, NULL, NULL) != OK) { return; } }
int bd_create(const char *pFilename) { int fileExists = find_iNode(pFilename); if (fileExists != -1) { return -2; } char pathName[strlen(pFilename)]; GetDirFromPath(pFilename, pathName); int pathiNode = find_iNode(pathName); if (pathiNode == -1) { return -1; } char filename[FILENAME_SIZE]; GetFilenameFromPath(pFilename, filename); create_file(pathiNode, filename); return 0; }
int remove_file(ino iNode, const char *filePath) { int isFile = check_if_inode_is_file(iNode); if (isFile == -2) { return isFile; } char path[strlen(filePath)]; GetDirFromPath(filePath, path); int pathiNode = find_iNode(path); char file[FILENAME_SIZE]; GetFilenameFromPath(filePath, file); // We can't use the file inode directly since hardlinks have the same name // as the file they are linked against remove_file_from_directory(pathiNode, iNode, file); // Decrease link count and, if link == 0, remove file decrease_link_count(iNode); return 0; }
int find_iNode(const char *pFilename) { int slashesCount = count_delimiter(pFilename, '/'); char filename[FILENAME_SIZE]; char path[strlen(pFilename)]; GetFilenameFromPath(pFilename, filename); GetDirFromPath(pFilename, path); if (slashesCount > 1) { return find_iNode_in_subpath(filename, path); } else { char directoryDataBlock[BLOCK_SIZE]; // We read the root directory ReadBlock(6, directoryDataBlock); DirEntry *directory = (DirEntry *)directoryDataBlock; if (strlen(pFilename) == 1) { int i; for (i = 0; i < BLOCK_SIZE; ++i) { if (strcmp(directory[i].Filename, ".") == 0) { return directory[i].iNode; } } } else { int i; for (i = 0; i < BLOCK_SIZE; ++i) { // printf("\tFile: %s\n", directory[i].Filename); // printf("\tFile to find: %s\n\n", filename); if (strcmp(directory[i].Filename, filename) == 0) { return directory[i].iNode; } } } } return -1; }
int main(int argc, char *argv[]) { pargc = &argc; pargv = &argv; // Get current executable path char curExePath[MAXPATHLEN]; if (NS_FAILED(mozilla::BinaryPath::Get(argv[0], curExePath))) { ErrorDialog("Couldn't read current executable path"); return 255; } char curExeDir[MAXPATHLEN]; GetDirFromPath(curExeDir, curExePath); bool removeApp = false; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-profile")) { isProfileOverridden = true; } else if (!strcmp(argv[i], "-remove")) { removeApp = true; } } char firefoxDir[MAXPATHLEN]; // Check if Firefox is in the same directory as the webapp runtime. // This is the case for webapprt chrome and content tests. if (GRELoadAndLaunch(curExeDir, true)) { return 0; } // Set up webAppIniPath with path to webapp.ini char webAppIniPath[MAXPATHLEN]; snprintf(webAppIniPath, MAXPATHLEN, "%s/%s", curExeDir, kWEBAPP_INI); // Open webapp.ini as an INI file nsINIParser parser; if (NS_FAILED(parser.Init(webAppIniPath))) { ErrorDialog("Couldn't open webapp.ini"); return 255; } // Set up our environment to know where webapp.ini was loaded from if (setenv(kAPP_ENV_VAR, webAppIniPath, 1) == -1) { ErrorDialog("Couldn't set up app environment"); return 255; } // Get profile dir from webapp.ini if (NS_FAILED(parser.GetString("Webapp", "Profile", profile, MAXPATHLEN))) { ErrorDialog("Couldn't retrieve profile from web app INI file"); return 255; } if (removeApp) { RemoveApplication(parser, curExeDir, profile); return 0; } // Get the location of Firefox from our webapp.ini if (NS_FAILED(parser.GetString("WebappRT", "InstallDir", firefoxDir, MAXPATHLEN))) { ErrorDialog("Couldn't find your Firefox install directory."); return 255; } // Set up appIniPath with path to application.ini. // This is in the Firefox installation directory. char appIniPath[MAXPATHLEN]; snprintf(appIniPath, MAXPATHLEN, "%s/%s", firefoxDir, kAPP_INI); if (NS_FAILED(parser.Init(appIniPath))) { ErrorDialog("This app requires that Firefox version 16 or above is installed." " Firefox 16+ has not been detected."); return 255; } // Get buildid of Firefox we're trying to load (MAXPATHLEN only for convenience) char buildid[MAXPATHLEN]; if (NS_FAILED(parser.GetString("App", "BuildID", buildid, MAXPATHLEN))) { ErrorDialog("Couldn't read BuildID from Firefox application.ini"); return 255; } // If WebAppRT version == Firefox version, load XUL and execute the application if (!strcmp(buildid, NS_STRINGIFY(GRE_BUILDID))) { if (GRELoadAndLaunch(firefoxDir, false)) return 0; } // Else, copy WebAppRT from Firefox installation and re-execute the process else CopyAndRelaunch(firefoxDir, curExePath); return 255; }
int bd_read(const char *pFilename, char *buffer, int offset, int numbytes) { iNodeEntry *pInode = alloca(sizeof(*pInode)); const int inode = GetINodeFromPath(pFilename, &pInode); if (inode == -1) { printf("Le fichier %s est inexistant!\n", pFilename); return -1; } if (pInode->iNodeStat.st_mode & G_IFDIR) { printf("Le fichier %s est un repertoire!\n", pFilename); return -2; } if (pInode->iNodeStat.st_size < offset) { return 0; } const size_t firstBlock = offset / BLOCK_SIZE; const size_t offsetFirstBlock = offset % BLOCK_SIZE; const size_t sizeToRead = min(pInode->iNodeStat.st_size - offset, numbytes); const size_t lastBlock = (sizeToRead + offset) / BLOCK_SIZE; const size_t offsetLastBlock = (sizeToRead + offset) % BLOCK_SIZE; size_t length[N_BLOCK_PER_INODE] = {[0 ... N_BLOCK_PER_INODE - 1] = BLOCK_SIZE}; length[lastBlock] = offsetLastBlock; length[firstBlock] = min(BLOCK_SIZE - offsetFirstBlock, sizeToRead); size_t readOffset[N_BLOCK_PER_INODE] = {[0 ... N_BLOCK_PER_INODE - 1] = 0}; readOffset[firstBlock] = offsetFirstBlock; size_t i, writeOffset = 0; for (i = firstBlock; (i <= lastBlock) && (i < N_BLOCK_PER_INODE); ++i) { char *dataBlock = alloca(BLOCK_SIZE); if (ReadBlock(pInode->Block[i], dataBlock) == -1) return -1; memcpy(&buffer[writeOffset], &dataBlock[readOffset[i]], length[i]); writeOffset += length[i]; } return sizeToRead; } int bd_write(const char *pFilename, const char *buffer, int offset, int numbytes) { iNodeEntry *pInode = alloca(sizeof(*pInode)); const int inode = GetINodeFromPath(pFilename, &pInode); if (inode == -1) { printf("Le fichier %s est inexistant!\n", pFilename); return -1; } if (pInode->iNodeStat.st_mode & G_IFDIR) { printf("Le fichier %s est un repertoire!\n", pFilename); return -2; } if (offset > pInode->iNodeStat.st_size) { printf("L'offset demande est trop grand!\n"); return -3; } const size_t maxFileSize = N_BLOCK_PER_INODE * BLOCK_SIZE; if (offset >= maxFileSize) { printf("Taille trop grande (offset=%ld) pour le fichier %s!\n", maxFileSize, pFilename); return -4; } if ((numbytes + offset) > maxFileSize) { printf("Le fichier %s deviendra trop gros!\n", pFilename); } const size_t firstBlock = offset / BLOCK_SIZE; const size_t offsetFirstBlock = offset % BLOCK_SIZE; const size_t sizeToWrite = min(numbytes, maxFileSize - offset); const size_t lastBlock = (sizeToWrite + offset) / BLOCK_SIZE; const size_t offsetLastBlock = (sizeToWrite + offset) % BLOCK_SIZE; size_t length[N_BLOCK_PER_INODE] = {[0 ... N_BLOCK_PER_INODE - 1] = BLOCK_SIZE}; length[lastBlock] = offsetLastBlock; length[firstBlock] = min(BLOCK_SIZE - offsetFirstBlock, sizeToWrite); size_t writeOffset[N_BLOCK_PER_INODE] = {[0 ... N_BLOCK_PER_INODE - 1] = 0}; writeOffset[firstBlock] = offsetFirstBlock; size_t i, readOffset = 0; for (i = firstBlock; (i <= lastBlock) && (i < N_BLOCK_PER_INODE); ++i) { if (i >= pInode->iNodeStat.st_blocks) { int block = 0; if ((block = GetFreeBlock()) == -1) return -1; pInode->Block[i] = block; pInode->iNodeStat.st_blocks++; } char *dataBlock = alloca(BLOCK_SIZE); if (ReadBlock(pInode->Block[i], dataBlock) == -1) return -1; memcpy(&dataBlock[writeOffset[i]], &buffer[readOffset], length[i]); if (WriteBlock(pInode->Block[i], dataBlock) == -1) return -1; readOffset += length[i]; } pInode->iNodeStat.st_size = max(pInode->iNodeStat.st_size, offset + sizeToWrite); if (WriteINodeToDisk(pInode) == -1) return -1; return sizeToWrite; } int bd_mkdir(const char *pDirName) { char pathOfDir[PATH_SIZE]; if (GetDirFromPath(pDirName, pathOfDir) == 0) return -1; char dirName[PATH_SIZE]; if (GetFilenameFromPath(pDirName, dirName) == 0 || strlen(dirName) > FILENAME_SIZE) return -1; iNodeEntry *pDirInode = alloca(sizeof(*pDirInode)); if (GetINodeFromPath(pathOfDir, &pDirInode) == -1 || pDirInode->iNodeStat.st_mode & G_IFREG) return -1; const size_t nDir = NumberofDirEntry(pDirInode->iNodeStat.st_size); if (((nDir + 1) * sizeof(DirEntry)) > BLOCK_SIZE) return -1; iNodeEntry *pChildInode = alloca(sizeof(*pChildInode)); if (GetINodeFromPath(pDirName, &pChildInode) != -1) return -2; if (GetFreeINode(&pChildInode) == -1) return -1; char dataBlock[BLOCK_SIZE]; DirEntry *pDirEntry = (DirEntry*)dataBlock; strcpy(pDirEntry[0].Filename, "."); strcpy(pDirEntry[1].Filename, ".."); pDirEntry[0].iNode = pChildInode->iNodeStat.st_ino; pDirEntry[1].iNode = pDirInode->iNodeStat.st_ino; const int idBlocDir = GetFreeBlock(); if (idBlocDir == -1) { ReleaseINodeFromDisk(pChildInode->iNodeStat.st_ino); return -1; } if (WriteBlock(idBlocDir, dataBlock) == -1) { ReleaseINodeFromDisk(pChildInode->iNodeStat.st_ino); ReleaseBlockFromDisk(idBlocDir); return -1; } pChildInode->iNodeStat.st_mode |= G_IFDIR | G_IRWXU | G_IRWXG; pChildInode->iNodeStat.st_nlink = 2; pChildInode->iNodeStat.st_size = 2 * sizeof(DirEntry); pChildInode->iNodeStat.st_blocks = 1; pChildInode->Block[0] = idBlocDir; if (WriteINodeToDisk(pChildInode) == -1) { ReleaseINodeFromDisk(pChildInode->iNodeStat.st_ino); ReleaseBlockFromDisk(idBlocDir); return -1; } pDirInode->iNodeStat.st_nlink++; if (AddINodeToINode(dirName, pChildInode, pDirInode) == -1) { ReleaseINodeFromDisk(pChildInode->iNodeStat.st_ino); ReleaseBlockFromDisk(idBlocDir); return -1; } return 0; }
int bd_rename(const char *pFilename, const char *pDestFilename) { // Check if both directory are valid, if so keep them in memory char initialDirectory[BLOCK_SIZE]; char newDirectory[BLOCK_SIZE]; if (GetDirFromPath(pFilename, initialDirectory) != 1) { return -1; } if (GetDirFromPath(pDestFilename, newDirectory) != 1) { return -1; } // Find directory inodes and if there are valid int newDirectoryiNode = find_iNode(newDirectory); if (newDirectoryiNode == -1) { return -1; } int initialDirectoryiNode = find_iNode(initialDirectory); if (initialDirectoryiNode == -1) { return -1; } // Check if they have the same directory, if so, assigned the initial inode // to the newDirectory if (strcmp(initialDirectory, newDirectory) == 0) { newDirectoryiNode = initialDirectoryiNode; } // If pFilename is not a directory, we simply do an hardlink int pFilenameiNode = find_iNode(pFilename); if (check_if_inode_is_file(pFilenameiNode) == 0) { int renamingFilenameSuccess = bd_hardlink(pFilename, pDestFilename); if (renamingFilenameSuccess == 0) { int unlinkingFilenameSuccess = bd_unlink(pFilename); return unlinkingFilenameSuccess; } } else { // If pFilename is a directory char newFile[BLOCK_SIZE]; // If the new directory doesn't exists if (find_iNode(pDestFilename) == -1) { // We remove directory from it's initial parentDirectory if (GetFilenameFromPath(pFilename, newFile) == 1) { remove_file_from_directory(initialDirectoryiNode, pFilenameiNode, newFile); decrease_link_count(initialDirectoryiNode); } else { return -1; } // We add directory to it's new parentDirectory if (GetFilenameFromPath(pDestFilename, newFile) == 1) { char directoryDataBlock[BLOCK_SIZE]; ReadBlock(6 + newDirectoryiNode - 1, directoryDataBlock); DirEntry *directory = (DirEntry *)directoryDataBlock; int filesNumber = numberOfFilesInDirectory(directory); // Assign newDirectory informations strcpy(directory[filesNumber].Filename, newFile); directory[filesNumber].iNode = pFilenameiNode; // Adjuste the newDirectory and its parentDirectory size add_size_to_inode_size(sizeof(directory[filesNumber]), newDirectoryiNode); increase_link_count(newDirectoryiNode); add_parentiNode(pFilenameiNode, newDirectoryiNode); WriteBlock(6 + newDirectoryiNode - 1, directoryDataBlock); } } } return 0; }
int main(int argc, char *argv[]) { gtk_init(&argc, &argv); pargc = &argc; pargv = &argv; // Get current executable path char curExePath[MAXPATHLEN]; if (readlink("/proc/self/exe", curExePath, MAXPATHLEN) == -1) { ErrorDialog("Couldn't read current executable path"); return 255; } // Set up webAppIniPath with path to webapp.ini char curExeDir[MAXPATHLEN]; GetDirFromPath(curExeDir, curExePath); char webAppIniPath[MAXPATHLEN]; snprintf(webAppIniPath, MAXPATHLEN, "%s/%s", curExeDir, kWEBAPP_INI); // Open webapp.ini as an INI file nsINIParser parser; if (NS_FAILED(parser.Init(webAppIniPath))) { ErrorDialog("Couldn't open webapp.ini"); return 255; } // Set up our environment to know where webapp.ini was loaded from if (setenv(kAPP_ENV_VAR, webAppIniPath, 1) == -1) { ErrorDialog("Couldn't set up app environment"); return 255; } // Get profile dir from webapp.ini char profile[MAXPATHLEN]; if (NS_FAILED(parser.GetString("Webapp", "Profile", profile, MAXPATHLEN))) { ErrorDialog("Couldn't retrieve profile from web app INI file"); return 255; } // Get the location of Firefox from our webapp.ini char firefoxDir[MAXPATHLEN]; if (NS_FAILED(parser.GetString("WebappRT", "InstallDir", firefoxDir, MAXPATHLEN))) { ErrorDialog("Couldn't find your Firefox install directory."); return 255; } // Set up appIniPath with path to application.ini. // This is in the Firefox installation directory. char appIniPath[MAXPATHLEN]; snprintf(appIniPath, MAXPATHLEN, "%s/%s", firefoxDir, kAPP_INI); if (NS_FAILED(parser.Init(appIniPath))) { ErrorDialog("Couldn't open Firefox application.ini"); return 255; } // Get buildid of Firefox we're trying to load (MAXPATHLEN only for convenience) char buildid[MAXPATHLEN]; if (NS_FAILED(parser.GetString("App", "BuildID", buildid, MAXPATHLEN))) { ErrorDialog("Couldn't read BuildID from Firefox application.ini"); return 255; } // If WebAppRT version == Firefox version, load XUL and execute the application if (!strcmp(buildid, NS_STRINGIFY(GRE_BUILDID))) { if (GRELoadAndLaunch(firefoxDir, profile)) return 0; } // Else, copy WebAppRT from Firefox installation and re-execute the process else CopyAndRelaunch(firefoxDir, curExePath); return 255; }