Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #10819 from rroshan1/branch_pref
Browse files Browse the repository at this point in the history
Project Preferences File Corruption Issue
  • Loading branch information
prksingh committed Apr 10, 2015
2 parents 3226325 + e391f96 commit 68793ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ define({
// Application preferences corrupt error strings
"ERROR_PREFS_CORRUPT_TITLE" : "Error Reading Preferences",
"ERROR_PREFS_CORRUPT" : "Your preferences file is not valid JSON. The file will be opened so that you can correct the format. You will need to restart {APP_NAME} for the changes to take effect.",
"ERROR_PROJ_PREFS_CORRUPT" : "Your project preferences file is not valid JSON. The file will be opened so that you can correct the format. You will need to reload the project for the changes to take effect.",

// Application error strings
"ERROR_IN_BROWSER_TITLE" : "Oops! {APP_NAME} Doesn't Run in Browsers Yet.",
Expand Down
32 changes: 32 additions & 0 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,38 @@ define(function (require, exports, module) {
// Some legacy code calls this API with a non-canonical path
rootPath = ProjectModel._ensureTrailingSlash(rootPath);

var projectPrefFullPath = (rootPath + SETTINGS_FILENAME),
file = FileSystem.getFileForPath(projectPrefFullPath);

//Verify that the project preferences file (.brackets.json) is NOT corrupted.
//If corrupted, display the error message and open the file in editor for the user to edit.
FileUtils.readAsText(file)
.done(function (text) {
try {
if (text) {
JSON.parse(text);
}
} catch (err) {
// Cannot parse the text read from the project preferences file.
var info = MainViewManager.findInAllWorkingSets(projectPrefFullPath);
var paneId;
if (info.length) {
paneId = info[0].paneId;
}
FileViewController.openFileAndAddToWorkingSet(projectPrefFullPath, paneId)
.done(function () {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_PREFS_CORRUPT_TITLE,
Strings.ERROR_PROJ_PREFS_CORRUPT
).done(function () {
// give the focus back to the editor with the pref file
MainViewManager.focusActivePane();
});
});
}
});

if (isUpdating) {
// We're just refreshing. Don't need to unwatch the project root, so we can start loading immediately.
startLoad.resolve();
Expand Down

0 comments on commit 68793ab

Please sign in to comment.