diff --git a/build.sh b/build.sh index b05a73c..43ebfc8 100755 --- a/build.sh +++ b/build.sh @@ -1,145 +1,22 @@ #!/bin/bash -# build.sh -- builds JAR and XPI files for mozilla extensions -# by Nickolay Ponomarev -# (original version based on Nathan Yergler's build script) -# Most recent version is at - -# This script assumes the following directory structure: -# ./ -# chrome.manifest (optional - for newer extensions) -# install.rdf -# (other files listed in $ROOT_FILES) -# -# content/ | -# locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS -# skin/ | +# build.sh -- builds JXPI file for seafile filelink extension # -# defaults/ | -# components/ |} these must be listed in $ROOT_DIRS in order to be packaged -# ... | +# Base on a script from mozilla see: # -# It uses a temporary directory ./build when building; don't use that! -# Script's output is: -# ./$APP_NAME.xpi -# ./$APP_NAME.jar (only if $KEEP_JAR=1) -# ./files -- the list of packaged files -# -# Note: It modifies chrome.manifest when packaging so that it points to -# chrome/$APP_NAME.jar!/* - +# usage : +# $ ./build.sh +# will generate seafile_for_filelink-currentbuildtime-tb.xpi # -# default configuration file is ./config_build.sh, unless another file is -# specified in command-line. Available config variables: -APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces -CHROME_PROVIDERS= # which chrome providers we have (space-separated list) -CLEAN_UP= # delete the jar / "files" when done? (1/0) -ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) -ROOT_DIRS= # ...and these directories (space separated list) -BEFORE_BUILD= # run this before building (bash command) -AFTER_BUILD= # ...and this after the build (bash command) - -if [ -z $1 ]; then - . ./config_build.sh -else - . $1 -fi - -if [ -z $APP_NAME ]; then - echo "You need to create build config file first!" - echo "Read comments at the beginning of this script for more info." - exit; -fi - -ROOT_DIR=`pwd` -TMP_DIR=build - -#uncomment to debug -#set -x - -# remove any left-over files from previous build -rm -f $APP_NAME.jar $APP_NAME.xpi files -rm -rf $TMP_DIR - -$BEFORE_BUILD - -mkdir -p -v $TMP_DIR/chrome - -# generate the JAR file, excluding CVS, SVN, and temporary files -JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar -echo "Generating $JAR_FILE..." -rm -f files ; touch files -for CHROME_SUBDIR in $CHROME_PROVIDERS; do - find $CHROME_SUBDIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~ >> files -done - -zip -0 -r $JAR_FILE -@ < files -echo $JAR_FILE > files -# The following statement should be used instead if you don't wish to use the JAR file -#cp --verbose --parents `cat files` $TMP_DIR/chrome - -# prepare components and defaults -echo "Copying various files to $TMP_DIR folder..." -for DIR in $ROOT_DIRS; do - mkdir $TMP_DIR/$DIR - FILES="`find $DIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~`" - echo $FILES >> files - for f in $FILES; do - mkdir -p -v "$TMP_DIR/$(dirname $f)" - cp -v $f "$TMP_DIR/$(dirname $f)/" - done -done - -# Copy other files to the root of future XPI. -for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do - if [ -f $ROOT_FILE ]; then - cp -v $ROOT_FILE $TMP_DIR - echo $ROOT_FILE >> files - fi -done - -cd $TMP_DIR - -if [ -f "chrome.manifest" ]; then - echo "Preprocessing chrome.manifest..." - # You think this is scary? - #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ - #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ - # - # Then try this! (Same, but with characters escaped for bash :) - # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) - - OS=`uname` - - if [ "$OS" == "Darwin" ]; then - # OS X version of sed is not GNU... - sed -i '' -E 's@^(content[ ]+[^ ]*[ ]+)([^ ]*/)$@\1jar:chrome/'$APP_NAME'\.jar\!/\2@' chrome.manifest - sed -i '' -E 's@^(skin|locale)([ ]+[^ ]*[ ]+[^ ]*[ ]+)(.*/)$@\1\2jar:chrome/'$APP_NAME'\.jar\!/\3@' chrome.manifest - - else - - sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest - sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest - - fi - -fi - -# generate the XPI file -echo "Generating $APP_NAME.xpi..." -zip -r ../$APP_NAME.xpi * - -cd "$ROOT_DIR" - -echo "Cleanup..." -if [ $CLEAN_UP = 0 ]; then - # save the jar file - mv $TMP_DIR/chrome/$APP_NAME.jar . -else - rm ./files -fi - -# remove the working files -rm -rf $TMP_DIR -echo "Done!" - -$AFTER_BUILD +# passing a string argument : +# $ ./build sh last +# will generate seafile_for_filelink-last-tb.xpi + +buildid=$1 +[[ "$buildid" == "" ]] && buildid=`date +%Y%m%d` +xpifile=seafile_for_filelink-$buildid-tb.xpi +rm $xpifile +cd cloudfile-seafile@oregpreshaz.eu +zip -r ../$xpifile . -x "CVS" +cd .. +echo -n Created file: +ls "$xpifile" diff --git a/cloudfile-seafile@oregpreshaz.eu/components/nsSeaFile.js b/cloudfile-seafile@oregpreshaz.eu/components/nsSeaFile.js index 41d941f..820afad 100644 --- a/cloudfile-seafile@oregpreshaz.eu/components/nsSeaFile.js +++ b/cloudfile-seafile@oregpreshaz.eu/components/nsSeaFile.js @@ -8,8 +8,8 @@ * nsIMsgCloudFileProvider interface. * This code is based of a YouSendIt implementation: * http://mxr.mozilla.org/comm-central/source/mail/components/cloudfile/nsYouSendIt.js - * - * Edited by Szabolcs Gyuris (szimszon at oregpreshaz dot eu) + * + * Edited by Szabolcs Gyuris (szimszon at oregpreshaz dot eu) */ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; @@ -25,7 +25,7 @@ var kUserInfoPath = "api2/account/info/"; var kRepoPath = "api2/repos/"; function nsSeaFile() { - this.log = Log4Moz.getConfiguredLogger("SeaFile","DEBUG","DEBUG"); + this.log = Log4Moz.getConfiguredLogger("SeaFile","DEBUG","DEBUG"); } nsSeaFile.prototype = { @@ -93,7 +93,7 @@ nsSeaFile.prototype = { this._repoName = this._prefBranch.getCharPref("library"); try { this._libraryCreate = this._prefBranch.getBoolPref("libraryCreate"); - } + } catch (e) { this._libraryCreate = false; this._prefBranch.setBoolPref("libraryCreate", false); @@ -116,7 +116,7 @@ nsSeaFile.prototype = { if (aCallback) aCallback(); }.bind(this); - + let createThunderbirdFolder = function(aParentFolderName) { this._createFolder("mozilla_thunderbird", aParentFolderName, saveFolderName); @@ -185,7 +185,7 @@ nsSeaFile.prototype = { // if we're uploading a file, queue this request. if (this._uploadingFile && this._uploadingFile != aFile) { this.log.info("Adding file ["+this._folderName+"/"+aFile.leafName+"] to queue"); - let uploader = new nsSeaFileFileUploader(this, + let uploader = new nsSeaFileFileUploader(this, this._folderName, aFile, this._uploaderCallback @@ -213,7 +213,7 @@ nsSeaFile.prototype = { }.bind(this); this.log.debug("Checking to see if we're logged in"); - + if (!this._loggedIn) { let onLoginSuccess = function() { this._getUserInfo(onGetUserInfoSuccess, onAuthFailure); @@ -244,14 +244,14 @@ nsSeaFile.prototype = { if (aFile.fileSize > this._maxFileSize) return this._fileExceedsLimit(aCallback, 'Limit', 0); if (aFile.fileSize > this._availableStorage) - return this._fileExceedsLimit(aCallback, 'Quota', + return this._fileExceedsLimit(aCallback, 'Quota', aFile.fileSize + this._fileSpaceUsed); */ delete this._userInfo; // force us to update userInfo on every upload. if (!this._uploader) { this.log.debug("_finishUpload: add uploader"); - this._uploader = new nsSeaFileFileUploader(this, + this._uploader = new nsSeaFileFileUploader(this, aFolderName, aFile, this._uploaderCallback @@ -293,7 +293,7 @@ nsSeaFile.prototype = { */ cancelFileUpload: function nsSeaFile_cancelFileUpload(aFile) { this.log.info("cancelFileUpload("+aFile.leafName+"): in cancel upload"); - if (this._uploadingFile != null && this._uploader != null && + if (this._uploadingFile != null && this._uploader != null && this._uploadingFile.equals(aFile)) { this._uploader.cancel(); } @@ -346,7 +346,7 @@ nsSeaFile.prototype = { if (req.status >= 200 && req.status < 400) { this.log.debug("_createRepo: request status = " + req.status + " response = " + req.responseText); - if ( docResponse.repo_name != repoName || docResponse.repo_id == "") { + if ( docResponse.repo_name != repoName || docResponse.repo_id == "") { let errormsg="_createRepo: Can't create library. Expected name: ["+repoName+"], got: ["+docResponse.repo_name+"], ["+docResponse.repo_id+"]"; this.log.error(errormsg); this._lastErrorText=errormsg; @@ -396,7 +396,7 @@ nsSeaFile.prototype = { let repoDesc="Thunderbird Filelink"; req.send("name="+repoName+"&desc="+repoDesc); }, - + /** * A private function for retreiving the selected repo-id */ @@ -468,7 +468,7 @@ nsSeaFile.prototype = { req.setRequestHeader("Accept", "application/json"); req.send(); }, - + /** * A private function for retrieving profile information about a user. * @@ -649,7 +649,7 @@ nsSeaFile.prototype = { aParentFolderName, aNotFoundCallback, aFoundCallback) { - + this._getRepoId(); let pfolder=aParentFolderName; if (pfolder=="") pfolder="/"; @@ -705,7 +705,7 @@ nsSeaFile.prototype = { req.setRequestHeader("Authorization", "Token "+this._cachedAuthToken + " "); req.setRequestHeader("Accept", "application/json"); req.send(); - + }, @@ -721,7 +721,7 @@ nsSeaFile.prototype = { aSuccessCallback) { this.log.debug("_createFolder("+aName+","+aParent+")"); if (aParent[aParent.lenght-1]!="/") aParent+="/"; - + if (Services.io.offline) throw Ci.nsIMsgCloudFileProvider.offlineErr; @@ -806,7 +806,7 @@ nsSeaFile.prototype = { get remainingFileSpace() (this._availableStorage-this._fileSpaceUsed), get fileSpaceUsed() this._fileSpaceUsed, - + /** * Attempts to delete an uploaded file. * @@ -837,7 +837,7 @@ nsSeaFile.prototype = { req.open("DELETE", gServerUrl + args, true); this.log.debug("deleteFile: Sending delete request to: " + gServerUrl + args); - req.onerror = function() { + req.onerror = function() { let response = JSON.parse(req.responseText); this._lastErrorStatus = req.status; this._lastErrorText = response.detail; @@ -920,7 +920,7 @@ nsSeaFile.prototype = { return ""; }, - + /** * Clears any saved SeaFile passwords for this instance's account. */ @@ -1146,8 +1146,8 @@ nsSeaFileFileUploader.prototype = { let contentType = "multipart/form-data; boundary="+ boundary; req.setRequestHeader("Content-Type", contentType+"; charset=utf-8"); - //let fileName = /^[\040-\176]+$/.test(this.file.leafName) - // ? this.file.leafName + //let fileName = /^[\040-\176]+$/.test(this.file.leafName) + // ? this.file.leafName // : encodeURIComponent(this.file.leafName); let fileName = this.file.leafName; let fileContents = "--" + boundary + @@ -1246,7 +1246,7 @@ nsSeaFileFileUploader.prototype = { this.callback(this.requestObserver, Ci.nsIMsgCloudFileProvider.uploadErr); }.bind(this); - + let uploadInfo=""; req.onload = function() { if (req.status >= 200 && req.status < 400) { @@ -1260,7 +1260,7 @@ nsSeaFileFileUploader.prototype = { }.bind(this); let failed = function() { - this.callback(this.requestObserver, this.file.leafName.length > 120 + this.callback(this.requestObserver, this.file.leafName.length > 120 ? Ci.nsIMsgCloudFileProvider.uploadExceedsFileNameLimit : Ci.nsIMsgCloudFileProvider.uploadErr); }.bind(this); @@ -1281,8 +1281,8 @@ nsSeaFileFileUploader.prototype = { req.setRequestHeader("Authorization", "Token "+this._cachedAuthToken + " "); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); - //let fileName = /^[\040-\176]+$/.test(this.file.leafName) - // ? this.file.leafName + //let fileName = /^[\040-\176]+$/.test(this.file.leafName) + // ? this.file.leafName // : encodeURIComponent(this.file.leafName); let fileName = this.file.leafName; req.send("p="+this.folderName+"/"+fileName); diff --git a/config_build.sh b/config_build.sh deleted file mode 100755 index 947ff18..0000000 --- a/config_build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# Build config for the build script, build.sh. Look there for more info. - -APP_NAME=seafile_for_filelink-last-tb -CHROME_PROVIDERS="content locale" -CLEAN_UP=1 -ROOT_FILES= -ROOT_DIRS="components resources" -BEFORE_BUILD= -BEFORE_PACK= -AFTER_BUILD=