mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-22 01:47:24 +00:00
Merge branch 'release/1.1.0' into connectivity_report
This commit is contained in:
commit
a09680d9b4
35
README.md
35
README.md
@ -107,6 +107,8 @@ Ideally, you would like to have these commands in your PATH
|
||||
|
||||
## Usage examples
|
||||
|
||||
Notice: the commands listed here assume you are using the interactive interaction mode: they are supposed to be executed within MEGAcmdShell.
|
||||
|
||||
* A **synchronization** can be stablished simply by typing:
|
||||
```
|
||||
sync /path/to/local/folder /folder/in/mega
|
||||
@ -116,15 +118,15 @@ This will synchronize the contents in your local and your mega folder both ways.
|
||||
* You can also set remote **backups** of a local folder to keep historical snapshots
|
||||
of your files. So simple as:
|
||||
```
|
||||
backup /path/to/myfolder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
backup /path/mega/folder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
```
|
||||
This will configure a backup of "myfolder" into /remote/path that will be carried out
|
||||
at 4:00 A.M. (UTC) every day. It will store the last 10 copies.
|
||||
Further info on backups [here](contrib/docs/BACKUPS.md).
|
||||
|
||||
* You serve a location via webdav:
|
||||
* You serve a location in your MEGA account via webdav:
|
||||
```
|
||||
webdav /path/to/myfolder
|
||||
webdav /path/mega/folder
|
||||
```
|
||||
|
||||
* Or stream a file in your MEGA account:
|
||||
@ -230,8 +232,11 @@ There are two different kinds of logging messages:
|
||||
- MEGAcmd based: those messages reported by MEGAcmd itself.
|
||||
|
||||
You can adjust the level of logging for those kinds with `log` command.
|
||||
However, for non interactive commands, passing `-v` (`-vv`, `-vvv`, and so on
|
||||
for a more verbose output) will use higher level of verbosity to an specific command.
|
||||
|
||||
However, passing `-v` (`-vv`, `-vvv`, and so on for a more verbose output)
|
||||
to an specific command will use higher level of verbosity of MEGAcmd based messages.
|
||||
|
||||
Further info on verbosity [here](contrib/docs/DEBUG.md).
|
||||
|
||||
## Regular Expressions
|
||||
If you have compiled MEGAcmd with PCRE (enabled by default),
|
||||
@ -252,6 +257,26 @@ take precedence. You will need to either escape symbols like `*` (`\*`)
|
||||
or surround them between quotes (e.g: "*.txt")
|
||||
|
||||
|
||||
## MEGAcmd UPDATES
|
||||
|
||||
MEGAcmd updates automatically for Windows & MacOS.
|
||||
For Linux, whenever there is a new update,
|
||||
it will be published in the corresponding repository and your system's updating tool will let you update it.
|
||||
|
||||
### Disable automatic updates
|
||||
|
||||
You can type `update --auto=OFF` to disable automatic updates. `update --auto=ON` will re-enable them.
|
||||
|
||||
If you want to see the state of automatic updates you can use `update --auto=query`. This will inform if
|
||||
automatic updates are enabled or not.
|
||||
|
||||
Notice that MEGAcmdServer must be running in order to have automatic updates working.
|
||||
|
||||
You can also update manually by typing `update` within MEGAcmd. This will check if there are updates available and
|
||||
proceed to update if affirmative. Whenever MEGAcmd is updated it will be restarted (all open instances of MEGAcmdShell will be restarted too).
|
||||
|
||||
Alternatively you can also execute `MEGAcmdUpdater.exe` in Windows or `MEGAcmdUpdater` (located at /Applications/MEGAcmd.app/Contents/MacOS) in MacOS.
|
||||
|
||||
# Known Bugs
|
||||
- Currently there are certain discrepancies with PATHS when loggin into a public folder.
|
||||
For instance, imagine a folder named `toshare` with a subfolder named `x`. If we login
|
||||
|
@ -96,7 +96,7 @@ Additional information about synchronising folders is available in our Help Cent
|
||||
### Backup configurations
|
||||
MEGAcmd can set up a periodic copy of a local folder to your MEGA account using the [`backup`](#backup) command. Here is a simple example that will back up a folder immediately and then at 4am each day, keeping the 10 most recent backups: <p>
|
||||
```
|
||||
backup /path/to/myfolder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
backup /path/mega/folder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
```
|
||||
|
||||
For further information on backups, please see the [`backup`](#backup) command and the [tutorial](contrib/docs/BACKUPS.md).
|
||||
|
@ -116,11 +116,11 @@ rm -f mega-cmd-server
|
||||
rm -f mega-cmd
|
||||
rm -f mega-cmd-exec
|
||||
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
|
||||
echo "outputs should be 3 files: mega-cmd mega-cmd-server mega-exec. ls output: "
|
||||
ls mega-cmd mega-cmd-server mega-exec
|
||||
|
@ -116,11 +116,11 @@ rm -f mega-cmd-server
|
||||
rm -f mega-cmd
|
||||
rm -f mega-cmd-exec
|
||||
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
|
||||
echo "outputs should be 3 files: mega-cmd mega-cmd-server mega-exec. ls output: "
|
||||
ls mega-cmd mega-cmd-server mega-exec
|
||||
|
@ -115,11 +115,11 @@ rm -f mega-cmd-server
|
||||
rm -f mega-cmd
|
||||
rm -f mega-cmd-exec
|
||||
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include `find sdk/src -name "*.o"` sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
|
||||
echo "outputs should be 3 files: mega-cmd mega-cmd-server mega-exec. ls output: "
|
||||
ls mega-cmd mega-cmd-server mega-exec
|
||||
|
@ -114,11 +114,11 @@ rm -f mega-cmd-server
|
||||
rm -f mega-cmd
|
||||
rm -f mega-cmd-exec
|
||||
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libfreeimage.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
|
||||
echo "outputs should be 3 files: mega-cmd mega-cmd-server mega-exec. ls output: "
|
||||
ls mega-cmd mega-cmd-server mega-exec
|
||||
|
@ -104,11 +104,11 @@ rm -f mega-cmd-server
|
||||
rm -f mega-cmd
|
||||
rm -f mega-cmd-exec
|
||||
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-cmd-server
|
||||
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
|
||||
echo "outputs should be 3 files: mega-cmd mega-cmd-server mega-exec. ls output: "
|
||||
ls mega-cmd mega-cmd-server mega-exec
|
||||
|
@ -194,17 +194,17 @@ echo "CXXFLAGS: $CXXFLAGS"
|
||||
|
||||
if ! [ -e mega-cmd-server ] ; then
|
||||
echo "Attempt to build mega-cmd-server manually"
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a $freeimagelib sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt -o mega-cmd-server
|
||||
$CXX $CXXFLAGS src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp src/comunicationsmanagerfilesockets.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libmediainfo.a sdk/sdk_build/install/lib/libzen.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a $freeimagelib sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt -o mega-cmd-server
|
||||
fi
|
||||
|
||||
if ! [ -e mega-cmd ] ; then
|
||||
echo "Attempt to build mega-cmd manually"
|
||||
$CXX $CXXFLAGS src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/megacmdshell/*.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a ./sdk/sdk_build/install/lib/libreadline.a ./sdk/sdk_build/install/lib/libtermcap.a -o mega-cmd
|
||||
fi
|
||||
|
||||
if ! [ -e mega-exec ] ; then
|
||||
echo "Attempt to build mega-exec manually"
|
||||
$CXX $CXXFLAGS src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
$CXX $CXXFLAGS src/megacmdcommonutils.cpp src/client/*.cpp src/megacmdshell/megacmdshellcommunications.cpp -Isdk/include -Isdk/include/mega/posix -Isdk/sdk_build/install/include sdk/sdk_build/install/lib/libmega.a sdk/sdk_build/install/lib/libcryptopp.a sdk/sdk_build/install/lib/libcurl.a sdk/sdk_build/install/lib/libcares.a sdk/sdk_build/install/lib/libssl.a sdk/sdk_build/install/lib/libcrypto.a sdk/sdk_build/build/libuv-v1.8.0/.libs/libuv.a sdk/sdk_build/install/lib/libsqlite3.a -lpthread -ldl -lrt sdk/sdk_build/install/lib/libz.a -o mega-exec
|
||||
fi
|
||||
|
||||
echo "final return code: $?"
|
||||
|
@ -23,6 +23,7 @@ add_executable(mega-cmd-server
|
||||
"${ProjectDir}/src/megacmdlogger.cpp"
|
||||
"${ProjectDir}/src/megacmdsandbox.cpp"
|
||||
"${ProjectDir}/src/megacmdutils.cpp"
|
||||
"${ProjectDir}/src/megacmdcommonutils.cpp"
|
||||
"${ProjectDir}/src/comunicationsmanager.cpp"
|
||||
"${ProjectDir}/src/comunicationsmanagernamedpipes.cpp"
|
||||
"${ProjectDir}/src/comunicationsmanagerportsockets.cpp"
|
||||
@ -34,12 +35,15 @@ add_executable(mega-exec
|
||||
"${ProjectDir}/src/client/megacmdclient.cpp"
|
||||
"${ProjectDir}/src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp"
|
||||
"${ProjectDir}/src/megacmdshell/megacmdshellcommunications.cpp"
|
||||
"${ProjectDir}/src/megacmdcommonutils.cpp"
|
||||
)
|
||||
|
||||
add_executable(mega-cmd
|
||||
"${ProjectDir}/src/megacmdshell/megacmdshellcommunications.cpp"
|
||||
"${ProjectDir}/src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp"
|
||||
"${ProjectDir}/src/megacmdshell/megacmdshell.cpp"
|
||||
"${ProjectDir}/src/megacmdcommonutils.cpp"
|
||||
|
||||
)
|
||||
|
||||
target_link_libraries(mega-exec Mega )
|
||||
|
@ -1,131 +1,201 @@
|
||||
MEGA LIMITED TERMS OF SERVICE ("TERMS")
|
||||
1. Welcome to MEGA. We are an Internet services provider and provide services made available at our website at https://mega.nz, subdomains and related sites ("website"), which enables users (depending which MEGA plan they are on), amongst other things, to encrypt by way of user controlled encryption ("UCE"), use our application programming interface ("API"), upload, store, manage, download and decrypt files, information, material and other data ("data") and give access to that data to others (all together, services). If you have questions about how to use our services or the great things you can do with Mega, see our FAQ first.
|
||||
2. These terms are binding and apply to any use of the services and website by you and anyone that you allow to access your data or our services. By using our services or the website, you and they irrevocably agree to these terms. If you do not like these terms or don't want to be bound, you can't use our services and the website.
|
||||
3. We can change these terms at any time and we will provide you notice of the change, whether via our website, by sending you an email or via any messaging service we provide. Your continued use after that notice means that you agree to the changed terms.
|
||||
4. If you comply with these terms, then we grant you a non-exclusive, non-transferable, worldwide licence to access and use our service via the website in accordance with these terms and any plan you have subscribed for.
|
||||
|
||||
Scope of these terms
|
||||
|
||||
1. Welcome to Mega. Mega Limited ("Mega", "we", "us") provides cloud storage and communication services with user-controlled encryption. We provide services ourselves and via our related or affiliated entities, payment processors and resellers who act on our behalf, at our website at https://mega.nz, subdomains and related sites ("website"), using our mobile apps ("mobile apps"), and our application programming interface ("API"). Using Mega, you and other users can encrypt your files and data by way of user-controlled encryption ("UCE"), upload, access, store, manage, share, communicate, download and decrypt files, information, material, text chats, voice chats, video chats and other data (all of which we call "data" in these terms) and give access to that data to others (all together, "services" and each, a "service"). If you have questions about how to use our services or the great things you can do with Mega, check our Help Centre or, if you can't find the answer there, check our contacts page for details of who to contact.
|
||||
2. These terms are binding and apply to any use of the services, website and our mobile apps by you and anyone who you allow to access your data or our services. By using our services, the website or our mobile apps, you and they irrevocably agree to these terms. If you do not like these terms or don't want to be bound, you can't use our services, the website or our mobile apps. In particular, OUR SERVICES ARE PROVIDED SUBJECT TO CERTAIN DISCLAIMERS BY US AND UNDERTAKINGS BY YOU, INCLUDING AN INDEMNITY FROM YOU IF YOU BREACH THESE TERMS - see clauses 37-48. NEW ZEALAND LAW AND ARBITRATION OF ANY DISPUTES APPLIES EXCLUSIVELY - see clauses 49 and 50.
|
||||
3. We can change these terms at any time by providing you at least 30 days' prior notice of the change, whether via our website, via our mobile apps, by sending you an email or via any messaging service we provide. Your continued use after that notice means that you agree to the changed terms. If you have paid for a subscription that is due to expire after that 30 day notice period and you do not wish to continue to use our services under the new terms, you may terminate your subscription before the new terms come into force. We will then (but not otherwise) refund the unexpired portion of your subscription payment within 30 days and close your account. For more information about refunds, recurring paid subscriptions and their termination, see clauses 55-57.
|
||||
4. If you comply with these terms, then we grant you a non-exclusive, non-transferable, worldwide licence to access and use our services via the website, our mobile apps and our API if applicable, in accordance with these terms and any plan you have subscribed for.
|
||||
|
||||
Your data
|
||||
|
||||
5. If you allow others to access your data (e.g. by, amongst other things, giving them a link to, and a key to decrypt, that data), in addition to them accepting these terms, you are responsible for their actions and omissions while they are using the website and services and you agree to fully indemnify us for any claim, loss, damage, fine, costs (including our legal fees) and other liability if they breach any of these terms.
|
||||
6. Our service includes UCE. You should keep your encryption keys safe and confidential and not release them to anyone unless you wish them to have access to your data. If you lose or misplace your encryption keys, you will lose access to your data. We strongly urge you to use robust anti-virus and firewall protection.
|
||||
7. You must maintain copies of all data stored by you on our service. We do not make any guarantees that there will be no loss of data or the services will be bug free. You are completely responsible to remove all data prior to termination of services.
|
||||
8. Our service may automatically delete a piece of data you upload or give someone else access to where it determines that that data is an exact duplicate of original data already on our service. In that case, you will access that original data.
|
||||
9. We will store your data on our service subject to these terms and any plan you subscribe to. If you choose to stop using our services, you need to make sure you retrieve your data first because, after that, we may, if we wish, delete it. If we suspend our services to you because you or someone you have given access to has breached these terms, during the term of that suspension, we may if we wish deny you access to your data. If we terminate our services to you because you or someone you have given access to has breached these terms, we may if we wish delete your data immediately. In circumstances where we cease providing all our services for other reasons, we will, if reasonably practicable and we are not prevented by law from doing so, give you 30 days access to retrieve your data.
|
||||
5. If you allow others to access your data (e.g. by giving them a link to, and a key to decrypt, that data), in addition to them accepting these terms, you are responsible for their actions and omissions while they are using our services and you agree to fully indemnify us for any claim, loss, damage, fine, costs (including our legal fees) and other liability if they breach any of these terms. This is particularly the case where you are the administrator of a business account (see clauses 51-54 below).
|
||||
6. UCE is fundamental to our services. This means that you, not us, have encrypted control of who has access to your data. You should keep your password and Recovery Key safe and confidential. You must not share your password with anyone else and should not release encryption keys to anyone else unless you wish them to have access to your data. If you lose or misplace your password, you will lose access to your data. Encryption won't help though if someone has full access to your system or device. We strongly urge you to use best practices for ensuring the safety and security of your system and devices (e.g. via unique passwords, security upgrades, firewall protection, anti-virus software, securing and encrypting your devices). Mega will never send you emails asking for your password or suggesting that you click a link to login to your account, so do not be fooled by any such email since it will not be from us.
|
||||
7. You must maintain copies of all data stored by you on our services. We do not make any guarantees that there will be no loss of data or the services will be bug free. You should download all data prior to termination of services.
|
||||
8. Our service may automatically (without us viewing the file content) delete a file you upload, store, access or share where it determines that the file is an exact duplicate of a file already on our service (a process usually referred to as deduplication). In that case, the original file will be accessed by you and any other user and that file will be retained as long as any user has a right to access it under these terms. Any right of deletion that you exercise will not apply to a deduplicated file that is associated with another user.
|
||||
9. We will store your data on our service subject to these terms and any plan you subscribe to. If you choose to stop using our services, you must download your data first because after that we may, if we wish, delete it.
|
||||
If we suspend or terminate our services to you because you have breached these terms, or someone you have given access to has breached these terms, during the term of that suspension we may, if we wish, delete your data immediately or deny you access to your data but keep it for evidential purposes. See also clauses 51-54 below which set out details of what happens to users within a business account when the business account is suspended or terminated.
|
||||
In circumstances where we cease providing our services for other reasons, we will, if we consider it appropriate, it is reasonably practicable and we are not prevented by law or likely to incur any liability in doing so, give you 30 days' notice to retrieve your data.
|
||||
|
||||
What does it cost you?
|
||||
Your obligations
|
||||
|
||||
10. Once you have purchased a plan for our services, you need to pay the fees (if any) for that plan (and any other taxes or duties). We can also change the fees for our services at any time if we give you notice. You can't withhold payment for any reason or claim any set-off without getting our written agreement.
|
||||
11. If at any time you do not make a payment to us when you are supposed to (including on termination), we can (and this doesn't affect any other rights we may have against you)...
|
||||
11.1 ...make you pay, on demand, default interest on any amount you owe us at 10% per annum calculated on a daily basis, from the date when payment was due until the date when payment is actually made by you. You will also need to pay all expenses and costs (including our legal costs) in connection with us trying to recover any unpaid amount from you; and/or
|
||||
11.2 ...suspend or terminate your use of the service.
|
||||
10. Once you have subscribed to a plan for our services (with payment having been made via the website, one of our mobile apps or one of our related or affiliated entities, payment processors and resellers), you need to pay the fees (if any) for that plan (and any other taxes or duties). No matter which reseller or related or affiliated entity of Mega you make payment to, your contract for services is with Mega Limited and is governed exclusively by these terms and our policies referenced in these terms. We can also change the fees for our services (other than those you have already contracted and paid for) at any time if we give you notice. In the absence of manifest error or other lawful error, you can't withhold payment or claim any set-off without getting our written agreement.
|
||||
11. If at any time you do not make a payment to us when you are supposed to (including on termination), we can (and this doesn't affect any other rights we may have against you):
|
||||
11.1. suspend or terminate your use of the service and/or;
|
||||
11.2. make you pay, on demand, default interest on any amount you owe us at 10% per annum calculated on a daily basis, from the date when payment was due until the date when payment is actually made by you. You will also need to pay all expenses and costs (including our full legal costs) in connection with us trying to recover any unpaid amount from you.
|
||||
12. You must:
|
||||
12.1 make sure you always give us and keep up to date your correct contact and billing details, particularly if these change;
|
||||
12.2 comply with these terms and any other agreements you have with us;
|
||||
12.3 make sure that you comply with all laws and rules that relate to your use of the website, the service and any data you upload to our service.
|
||||
12.1. where you have subscribed for a service, always give us and keep up to date, your correct contact and any billing details and those of any users within a business account;
|
||||
12.2. comply with these terms and any other agreements you have with us and ensure that users within a business account, of which you are administrator, do likewise;
|
||||
12.3. comply with all applicable laws, regulations and rules when using the website, our services and with respect to any data you upload, access or share using our services and ensure that users within a business account, of which you are administrator, do likewise.
|
||||
|
||||
What you can't do
|
||||
|
||||
13. You can't, and will ensure that no users within a business account, of which you are administrator:
|
||||
13.1. assign or transfer any rights you have under these terms to any other person (including by sharing your password with someone else) without our prior written consent;
|
||||
13.2. do anything that would damage, disrupt or place an unreasonable burden on our website or service or anyone else's use of our website, our mobile apps or a service including but not limited to denial of service attacks or similar;
|
||||
13.3. infringe anyone else's intellectual property (including but not limited to copyright) or other rights in any data;
|
||||
13.4. resell or otherwise supply our services to anyone else without our prior written consent;
|
||||
13.5. open multiple free accounts;
|
||||
13.6. use our website, mobile apps, API, or any service, including, without limitation, any communication tools available through the website, our mobile apps, or our API, or any forum, chat facility or message centre that we provide:
|
||||
13.6.1. to store, use, download, upload, share, access, transmit, or otherwise make available, data in violation of any law in any country (including to breach copyright or other intellectual property rights held by us or anyone else);
|
||||
13.6.2. to send unwelcome communications of any kind (including but not limited to unlawful unsolicited commercial communications) to anyone (e.g. spam or chain letters);
|
||||
13.6.3. to abuse, defame, threaten, stalk or harass anyone, or to harm them as defined in the Harmful Digital Communications Act 2015 (NZ) or any similar law in any jurisdiction;
|
||||
13.6.4. to store, use, download, upload, share, access, transmit, or otherwise make available, unsuitable, offensive, obscene or discriminatory information of any kind;
|
||||
13.6.5. to run any network scanning software, spiders, spyware, robots, open relay software or similar software;
|
||||
13.6.6. to upload anything or otherwise introduce any spyware, viruses, worms, trojan horses, time bombs or bots or any other damaging items which could interfere with our, or anyone else's, network, device or computer system;
|
||||
13.6.7. to use any software or device which may hinder the services (like mail bombs, war dialing, automated multiple pinging etc.);
|
||||
13.6.8. to attempt to gain unauthorised access to any services other than those to which you have been given express permission to access; or
|
||||
13.6.9. to impersonate anyone or to try to trick or defraud anyone for any reason (e.g. by claiming to be someone you are not).
|
||||
14. If you register with us, you will need to use a password in conjunction with your specific account email address. You need to make sure your password is secure, not used by you on other sites and confidential. Make sure you tell us straight away if you think or know someone else has used your password or there has been any other security breach. We will hold you responsible for anything done using your account and password. MAKE YOUR PASSWORD A STRONG ONE AND KEEP IT SECURE. We are not responsible if someone else gains access to your computer or other device and/or your Mega password and/or encryption keys for any files.
|
||||
|
||||
Intellectual Property
|
||||
|
||||
Our IP
|
||||
|
||||
13. The license that we give you to use the website and our services does not give you the right, and you can't reproduce or use any of our copyright, intellectual property or other rights other than for the purposes of using the services and the website or as allowed under any open source licences under which we use intellectual property provided by others. The open source code that we use, where we obtained it, and licences for that code are all referenced in our FAQ.
|
||||
14. You are not allowed to, and you can't let anyone else, copy, alter, distribute, display, licence, modify or reproduce, reverse assemble, reverse compile (whether digitally, electronically, by linking, or in hard copy or by any means whatsoever) or use any of our copyright, intellectual property or other rights without getting our permission first in writing, unless in order to use our services and the website or as allowed under any open source licences under which we use intellectual property provided by others. The open source code that we use, where we obtained it, and licences for that code are all referenced in our FAQ.
|
||||
15. Without limiting any other provision of these terms, you are only permitted to use the API if you register at the developer registration page and agree that you may only publish or make available your application after we have approved it pursuant to our application approval process and license agreement available on request at api@mega.nz.
|
||||
15. You are not allowed to, and you can't let anyone else (including in particular any user within a business account of which you are administrator), use, copy, alter, distribute, display, licence, modify or reproduce, reverse assemble, reverse compile, communicate, share, transmit or otherwise make available, (whether digitally, electronically, by linking, or in hard copy or by any means whatsoever), any of our code, content, copyright materials, intellectual property or other rights without getting our permission in writing, other than in order to use our services as intended or as allowed under any open source licences under which we use intellectual property provided by others. The open source code that we use, where we obtained it, and licences for that code, are all referenced on our website and via our mobile apps.
|
||||
16. Without limiting any other provision of these terms, you are only permitted to directly and specifically use the API if you register at the developer registration page and agree that you may only publish or make available your application after we have approved it pursuant to our application approval process and licence agreement available on request at api@mega.nz
|
||||
|
||||
Your IP
|
||||
|
||||
16. You own, or warrant that you are authorised to use, any intellectual property in any data you store on, use, download, upload or otherwise transmit to or from, our service. You grant us a worldwide, royalty free licence to use, store, back-up, copy, transmit, distribute, communicate and otherwise make available, your data, for the purposes of enabling you and those you give access to, to use the website and the services and for any other purpose related to provision of the services to you.
|
||||
17. You own, or undertake that you are authorised to use, any intellectual property in any data you store on, use, download, upload, share, access, transmit or otherwise make available to or from, our systems or using our services. You grant us a worldwide, royalty-free licence to use, store, back-up, copy, transmit, distribute, communicate, modify and otherwise make available, your data, solely for the purposes of enabling you and those you give access to, to use our services and for any other purpose related to provision of the services to you and them.
|
||||
|
||||
What you can't do
|
||||
Copyright Infringement Notices
|
||||
|
||||
17. You can't:
|
||||
17.1 assign or transfer any rights you have under these terms to any other person without getting our written agreement;
|
||||
17.2 do anything that would damage, disrupt or place an unreasonable burden on our website or service or anyone else's use of our website or a service including but not limited to denial of service attacks or similar;
|
||||
17.3 infringe anyone else's intellectual property (including but not limited to copyright) or other rights in any material.
|
||||
17.4 resell or otherwise supply our services to anyone else without our prior written consent;
|
||||
17.5 use our website or a service, including, without limitation, any communication tools available through the website, or any forum, chat room or message centre that we provide:
|
||||
17.5.1 to store, use, download, upload or otherwise transmit, data in violation of any law (including to breach copyright or other intellectual property held by us or anyone else);
|
||||
17.5.2 to send unwelcome communications of any kind (including but not limited to unlawful unsolicited commercial communications) to anyone (e.g. spam or chain letters);
|
||||
17.5.3 to abuse, defame, threaten, stalk or harass anyone;
|
||||
17.5.4 to store, use, download, upload or otherwise transmit, unsuitable, offensive, obscene or discriminatory information of any kind;
|
||||
17.5.5 to run any network scanning software, spiders, spyware, robots, open relay software or similar software;
|
||||
17.5.6 to upload anything or otherwise introduce any spyware, viruses, worms, trojan horses, time bombs or bots or any other damaging items which could interfere with our, or anyone else's, network or computer system;
|
||||
17.5.7 to use any software or device which may hinder the services (like mail bombs, war dialing, pinging etc.);
|
||||
17.5.8 to attempt to gain unauthorised access to any services other than those to which you have been given express permission to access; or
|
||||
17.5.9 to try to trick or defraud anyone for any reason (e.g. by claiming to be someone you are not).
|
||||
18. If you register with us, we will provide you with a password to associate with your specific username. You need to make sure your username and password is secure and confidential. Make sure you tell us straight away if you think or know someone else has used your password or there has been any other security breach. We will hold you responsible for anything done using your username and password. MAKE YOUR PASSWORD A STRONG ONE AND KEEP IT SECURE.
|
||||
18. We respect the copyright of others and require that users of our services comply with copyright laws. You are strictly prohibited from using our services to infringe copyright. You may not upload, download, store, share, access, display, stream, distribute, e-mail, link to, communicate, transmit, or otherwise make available any files, data, or content that infringes any copyright or other proprietary rights of any person or entity.
|
||||
19. We will respond to notices of alleged copyright infringement that comply with applicable law and are properly provided to us. If you believe that your content has been copied or used in a way that constitutes copyright infringement, please provide us with the following information:
|
||||
i. a physical or electronic signature of the copyright owner or a person authorised to act on their behalf;
|
||||
ii. identification of the copyrighted work claimed to have been infringed;
|
||||
iii. identification of the material that is claimed to be infringing or to be the subject of infringing activity and that is to be removed or access to which is to be disabled, and information reasonably sufficient to permit us to locate the material including the exact URL link (with decryption key) to that material on Mega;
|
||||
iv. your contact information, including your address, telephone number, and an email address; a statement by you that you have a good faith belief that use of the material in the manner complained of is not authorised by the copyright owner, its agent, or the law; and
|
||||
v. a statement that the information in the notification is accurate, and, under penalty of perjury (unless applicable law says otherwise), that you are authorised to act on behalf of the copyright owner.
|
||||
20. We reserve the right to remove data alleged to be infringing without prior notice, at our sole discretion, and without liability to you. In appropriate circumstances, we will also terminate your account if we consider you to be a repeat infringer. Details of our designated copyright agent for notice of alleged copyright infringement are on our contacts page.
|
||||
|
||||
Infringement Notices
|
||||
Copyright Counter-Notices
|
||||
|
||||
19. We respect the copyright of others and require that users of our services comply with the laws of copyright. You are strictly prohibited from using our services to infringe copyright. You may not upload, download, store, share, display, stream, distribute, e-mail, link to, transmit or otherwise make available any files, data, or content that infringes any copyright or other proprietary rights of any person or entity.
|
||||
We will respond to notices of alleged copyright infringement that comply with applicable law and are properly provided to us. If you believe that your content has been copied or used in a way that constitutes copyright infringement, please provide us with the following information: (i) a physical or electronic signature of the copyright owner or a person authorized to act on their behalf; (ii) identification of the copyrighted work claimed to have been infringed; (iii) identification of the material that is claimed to be infringing or to be the subject of infringing activity and that is to be removed or access to which is to be disabled, and information reasonably sufficient to permit us to locate the material including for example the uniform resource locator(s) (URL); (iv) your contact information, including your address, telephone number, and an email address; (v) a statement by you that you have a good faith belief that use of the material in the manner complained of is not authorized by the copyright owner, its agent, or the law; and (vi) a statement that the information in the notification is accurate, and, under penalty of perjury (unless applicable law says otherwise), that you are authorized to act on behalf of the copyright owner.
|
||||
We reserve the right to remove data alleged to be infringing without prior notice, at our sole discretion, and without liability to you. In appropriate circumstances, we will will also terminate your account if you are determined to be a repeat infringer. Our designated copyright agent for notice of alleged copyright infringement is:
|
||||
Mega Limited Copyright Agent:
|
||||
Hana Svobodova
|
||||
Private Bag 92533 Wellesley St
|
||||
Auckland 1141
|
||||
New Zealand
|
||||
copyright@mega.nz
|
||||
Copyright Counter Notices
|
||||
21. We process all takedown notices based on good faith acceptance of the representations from the party submitting the takedown notice. We do not review the material before processing the takedown notice.
|
||||
22. You may file a counter-notice if you believe that access to a file you have uploaded has been wrongly disabled because it was the subject of an incorrect takedown notice. You should only do so if you are confident that no other party owns copyright in the material, or you have rights to store the material and, if you are sharing it, that you have the right to do so.
|
||||
23. Please understand that:
|
||||
23.1. When we receive your counter-notice, we pass it, including your address and other contact information, to the party who issued the original takedown notice. By submitting your counter-notice you authorise us to do so.
|
||||
23.2. Filing a counter-notification may lead to legal proceedings between you and the complaining party.
|
||||
23.3. There may be adverse legal consequences in New Zealand and/or your jurisdiction if you make a false or bad faith allegation by using this process.
|
||||
23.4. If, when using this counter-notice process, you make a false or bad faith allegation or otherwise breach these terms or any of our policies and that causes us any loss, costs (including legal costs), damages or other liability, we reserve the right to claim for and recover from you that loss, those costs (including full legal costs on a solicitor-client basis), damages and other liability, by deduction from any balance in our account and/or by proceedings in New Zealand and/or the jurisdiction of the address in your counter-notice.
|
||||
23.5. We provide this counter-notice process voluntarily for the purposes of all applicable copyright takedown and counter-notice regimes in New Zealand and other jurisdictions, but, in doing so, we do not submit to any jurisdiction, law, tribunal or court other than those of New Zealand, as set out in these terms. We may amend, suspend or withdraw this counter-notice process at any time, provided that any counter-notices in train at that time shall continue to be processed.
|
||||
24. By filing a counter-notice, you are deemed to have accepted the above terms. If you do not accept the above terms, do not file a counter-notice.
|
||||
25. To file a counter-notice with us, you must provide a written communication at https://mega.nz/copyright or by email to copyright@mega.nz that includes substantially the following:
|
||||
25.1. Identification of the specific URL(s) of material that has been removed or to which access has been disabled.
|
||||
25.2. Your full name, address, telephone number, email address and the username of your Mega account.
|
||||
25.3. The statement: "I have a good faith belief that the material was removed or disabled as a result of a mistake or misidentification of the material to be removed or disabled."
|
||||
25.4. The reasons for that good faith belief, sufficient to explain the mistake or misidentification to the person who filed the original takedown notice.
|
||||
25.5. The statement "I will accept service of proceedings in New Zealand or in the jurisdiction where my address in this counter-notice is located, from the person who provided Mega Limited with the original copyright takedown notice or an agent of such person."
|
||||
25.6. Signature. A scanned physical signature or usual signoff in an email or using our webform will be accepted.
|
||||
25.7. You may also provide comments.
|
||||
26. We will only accept a counter-notification directly from the user from whose account a folder or file has been disabled. Counter-notifications must be submitted from the email address associated with the Mega account.
|
||||
27. If we do not receive any further communication from or on behalf of the person who originally submitted the takedown notice, or any communication we do receive does not in our sole opinion adequately justify the original takedown notice, we may, but shall not be obliged to, reinstate the material in approximately 10-14 days provided we have no reason to believe that the material infringes copyright.
|
||||
28. Nothing in this counter-notice section prejudices our right to remove or disable access to any material at any time, for any reason or no reason.
|
||||
|
||||
Other Infringement Notices
|
||||
|
||||
29. If you consider there has been some other infringement or breach of law, or of these terms, and wish to file a complaint, contact us at the relevant address on our contacts page. We will generally require the same amount of detail as set out above for copyright infringement notices. See also our Takedown Guidance Policy.
|
||||
|
||||
20. To file a counter-notification with us, you must provide a written communication to copyright@mega.nz that sets forth the items specified below. Please understand that filing a counter-notification may lead to legal proceedings between you and the complaining party to determine ownership. Be aware that there may be adverse legal consequences in your country if you make a false or bad faith allegation by using this process. The location of the original claimant, and whether or not it was submitted under United States law (governed by the United States Digital Millennium Copyright Act, Section 512 g), determines which if any type of counter-notification you may file. A counter-notification must include at least the following specific elements and any other elements required by applicable law: Identification of the specific URLs of material that has been removed or to which access has been disabled. Your full name, address, telephone number, email address and the username of your MEGA account. The statement "I will accept service of process from the person who provided MEGA with the original copyright complaint or an authorised agent of such person." The statement: "I have a good faith belief that the material was removed or disabled as a result of a mistake or misidentification of the material to be removed or disabled." Signature. A scanned physical signature or a valid electronic signature will be accepted. We can only accept a counter-notification directly from the user from whose account a URL or file has been disabled. For verification, we require that counter-notifications be submitted from the email address associated with the account. Our preferred method of counter-notification submission is via email to copyright@mega.nz After we receive your counter notification, we will forward it to the party who submitted the original claim of copyright infringement. Please note that when we forward the counter notification, it includes your personal information. By submitting a counter notification, you consent to having your information revealed in this way.
|
||||
If you are filing the counter notice under the DMCA please add the following elements to your counter notice: State that you consent to the jurisdiction of the U.S. Federal District Court for the judicial district in which your address is located; State that you will accept service of process from the person (or an agent of such person) who provided the DMCA Notice to us. Include the following statement above your signature: "I swear under penalty of perjury, that I have a good faith belief that the material identified above was removed or disabled as a result of a mistake or misidentification of the material to be removed or disabled".
|
||||
Suspension and Termination
|
||||
21. You can terminate your access to the website and our services at any time by sending an email to support@mega.nz requesting termination. However, we will not provide any part- refund for any time not used on any subscription you may have.
|
||||
22. We can immediately suspend or terminate your access to the website and our services without notice to you if you breach any of these terms or any other agreement you have with us. If you are not a registered user, we may suspend or terminate your access to website and our service at any time, without notice to you.
|
||||
23. We may also terminate or suspend our services or any part of our services, for all users or for groups of users, at any time and for any reason or no reason.
|
||||
24. All charges outstanding on your account must be paid at termination.
|
||||
|
||||
Communication Conditions
|
||||
|
||||
25. As with any other web-based forum, you must exercise caution when using any communication tools available on the website. However, while we are not obligated to, we have the right to remove any communication at any time, for any reason or no reason, without any liability to you.
|
||||
30. You can terminate your access to our services at any time by following the 'Cancel your account' link in the Account section of the website or the Settings section of our mobile apps. However, we will not provide any part-refund for any allowance not used on any subscription you may have, other than under clause 3 above. If you are a business account administrator you may also terminate access to any user within the business account.
|
||||
31. We can immediately suspend or terminate your, and that of other users within a business account, , access, to the website and our services without notice to you:
|
||||
31.1. if you or they breach any of these terms or any other agreement you or they have with us;
|
||||
31.2. at any time if you are not a registered user;
|
||||
31.3. if you are using a free account and that account has been inactive for over 3 months or we have been unable to contact you using the email address in your account details.
|
||||
32. We may also terminate or suspend our services or any part of our services, for all users or for groups of users, without notice, at any time, for any reason or no reason.
|
||||
33. All charges outstanding on your account must be paid at termination.
|
||||
|
||||
Export Control
|
||||
|
||||
26. You may not use, export, re-export, import, or transfer any software or code suplied as part of your use of the website or our services: (a) into any United States or New Zealand embargoed countries ; or (b) to anyone listed as a specifically prohibited recipient by the United States Government or New Zealand Government. By using the website and our services, you represent and warrant that you are not located in any such country or on any such list. You also will not use the website or our services for any purpose prohibited by United States, New Zealand or any other law, including, without limitation, the development, design, manufacture or production of missiles, nuclear, chemical or biological weapons.
|
||||
34. You may not use, export, re-export, import, or transfer any software or code supplied as part of your use of our services: (a) into any United States or New Zealand embargoed countries; or (b) to anyone listed as a specifically prohibited recipient by the United States Government or the New Zealand Government. By using the website and our services, you represent and warrant that you are not located in any such country or on any such list. You also will not use the website or our services for any purpose prohibited by United States, New Zealand or any other law, including, without limitation, the development, design, manufacture or production of missiles, nuclear, chemical or biological weapons.
|
||||
|
||||
Severability and Waiver
|
||||
|
||||
27. If any provision of these terms is held to be invalid or unenforceable, the remaining provisions will remain in full force and effect. If we do not enforce any right or provision of these terms or if we in any instance grant any concession or indulgence, that will not be deemed a waiver of such right or provision or obligate us to grant any concession or indulgence to anyone else.
|
||||
35. If any provision of these terms is held to be invalid or unenforceable, the remaining provisions will remain in full force and effect. If we do not enforce any right or provision of these terms or if we in any instance grant any concession or indulgence, that will not be deemed a waiver of such right or provision or obligate us to grant any concession or indulgence to anyone else.
|
||||
|
||||
Force Majeure
|
||||
|
||||
28. We will not be liable by reason of any failure or delay in the performance of our obligations because of events beyond our reasonable control, which may include, without limitation, denial-of-service attacks, strikes, shortages, riots, insurrection, fires, flood, storm, explosions, acts of God, war, terrorism, governmental action, labour conditions, earthquakes, material shortages, extraordinary internet congestion or extraordinary connectivity issues or failure of a third party host, (each a "Force Majeure Event"). Upon the occurrence of a Force Majeure Event, we will be excused from any further performance of the obligations which are affected by that Force Majeure Event for so long as the event continues.
|
||||
|
||||
Entire Agreement
|
||||
|
||||
29. These terms, our Privacy policy, the terms of any plan you purchase and any other provisions expressly referenced in these terms, together constitute the entire agreement between us relating to your use of the website and our services. They supersede and replace any prior agreement, arrangement or understanding between you and us regarding the webiste and our services.
|
||||
36. We will not be liable by reason of any failure or delay in the performance of our obligations because of events beyond our reasonable control, which may include, without limitation, denial-of-service attacks, strikes, shortages, riots, insurrection, fires, flood, storm, explosions, acts of God, war, terrorism, governmental action, labour conditions, earthquakes, material shortages, extraordinary internet congestion or extraordinary connectivity issues or failure of a third party host, (each a "Force Majeure Event"). Upon the occurrence of a Force Majeure Event, we will be excused from any further performance of the obligations which are affected by that Force Majeure Event for so long as the event continues.
|
||||
|
||||
DISCLAIMERS
|
||||
30. WE DON'T GIVE YOU ANY WARRANTY OR UNDERTAKING ABOUT THE SERVICES OR THE WEBSITE WHICH ARE PROVIDED "AS IS". TO AVOID DOUBT, ALL IMPLIED CONDITIONS OR WARRANTIES ARE EXCLUDED AS MUCH AS IS PERMITTED BY LAW, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR PURPOSE, SAFETY, RELIABILITY, DURABILITY, TITLE AND NON-INFRINGEMENT.
|
||||
31. We will try to give you access to our website all the time, but we do not make any promises or provide you with a warranty that our website or the services will be without any faults, bugs or interruptions.
|
||||
32. Whilst we intend that the services should be available 24 hours a day, seven days a week, it is possible that on occasions the website or services may be unavailable to permit maintenance or other development activity to take place or be periodically interrupted for reasons outside our control.
|
||||
33. Information on our website will change regularly. We will try to keep our website up to date and correct, but again, we do not make any promises or guarantees about the accuracy of the information on our website.
|
||||
34. We do not warrant that the services will meet your requirements or that they will be suitable for any particular purpose. It is your sole responsibility to determine that the services meet the needs of your business or otherwise and are suitable for the purposes for which they are used.
|
||||
35. We also aren't legally responsible for:
|
||||
35.1 any corruption or loss of data or other content which you or anyone else may experience after using our website, or any problems you may have when you view or navigate our website;
|
||||
35.2 devices or equipment that we do not own or have not given you;
|
||||
35.3 if you do not follow our instructions or these terms or our Privacy Policy;
|
||||
35.4 any actions or non-actions of other people which disrupt access to our website including the:
|
||||
35.4.1 content of any data;
|
||||
35.4.2 content of ads appearing on our website (including links to advertisers' own websites) as the advertisers are responsible for the ads (we don't endorse the advertisers' products);
|
||||
35.4.3 content of other people's websites even if a link to their website is included on our website (we just include the links for convenience to you).
|
||||
36. You warrant that if you are accessing and using the services for the purposes of a business then, to the maximum extent permitted by law, any statutory consumer guarantees or legislation intended to protect non-business consumers in any jurisdiction (such as the Consumer Guarantees Act 1993 in New Zealand) do not apply to the supply of the services, the website or these terms.
|
||||
|
||||
37. WE DON'T GIVE YOU ANY WARRANTY OR UNDERTAKING ABOUT THE SERVICES OR THE WEBSITE WHICH ARE PROVIDED "AS IS". TO AVOID DOUBT, ALL IMPLIED CONDITIONS OR WARRANTIES ARE EXCLUDED AS MUCH AS IS PERMITTED BY LAW, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR PURPOSE, SAFETY, RELIABILITY, DURABILITY, TITLE AND NON-INFRINGEMENT.
|
||||
38. We will try to give you access to our website and our mobile apps all the time, but we do not make any promises or provide you with a warranty that our website or the services will be without any faults, bugs or interruptions.
|
||||
39. Whilst we intend that the services should be available 24 hours a day, seven days a week, it is possible that on occasions the website or services may be unavailable to permit maintenance or other development activity to take place or be periodically interrupted for reasons outside our control.
|
||||
40. Information on our website will change regularly. We will try to keep our website up to date and correct, but again, we do not make any promises or guarantees about the accuracy of the information on our website.
|
||||
41. We do not warrant that the services will meet your requirements or that they will be suitable for any particular purpose.
|
||||
42. You are the controller in respect of some data Mega holds about you and Mega is the processor, for General Data Protection Regulation ("GDPR") purposes. Mega is the controller in respect of some other data. See our Privacy & Data Policy for more details. These terms, our Privacy & Data Policy and our Takedown Guidance Policy are the contract between us that governs our processing of that data. It is your sole responsibility to determine that the services meet the needs of you, your business or otherwise and are suitable for the purposes for which they are used.
|
||||
43. We also aren't legally responsible for:
|
||||
43.1. any corruption or loss of data or other content which you or anyone else may experience after using our website or our mobile apps, or any problems you may have when you view or navigate our website or use any of our mobile apps;
|
||||
43.2. devices or equipment that we do not own or have not given you;
|
||||
43.3. any loss or damage if you do not follow our reasonable instructions, these terms, our Privacy & Data Policy and our Takedown Guidance Policy;
|
||||
43.4. any actions or non-actions of other people which disrupt access to our website, our mobile apps, or our API, including the
|
||||
43.4.1. content and nature of any data that you upload, access or share;
|
||||
43.4.2. content of ads appearing on our website or our mobile apps (including links to advertisers' own websites) as the advertisers are responsible for the ads and we don't endorse the advertisers' products;
|
||||
43.4.3. content of other people's websites even if a link to their website is included on our website or our mobile apps.
|
||||
44. You warrant that if you are accessing and using the services for the purposes of a business then, to the maximum extent permitted by law, any statutory consumer guarantees or legislation intended to protect non-business consumers in any jurisdiction (such as the Consumer Guarantees Act 1993 in New Zealand) do not apply to the supply of the services, the website, our mobile apps or these terms.
|
||||
|
||||
LIMITATION OF LIABILITY AND INDEMNITY BY YOU
|
||||
37. TO THE MAXIMUM EXTENT PERMITTED BY LAW, WE (THIS INCLUDES OUR EMPLOYEES, OFFICERS, AGENTS AND AUTHORISED RESELLERS) ARE NOT LIABLE WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), EQUITY OR ON ANY OTHER GROUNDS TO YOU OR ANYONE ELSE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGE, LOSS, COST OR EXPENSE, DAMAGE TO PROPERTY, INJURY TO PERSONS, LOSS OF PROFITS, LOSS OF DATA OR REVENUE, LOSS OF USE, LOST BUSINESS OR MISSED OPPORTUNITIES, WASTED EXPENDITURE OR SAVINGS WHICH YOU MIGHT HAVE HAD, DENIAL OF SERVICE OR ACCESS TO OUR WEBSITE, OCCURRING DIRECTLY OR INDIRECTLY FROM THE USE OR ABILITY OR INABILITY TO USE, OR RELIANCE ON, OUR WEBSITE, OR THE SERVICE AND BASED ON ANY TYPE OF LIABILITY INCLUDING BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR OTHERWISE.
|
||||
38. YOU SHALL INDEMNIFY US AGAINST ALL CLAIMS, COSTS (INCLUDING ALL OUR LEGAL COSTS), EXPENSES, DEMANDS OR LIABILITY, DAMAGES AND LOSSES WHETHER DIRECT, INDIRECT, CONSEQUENTIAL, OR OTHERWISE, AND WHETHER ARISING IN CONTRACT, TORT (INCLUDING IN EACH CASE NEGLIGENCE), OR EQUITY OR OTHERWISE, ARISING DIRECTLY OR INDIRECTLY FROM BREACH BY YOU OR ANYONE YOU GIVE ACCESS TO YOUR DATA, OF ANY OF THESE TERMS.
|
||||
39. IF YOU ARE NOT SATISFIED WITH THE SERVICES, THEN YOUR SOLE AND EXCLUSIVE REMEDY IS TO TERMINATE THESE TERMS
|
||||
40. DESPITE THE ABOVE, IF ANY COURT HOLDS US (THIS INCLUDES OUR OFFICERS, STAFF AND AGENTS) LIABLE FOR ANY MATTER RELATED TO THESE TERMS OR OUR SERVICES, OUR TOTAL COMBINED LIABILITY WILL BE LIMITED TO THE SUM OF YOUR MONTHLY FEES PAID BY YOU FOR THE PREVIOUS MONTH.
|
||||
|
||||
45. TO THE MAXIMUM EXTENT PERMITTED BY LAW, WE (THIS INCLUDES OUR EMPLOYEES, OFFICERS, AGENTS AND AUTHORISED RESELLERS) ARE NOT LIABLE WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), EQUITY OR ON ANY OTHER GROUNDS TO YOU OR ANYONE ELSE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGE, LOSS, COST OR EXPENSE, DAMAGE TO PROPERTY, INJURY TO PERSONS, LOSS OF PROFITS, LOSS OF DATA OR REVENUE, LOSS OF USE, LOST BUSINESS OR MISSED OPPORTUNITIES, WASTED EXPENDITURE OR SAVINGS WHICH YOU MIGHT HAVE HAD, DENIAL OF SERVICE OR ACCESS TO OUR WEBSITE, OUR MOBILE APPS OR OUR API, OCCURRING DIRECTLY OR INDIRECTLY FROM THE USE OR ABILITY OR INABILITY TO USE, OR RELIANCE ON, OUR WEBSITE, OUR MOBILE APPS OR OUR API, OR THE SERVICES, AND BASED ON ANY TYPE OF LIABILITY INCLUDING BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), STATUTORY OR PRODUCT LIABILITY, OR OTHERWISE.
|
||||
46. YOU SHALL INDEMNIFY US AGAINST ALL CLAIMS, COSTS (INCLUDING ALL OUR LEGAL COSTS), EXPENSES, DEMANDS OR LIABILITY, DAMAGES AND LOSSES WHETHER DIRECT, INDIRECT, CONSEQUENTIAL, OR OTHERWISE, AND WHETHER ARISING IN CONTRACT, TORT (INCLUDING IN EACH CASE NEGLIGENCE), OR EQUITY OR OTHERWISE, ARISING DIRECTLY OR INDIRECTLY FROM BREACH BY YOU OR ANYONE YOU GIVE ACCESS TO YOUR DATA, OF ANY OF THESE TERMS OR ANY POLICY REFERENCED IN THESE TERMS.
|
||||
47. IF YOU ARE NOT SATISFIED WITH THE SERVICES, THEN YOUR SOLE AND EXCLUSIVE REMEDY IS TO TERMINATE YOUR USE OF OUR SERVICES AND THE CONTRACT YOU HAVE WITH US.
|
||||
48. DESPITE THE ABOVE, IF ANY COURT OR OTHER COMPETENT AUTHORITY HOLDS US (THIS INCLUDES OUR OFFICERS, STAFF AND AGENTS) LIABLE FOR ANY MATTER RELATED TO THESE TERMS OR OUR SERVICES, OUR TOTAL COMBINED LIABILITY WILL BE LIMITED TO THE MOST RECENT SUBSCRIPTION AMOUNT YOU HAVE PAID TO US.
|
||||
|
||||
Disputes and Choice of Law
|
||||
|
||||
41. Any and all disputes arising of this agreement, termination, or our relationship with you shall be determined by binding arbitration under the Arbitration Act 1996 in Auckland, New Zealand, by one arbitrator who shall be a lawyer knowledgable in relevant technology matters appointed by the President for the time being of the Arbitrators and Mediators Institute of New Zealand Incorporated (AMINZ) on a request by either you or us.
|
||||
41.1 Notice must be given to apply for any interim measure in the arbitration proceeding.
|
||||
41.2 The arbitration proceeding will commence when a request is made to AMINZ to appoint an arbitrator.
|
||||
41.3 The arbitration shall be in English. The Arbitrator in his or her discretion may permit the parties and witnesses to appear by videoconference.
|
||||
41.4 The relationship we have with you under these terms is governed by New Zealand law. You and we submit to the exclusive jurisdiction of the New Zealand arbitral tribunals and courts (for the purposes of that arbitation) and the parties agree to enforcement of the arbitral award and orders in New Zealand and any other country.
|
||||
49. Any and all disputes arising out of this agreement, its termination, or our relationship with you shall be determined by binding arbitration under the Arbitration Act 1996 in Auckland, New Zealand, by one arbitrator who shall be a lawyer knowledgeable in relevant technology matters appointed by the President for the time being of the Arbitrators and Mediators Institute of New Zealand Incorporated (AMINZ) on a request by either you or us. The following terms apply to the arbitration in addition to those implied by New Zealand law:
|
||||
49.1. Notice must be given to apply for any interim measure in the arbitration proceeding;
|
||||
49.2. The arbitration proceeding will commence when a request is made to AMINZ to appoint an arbitrator;
|
||||
49.3. The arbitration shall be in English. The Arbitrator shall permit the parties and witnesses to appear by videoconference that we will organise and pay for;
|
||||
49.4. We will pay the arbitrator's fees and expenses unless the arbitrator determines that you should meet some or all of those fees and expenses because your dispute is frivolous or vexatious.
|
||||
50. The relationship we have with you under these terms and their interpretation and construction together with any dispute, suspension or termination arising out of or in connection with them, is governed exclusively by New Zealand law. Mega does not submit to any other jurisdiction other than New Zealand and New Zealand law. You and we submit to the exclusive jurisdiction of the New Zealand arbitral tribunals (and courts for the purposes of the enforcement of any arbitral award or appeal on question of law).The parties agree to enforcement of the arbitral award and orders and any judgement in New Zealand and in any other country.
|
||||
|
||||
Business Accounts
|
||||
|
||||
51. For business accounts, the administrator of that account can see and deal with the files and data associated with all users within that account (including any data and any personal information). In addition:
|
||||
51.1. if the business account is suspended or terminated, the action will affect the data and personal information of every user within that account;
|
||||
51.2. the administrator of the business account will be able to see and deal with, change or delete the files and data associated with every user within that account (including any of data and personal information);
|
||||
51.3. the administrator of the business account will be able to terminate any user's account within the business account, restrict or disable usage of the account, change any user's password and otherwise deny access to the account and all data and personal information and such users will then lose access to all their data and all personal information associated their account.
|
||||
52. We will charge the credit card associated with the business account with the applicable fees per user (for a minimum of three users) at the monthly billing date, on a recurring basis.
|
||||
53. Where a business account recurring payment fails for any reason, after 30 days we may suspend the account and all users within that account until payment is made. If no payment is made within a reasonable period of time, we will be entitled to terminate the business account and all users within that account, in which case all data and personal information associated with those users and the account will be subject to deletion in accordance with these terms.
|
||||
54. Since business accounts and the users within them are entitled to unlimited storage, they are subject to a fair use policy as follows:
|
||||
54.1. Business accounts are only to be used for business purposes;
|
||||
54.2. Business accounts are intended for multiple users and are not to be held or used by one person;
|
||||
54.3. Each user must comply with these terms. Any breach of these terms by one user will be treated as a breach of these terms in respect of the whole account;
|
||||
54.4. Mega will not be liable to any business account user should the actions of another user within the account, including the administrator of the business account, cause any loss or damage to another user within the business account (including by way of deletion, amendment, sharing or any other dealing with data or personal information);
|
||||
54.5. Each user's use of the business service must be fair, reasonable and not excessive, as reasonably determined by us by reference to average and/or estimated typical per business user usage of the business service. We will consider usage to be excessive and unreasonable where it materially exceeds the average and/or estimated use patterns over any day, week or month (or other period of time as determined by us) ("excessive usage"). If we identify excessive usage or consider that usage patterns on any business account indicate that any of the usage is not for business purposes we may suspend, and after 30 days' notice terminate, any or all of the users or the whole business account, in which case data and personal information associated with those users and the account will be subject to deletion in accordance with these terms. Examples of such unreasonable usage patterns also include: making non-business data publicly available, adding users who do not appear to Mega to be associated with the business, and uploading or sharing files from non-business related third party sites.
|
||||
|
||||
Refunds
|
||||
|
||||
55. Unless otherwise provided by New Zealand law or by a particular service offer, all purchases are final and non-refundable. If you believe that Mega has charged you in error, you must contact us within 90 days of such charge. No refunds will be given for any charges more than 90 days old. We reserve the right to issue refunds or credits at our sole discretion. If we issue a refund or credit, we are under no obligation to issue the same or similar refund in the future. This refund policy does not affect any statutory rights that may apply. If you have made a payment by mistake and have not used the subscription plan services, you must contact support@mega.nz within 24 hours. This will be acknowledged promptly and answered within 7 days.
|
||||
|
||||
Recurring Paid Subscriptions
|
||||
|
||||
56. Recurring subscriptions will renew indefinitely, either monthly or annually, based upon your chosen subscription period, unless the subscription is cancelled prior to a renewal date. For recurring subscriptions established via mobile apps using in-app-purchase platforms, you should refer to your app store account for details of the dates and terms of the subscription. Any other recurring subscription will renew on the same day of month as it was established, except in cases where the day is not available due to a short month, in which case the renewal date will be moved to the first day of the following month.
|
||||
|
||||
Cancellation of Recurring Paid Subscriptions
|
||||
|
||||
57. Recurring subscriptions established through the mobile app using in-app-purchase platforms should be cancelled through the relevant app store account directly. Any other recurring subscription should be cancelled by navigating to https://mega.nz/account in your browser and selecting the option to cancel your subscription. Any payments processed after an effective subscription cancellation will be promptly refunded by us. If you cancel a paid subscription, but you maintain your Mega account as a free account, access to your account may be restricted or blocked if the level of use is above the limits applying to free accounts at that time.
|
||||
|
||||
Information and Privacy
|
||||
42. We reserve the right to disclose data and other information as required by law.
|
||||
43. You and anyone else you give access to are also bound by our Privacy Policy. By accepting these terms, you also accept our Privacy Policy.
|
||||
|
||||
58. We reserve the right to disclose data and other information as required by law or any competent authority. Our approach is referenced in our Privacy & Data Policy and Takedown Guidance Policy, both of which are subject to these terms.
|
||||
59. You and anyone else you give access to are also bound by our Privacy & Data Policy and Takedown Guidance Policy.
|
||||
By accepting these terms, you also accept our Privacy & Data Policy and Takedown Guidance Policy.
|
||||
|
||||
Notices
|
||||
44. You can contact us by writing to support@mega.nz. If we need to contact you or provide you with Notice we will email you at the email address you gave us when you set up your access to the services and/or through any internal messaging system we provide.
|
||||
|
||||
60. You can contact us by sending an email to support@mega.nz. If we need to contact you or provide you with notice we will email you at the email address you have recorded in your account details and such notices will be valid and deemed to be received by you whether or not you are using that address. We may also send notices via any chat facility or internal messaging system we may provide.
|
||||
|
||||
Rights to Third Parties
|
||||
45. Employees, officers, agents, authorised suppliers of services to and authorised resellers of, our services, are entitled to the benefit of all indemnities and other provisions of these terms which are for the benefit of Mega.
|
||||
|
||||
61. Mega Limited employees, officers, agents, related companies and affiliates together with authorised suppliers of services to and authorised resellers of, our services, are entitled to the benefit of all indemnities and other provisions of these terms which are for the benefit of Mega in these terms.
|
||||
|
||||
Entire Agreement
|
||||
|
||||
62. These terms, our Privacy & Data Policy, and Takedown Guidance Policy, the terms of any plan you purchase and any other terms and policies expressly referenced in these terms, together constitute the entire agreement between us relating to your use of the website, our mobile apps, our API and our services. From the date they come into force, in respect of any use of any of our services after that, they supersede and replace any prior agreement, arrangement or understanding between you and us regarding the use of our services. No agreement, arrangement or understanding alleged to be made between us, or representation alleged to be made, by us or on our behalf, to you, if inconsistent with these terms, shall be valid unless agreed to in writing by an executive officer of Mega Limited.
|
||||
|
||||
Last updated 15 November 2018, effective 17 December 2018.
|
||||
|
@ -526,6 +526,10 @@ modeselected:
|
||||
AccessControl::SetFileOwner "$INSTDIR\mega-du.bat" "$USERNAME"
|
||||
AccessControl::GrantOnFile "$INSTDIR\mega-du.bat" "$USERNAME" "GenericRead + GenericWrite"
|
||||
|
||||
File "${SRCDIR_BATFILES}\mega-df.bat"
|
||||
AccessControl::SetFileOwner "$INSTDIR\mega-df.bat" "$USERNAME"
|
||||
AccessControl::GrantOnFile "$INSTDIR\mega-df.bat" "$USERNAME" "GenericRead + GenericWrite"
|
||||
|
||||
File "${SRCDIR_BATFILES}\mega-export.bat"
|
||||
AccessControl::SetFileOwner "$INSTDIR\mega-export.bat" "$USERNAME"
|
||||
AccessControl::GrantOnFile "$INSTDIR\mega-export.bat" "$USERNAME" "GenericRead + GenericWrite"
|
||||
@ -888,6 +892,7 @@ Section Uninstall
|
||||
Delete "$INSTDIR\mega-cp.bat"
|
||||
Delete "$INSTDIR\mega-debug.bat"
|
||||
Delete "$INSTDIR\mega-du.bat"
|
||||
Delete "$INSTDIR\mega-df.bat"
|
||||
Delete "$INSTDIR\mega-export.bat"
|
||||
Delete "$INSTDIR\mega-find.bat"
|
||||
Delete "$INSTDIR\mega-get.bat"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/make -f
|
||||
CPPFLAGS := $(shell cat /etc/issue | grep "Ubuntu 1[235]\|Debian.* 7\|Ubuntu 17.04\|Ubuntu 1[46].10" >/dev/null && echo "$$CPPFLAGS -DMEGACMD_DEPRECATED_OS" || echo "")
|
||||
CPPFLAGS := $(shell cat /etc/issue | grep "Ubuntu 1[2357]\|Debian.* 7\|Ubuntu 1[46].10" >/dev/null && echo "$$CPPFLAGS -DMEGACMD_DEPRECATED_OS" || echo "")
|
||||
FMEDIAINFO := $(shell dpkg -l | grep mediainfo >/dev/null && echo "-i" || echo " ")
|
||||
WMEDIAINFO := $(shell dpkg -l | grep mediainfo >/dev/null && echo " " || echo "--with-libmediainfo=$(CURDIR)/deps --with-libzen=$(CURDIR)/deps")
|
||||
FULLREQS := $(shell cat /etc/issue | grep "Ubuntu 12.04" >/dev/null && echo "" || echo '-DREQUIRE_HAVE_FFMPEG -DREQUIRE_HAVE_LIBUV -DREQUIRE_USE_MEDIAINFO -DREQUIRE_USE_PCRE')
|
||||
|
@ -127,7 +127,7 @@ sed -i "s#AC_INIT#m4_pattern_allow(AC_PROG_OBJCXX)\nAC_INIT#g" sdk/configure.ac
|
||||
mkdir deps || :
|
||||
bash -x ./contrib/build_sdk.sh %{flag_cryptopp} %{flag_libraw} %{flag_cares} -o archives \
|
||||
-g %{flag_disablezlib} %{flag_disablemediainfo} -b -l -c -s -u -v -a -p deps/
|
||||
%if ( 0%{?fedora_version} && 0%{?fedora_version}<=24 ) || ( 0%{?centos_version} == 600 ) || ( 0%{?suse_version} && 0%{?suse_version} <= 1320 && !0%{?sle_version})
|
||||
%if ( 0%{?fedora_version} && 0%{?fedora_version}<=27 ) || ( 0%{?centos_version} == 600 ) || ( 0%{?suse_version} && 0%{?suse_version} <= 1320 && !0%{?sle_version} ) || ( 0%{?sle_version} && 0%{?sle_version} <= 120200 )
|
||||
export CPPFLAGS="$CPPFLAGS -DMEGACMD_DEPRECATED_OS"
|
||||
%endif
|
||||
|
||||
@ -446,6 +446,7 @@ killall mega-cmd-server 2> /dev/null || true
|
||||
%{_bindir}/mega-cp
|
||||
%{_bindir}/mega-debug
|
||||
%{_bindir}/mega-du
|
||||
%{_bindir}/mega-df
|
||||
%{_bindir}/mega-exec
|
||||
%{_bindir}/mega-export
|
||||
%{_bindir}/mega-find
|
||||
|
@ -16,11 +16,13 @@ CONFIG += console
|
||||
|
||||
SOURCES += ../../../../src/client/megacmdclient.cpp \
|
||||
../../../../src/megacmdshell/megacmdshellcommunications.cpp \
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp \
|
||||
../../../../src/megacmdcommonutils.cpp
|
||||
|
||||
HEADERS += ../../../../src/megacmdshell/megacmdshellcommunications.h \
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.h \
|
||||
../../../../sdk/include/mega/thread.h
|
||||
../../../../sdk/include/mega/thread.h \
|
||||
../../../../src/megacmdcommonutils.h
|
||||
|
||||
INCLUDEPATH += ../../../../sdk/include
|
||||
|
||||
@ -71,6 +73,11 @@ else{
|
||||
|
||||
|
||||
macx {
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
QMAKE_CXXFLAGS -= -stdlib=libc++
|
||||
QMAKE_LFLAGS -= -stdlib=libc++
|
||||
CONFIG -= c++11
|
||||
|
||||
QMAKE_CXXFLAGS += -g
|
||||
}
|
||||
|
||||
|
@ -22,5 +22,10 @@ win32 {
|
||||
}
|
||||
|
||||
macx {
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
QMAKE_CXXFLAGS -= -stdlib=libc++
|
||||
QMAKE_LFLAGS -= -stdlib=libc++
|
||||
CONFIG -= c++11
|
||||
|
||||
QMAKE_CXXFLAGS += -g
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ CONFIG -= qt
|
||||
|
||||
win32 {
|
||||
TARGET = MEGAcmdServer
|
||||
CONFIG += USE_AUTOCOMPLETE
|
||||
}
|
||||
else {
|
||||
TARGET = MEGAcmd
|
||||
@ -61,7 +62,8 @@ SOURCES += ../../../../src/megacmd.cpp \
|
||||
../../../../src/megacmdsandbox.cpp \
|
||||
../../../../src/configurationmanager.cpp \
|
||||
../../../../src/comunicationsmanager.cpp \
|
||||
../../../../src/megacmdutils.cpp
|
||||
../../../../src/megacmdutils.cpp \
|
||||
../../../../src/megacmdcommonutils.cpp
|
||||
|
||||
|
||||
HEADERS += ../../../../src/megacmd.h \
|
||||
@ -72,6 +74,7 @@ HEADERS += ../../../../src/megacmd.h \
|
||||
../../../../src/configurationmanager.h \
|
||||
../../../../src/comunicationsmanager.h \
|
||||
../../../../src/megacmdutils.h \
|
||||
../../../../src/megacmdcommonutils.h \
|
||||
../../../../src/megacmdversion.h \
|
||||
../../../../src/megacmdplatform.h
|
||||
|
||||
@ -98,9 +101,6 @@ macx {
|
||||
ICON = app.icns
|
||||
# QMAKE_INFO_PLIST = Info_MEGA.plist
|
||||
|
||||
CONFIG += USE_OPENSSL
|
||||
DEFINES += USE_OPENSSL
|
||||
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
QMAKE_CXXFLAGS -= -stdlib=libc++
|
||||
QMAKE_LFLAGS -= -stdlib=libc++
|
||||
|
@ -15,20 +15,24 @@ TEMPLATE = app
|
||||
CONFIG += console
|
||||
|
||||
win32 {
|
||||
CONFIG += USE_AUTOCOMPLETE
|
||||
CONFIG += USE_CONSOLE
|
||||
DEFINES += NO_READLINE
|
||||
include(../../../../sdk/bindings/qt/sdk.pri) #This is required to have console.cpp included: avoiding this is rather complicated
|
||||
HEADERS += ../../../../sdk/include/mega/autocomplete.h
|
||||
}
|
||||
|
||||
SOURCES += ../../../../src/megacmdshell/megacmdshell.cpp \
|
||||
../../../../src/megacmdshell/megacmdshellcommunications.cpp \
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.cpp \
|
||||
../../../../src/megacmdcommonutils.cpp
|
||||
|
||||
|
||||
HEADERS += ../../../../src/megacmdshell/megacmdshell.h \
|
||||
../../../../src/megacmdshell/megacmdshellcommunications.h \
|
||||
../../../../src/megacmdshell/megacmdshellcommunicationsnamedpipes.h \
|
||||
../../../../sdk/include/mega/thread.h
|
||||
../../../../sdk/include/mega/thread.h \
|
||||
../../../../src/megacmdcommonutils.h
|
||||
|
||||
|
||||
INCLUDEPATH += ../../../../sdk/include
|
||||
|
||||
@ -57,9 +61,7 @@ else{
|
||||
}
|
||||
|
||||
win32 {
|
||||
SOURCES += ../../../../sdk/src/autocomplete.cpp \
|
||||
../../../../sdk/src/win32/console.cpp \
|
||||
../../../../sdk/src/thread/win32thread.cpp \
|
||||
SOURCES += ../../../../sdk/src/thread/win32thread.cpp \
|
||||
../../../../sdk/src/logging.cpp
|
||||
HEADERS += ../../../../sdk/include/mega/win32thread.h \
|
||||
../../../../sdk/include/mega/logging.h
|
||||
@ -87,6 +89,12 @@ macx {
|
||||
LIBS += $$PWD/../../../../sdk/bindings/qt/3rdparty/libs/libreadline.a
|
||||
LIBS += -framework Cocoa -framework SystemConfiguration -framework CoreFoundation -framework Foundation -framework Security
|
||||
LIBS += -lncurses
|
||||
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
|
||||
QMAKE_CXXFLAGS -= -stdlib=libc++
|
||||
QMAKE_LFLAGS -= -stdlib=libc++
|
||||
CONFIG -= c++11
|
||||
|
||||
QMAKE_CXXFLAGS += -g
|
||||
}
|
||||
else {
|
||||
|
@ -1,9 +1,11 @@
|
||||
# MEGA-BACKUPS - Backing folders with MEGAcmd
|
||||
This is a brief tutorial on how to configure backups. It will be improved soon.
|
||||
This is a brief tutorial on how to configure backups.
|
||||
|
||||
Notice: the commands listed here assume you are using the interactive interaction mode: they are supposed to be executed within MEGAcmdShell.
|
||||
|
||||
## Creation
|
||||
Example:
|
||||
backup /path/to/myfolder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
backup /path/mega/folder /remote/path --period="0 0 4 * * *" --num-backups=10
|
||||
|
||||
This will configure a backup of "myfolder" into /remote/path that will be carried out
|
||||
at 4:00 A.M. (UTC) every day. It will store the last 10 copies.
|
||||
@ -25,7 +27,7 @@ You can list the backups configured typing `backup`:
|
||||
|
||||
```
|
||||
TAG LOCALPATH REMOTEPARENTPATH STATUS
|
||||
4 /path/to/myfolder /remote/path ACTIVE
|
||||
4 /path/mega/folder /remote/path ACTIVE
|
||||
```
|
||||
|
||||
Notice the TAG. You can use it to refer to the backup if you wan to change its configuration
|
||||
@ -37,7 +39,7 @@ If you type "backup -l" you will see extra information concerning the backup. He
|
||||
see when the next backup is scheduled for:
|
||||
```
|
||||
TAG LOCALPATH REMOTEPARENTPATH STATUS
|
||||
4 /path/to/myfolder /remote/path ONGOING
|
||||
4 /path/mega/folder /remote/path ONGOING
|
||||
Max Backups: 4
|
||||
Period: "0 0 4 * * *"
|
||||
Next backup scheduled for: Fri, 19 Jan 2018 04:00:00 +0000
|
||||
@ -55,7 +57,7 @@ With "backup -h" you will be able to see the existing backups with their state a
|
||||
|
||||
```
|
||||
TAG LOCALPATH REMOTEPARENTPATH STATUS
|
||||
4 /path/to/myfolder /remote/path ONGOING
|
||||
4 /path/mega/folder /remote/path ONGOING
|
||||
-- SAVED BACKUPS --
|
||||
NAME DATE STATUS FILES FOLDERS
|
||||
myfolder_bk_20180115175811 15Jan2018 17:58:11 COMPLETE 33 10
|
||||
@ -83,7 +85,7 @@ This will cancel all transfers and set the backup as ABORTED
|
||||
|
||||
Similarly you can remove a backup, to no longer backup that folder with:
|
||||
```
|
||||
backup -d /path/to/myfolder
|
||||
backup -d /path/mega/folder
|
||||
```
|
||||
This will not remove the existing backups wich will be available in MEGA.
|
||||
|
||||
@ -95,7 +97,7 @@ backup 4 --period=2h
|
||||
```
|
||||
This will set our backup with TAG=4 to have a period of 2 hours.
|
||||
```
|
||||
backup /path/to/myfolder --num-backups=1
|
||||
backup /path/mega/folder --num-backups=1
|
||||
```
|
||||
This will configure the backup to only keep one instance.
|
||||
Notice that in order not to lose data, older instances will not be deleted until
|
||||
|
94
contrib/docs/DEBUG.md
Normal file
94
contrib/docs/DEBUG.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Debugging MEGAcmd
|
||||
|
||||
There are two different kinds of logging messages:
|
||||
- MEGAcmd based: those messages reported by MEGAcmd itself.
|
||||
|
||||
These messages will show information regarding the processing of user commands.
|
||||
|
||||
- SDK based: those messages reported by the sdk and dependent libraries.
|
||||
|
||||
These messages will show information regarding requests, transfers, network, etc.
|
||||
They will be labeled with `API:`.
|
||||
|
||||
MEGAcmdServer logs messages depending on the level of log adjusted to those
|
||||
two categories. You can adjust the level of logging for those kinds with `log` command.
|
||||
Log levels range from FATAL (the lowest) to VERBOSE (the highest).
|
||||
|
||||
## How to access the logs
|
||||
|
||||
Accessing the logs depends on the platform you are in.
|
||||
|
||||
### MacOS
|
||||
|
||||
By default, whenever MEGAcmdServer is executed, it will log the output into
|
||||
`$HOME/.megaCmd/megacmdserver.log`.
|
||||
|
||||
If you want to launch it manually execute in a terminal:
|
||||
|
||||
```
|
||||
export PATH=/Applications/MEGAcmd.app/Contents/MacOS:$PATH
|
||||
./mega-cmd
|
||||
```
|
||||
|
||||
### Linux
|
||||
By default, whenever MEGAcmdServer is executed, it will log the output into
|
||||
$HOME/.megaCmd/megacmdserver.log.
|
||||
|
||||
If you want to launch it manually execute in a terminal:
|
||||
|
||||
```
|
||||
mega-cmd-server
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
MEGAcmdServer is executed in the background without saving the log into a file. If you want to
|
||||
see the output you would need to execute the server (MEGAcmdShell.exe) manually.
|
||||
|
||||
## Verbosity on startup
|
||||
|
||||
You can start the server with higher level of verbosity in order to have log levels increased at startup.
|
||||
In Windows & Linux you will need to pass `--debug-full` as an argument to the executable (e.g: `MEGAcmdShell.exe --debug-full`).
|
||||
|
||||
In MacOS, you can use `MEGACMD_LOGLEVEL` environment variable like this: `MEGACMD_LOGLEVEL=FULLDEBUG ./mega-cmd`.
|
||||
|
||||
If you want other startup level of loggin, you can use:
|
||||
|
||||
* `--debug`
|
||||
* `MEGACMD_LOGLEVEL=DEBUG`
|
||||
|
||||
This will set:
|
||||
|
||||
MEGAcmd log level = DEBUG
|
||||
SDK log level = DEFAULT
|
||||
|
||||
* `--debug-full`
|
||||
* `MEGACMD_LOGLEVEL=DEBUG`
|
||||
|
||||
This will set:
|
||||
|
||||
MEGAcmd log level = DEBUG
|
||||
SDK log level = DEBUG
|
||||
|
||||
* `--verbose`
|
||||
* `MEGACMD_LOGLEVEL=VERBOSE`
|
||||
|
||||
This will set:
|
||||
|
||||
MEGAcmd log level = VERBOSE
|
||||
SDK log level = DEFAULT
|
||||
|
||||
* `--verbose-full`
|
||||
* `MEGACMD_LOGLEVEL=FULLVERBOSE`
|
||||
|
||||
This will set:
|
||||
|
||||
MEGAcmd log level = VERBOSE
|
||||
SDK log level = VERBOSE
|
||||
|
||||
|
||||
## Controlling verbosity of a single command
|
||||
|
||||
You can pass `-v` (`-vv`, `-vvv`, and so on for a more verbose output)
|
||||
to an specific command and it will use higher level of verbosity of MEGAcmd based messages.
|
||||
|
@ -4,10 +4,12 @@ This is a brief tutorial on how to configure [ftp](https://en.wikipedia.org/wiki
|
||||
Configuring a FTP server will let you access your MEGA files as if they were located in your computer.
|
||||
All major platforms support access to FTP server. See [`Platform`](#platforms) usage.
|
||||
|
||||
Notice: the commands listed here assume you are using the interactive interaction mode: they are supposed to be executed within MEGAcmdShell.
|
||||
|
||||
## Serving a folder
|
||||
Example:
|
||||
```
|
||||
ftp /path/to/myfolder
|
||||
ftp /path/mega/folder
|
||||
```
|
||||
|
||||
This will configure a FTP server that will serve "myfolder". It'll show you the URL to access that path. You just use that location to configure access [according to your specific OS](#platforms).
|
||||
@ -39,7 +41,7 @@ You can list the ftp served locations typing `ftp`:
|
||||
|
||||
```
|
||||
FTP SERVED LOCATIONS:
|
||||
/path/to/myfolder: ftp://127.0.0.1:4990/XXXXXXX/myfolder
|
||||
/path/mega/folder: ftp://127.0.0.1:4990/XXXXXXX/myfolder
|
||||
/path/to/myfile.mp4: ftp://127.0.0.1:4990/YYYYYYY/myfile.mp4
|
||||
```
|
||||
|
||||
@ -66,7 +68,7 @@ you can secure it with [TLS](https://wikipedia.org/wiki/Transport_Layer_Security
|
||||
To serve via FTPS, you just need to pass `--tls` and the paths* to your certificate and key files (in PEM format):
|
||||
|
||||
```
|
||||
ftp /path/to/myfolder --tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key
|
||||
ftp /path/mega/folder --tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key
|
||||
```
|
||||
|
||||
*Those paths are local paths in your machine, not in MEGA.
|
||||
@ -80,11 +82,11 @@ If you want to change that configuration you will need to stop serving each and
|
||||
|
||||
You can stop serving a MEGA location with:
|
||||
```
|
||||
ftp -d /path/to/myfolder
|
||||
ftp -d /path/mega/folder
|
||||
```
|
||||
If successfully, it will show a message indicating that the path is no longer served:
|
||||
```
|
||||
/path/to/myfolder no longer served via ftp
|
||||
/path/mega/folder no longer served via ftp
|
||||
```
|
||||
|
||||
## Platforms
|
||||
|
@ -4,10 +4,12 @@ This is a brief tutorial on how to configure [webdav](https://wikipedia.org/wiki
|
||||
Configuring a WEBDAV server will let you access your MEGA files as if they were located in your computer.
|
||||
All major platforms support access to WEBDAV server. See [`Platform`](#platforms) usage.
|
||||
|
||||
Notice: the commands listed here assume you are using the interactive interaction mode: they are supposed to be executed within MEGAcmdShell.
|
||||
|
||||
## Serving a folder
|
||||
Example:
|
||||
```
|
||||
webdav /path/to/myfolder
|
||||
webdav /path/mega/folder
|
||||
```
|
||||
|
||||
This will configure a WEBDAV server that will serve "myfolder". It'll show you the URL to access that path. You just use that location to configure access [according to your specific OS](#platforms).
|
||||
@ -40,7 +42,7 @@ You can list the webdav served locations typing `webdav`:
|
||||
|
||||
```
|
||||
WEBDAV SERVED LOCATIONS:
|
||||
/path/to/myfolder: http://127.0.0.1:4443/XXXXXXX/myfolder
|
||||
/path/mega/folder: http://127.0.0.1:4443/XXXXXXX/myfolder
|
||||
/path/to/myfile.mp4: http://127.0.0.1:4443/YYYYYYY/myfile.mp4
|
||||
```
|
||||
|
||||
@ -64,7 +66,7 @@ you can secure it with [TLS](https://wikipedia.org/wiki/Transport_Layer_Security
|
||||
You just need to pass `--tls` and the paths* to your certificate and key files (in PEM format):
|
||||
|
||||
```
|
||||
webdav /path/to/myfolder --tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key
|
||||
webdav /path/mega/folder --tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key
|
||||
```
|
||||
|
||||
*Those paths are local paths in your machine, not in MEGA.
|
||||
@ -78,11 +80,11 @@ If you want to change that configuration you will need to stop serving each and
|
||||
|
||||
You can stop serving a MEGA location with:
|
||||
```
|
||||
webdav -d /path/to/myfolder
|
||||
webdav -d /path/mega/folder
|
||||
```
|
||||
If successfully, it will show a message indicating that the path is no longer served:
|
||||
```
|
||||
/path/to/myfolder no longer served via webdav
|
||||
/path/mega/folder no longer served via webdav
|
||||
```
|
||||
|
||||
## Platforms
|
||||
|
@ -56,12 +56,14 @@ MEGA Website.url;MEGA Website.url;7b5f1278de755dde65017404b662b6ab97fa7328974eec
|
||||
mega-attr.bat;mega-attr.bat;89a1b21160a0e3890c45596d7832ff37474a2c3200423f23adee11ff676b295b
|
||||
mega-backup.bat;mega-backup.bat;167d72cbaa49b8c6c54d57ab44ad9e907f4bf9551460574f4231a9dd956c4c32
|
||||
mega-cancel.bat;mega-cancel.bat;aab45aa9eac5e0b9865f44a234f6c5cddbc3b2fcb14aa4fee101cbcef2ba37d8
|
||||
mega-cat.bat;mega-cat.bat;03d39664173b9baf2ae530b457510c4ee915e9060be46063511ed903d3afa265
|
||||
mega-cd.bat;mega-cd.bat;d3b331e8568b4aa59710b2a731541d625138fa0d37aa26fda679a6b8713827ad
|
||||
mega-confirm.bat;mega-confirm.bat;e45eeac40ace7b050f9747d79954c4b7bb82792b727a691799694f109938b338
|
||||
mega-confirmcancel.bat;mega-confirmcancel.bat;5c3128dfd3f4d604afa6e602aca4a346d758d889400eb74584c88f1e40fe9bac
|
||||
mega-cp.bat;mega-cp.bat;f5cc9ce16100354271c7b385377053076c486cba84f21151a65721d24caecf09
|
||||
mega-debug.bat;mega-debug.bat;df39fd5831826cb988eb5bfdfb4a98ca75eda8c03f6acdc286a7741448849c9b
|
||||
mega-deleteversions.bat;mega-deleteversions.bat;ac1d8b0b8458ec134d5c85fa863c3d8ed016e35454dedae79698ad0818919b7f
|
||||
mega-df.bat;mega-df.bat;b47b85efda1561b559c7d1a81e0d4b49958607f6e4933bf46f97f43c917f69a7
|
||||
mega-du.bat;mega-du.bat;fbb81f40c843fc33e57a23db01ee0f206c99c6ed75520a5594e0b3d525725215
|
||||
mega-errorcode.bat;mega-errorcode.bat;f5793c201602a3619cac14d31d0356d058d8128b13027b1e64073dd029193614
|
||||
mega-exclude.bat;mega-exclude.bat;a347a180847fa3dca00bc28dd1321f5b332fdf574c73ea2b30ef3fab63b2380b
|
||||
@ -82,6 +84,7 @@ mega-login.bat;mega-login.bat;9bc358f934bfbeb12347083aef6b7a6efe26846b83ce0e653a
|
||||
mega-logout.bat;mega-logout.bat;ab36f1dcf6cfd93b95bf5394b1ef22deff505df685c9b0a36d25fa9c94f4b548
|
||||
mega-lpwd.bat;mega-lpwd.bat;6364d746c3f1f0329fd67cec0f6a1f09ae3e521f3ef37b0ab728009cf55c4a5c
|
||||
mega-ls.bat;mega-ls.bat;d57684855baf42e911b235c7ffb5a106aac875461d5faeb059c4d941e7b5cfd6
|
||||
mega-mediainfo.bat;mega-mediainfo.bat;59606376cabc50a19af3732cddbbcda40c59e0c85aa6bc0320420a6a19abca49
|
||||
mega-mkdir.bat;mega-mkdir.bat;690c56c5ebd58d596632a4ff28596df8aa478309fc979b9eb8b07fb89db4d944
|
||||
mega-mount.bat;mega-mount.bat;6f0a3e80dcde8611beb4ac1d9e575601997e58b9a4a17054c5cb4eedf6f8062f
|
||||
mega-mv.bat;mega-mv.bat;4e694c7eb85dcf55d7642f3504a5d63493e46ebd711735c57a45569ef2a7b88a
|
||||
@ -100,14 +103,12 @@ mega-speedlimit.bat;mega-speedlimit.bat;c6f2a4b09f9249c4e77ad03cc0e15940f080c125
|
||||
mega-sync.bat;mega-sync.bat;c39719e5e79043b28a6368cdc942032bf5b2ab18fff2f66bd726058e9e921ef7
|
||||
mega-thumbnail.bat;mega-thumbnail.bat;58574690db6cfff0ffa7864a0a13265ae1bd37d5fc3b0d9e0c88a1f7d69c193d
|
||||
mega-transfers.bat;mega-transfers.bat;6f35a34033499938700e42f4123399f711003d2dab83ed50e69f7df5ecf976d8
|
||||
mega-tree.bat;mega-tree.bat;92a11c9ee2af4ffb55d05210813c7ff309f90274a1d211018acc2643367b2534
|
||||
mega-userattr.bat;mega-userattr.bat;a48dfc0e20bd69e3774d74860f2a74691addf9fbaae42c71450561a4d526f92a
|
||||
mega-users.bat;mega-users.bat;24d85b5700f05d7b638d294c87e8b8809df80f0611c63ee818f60ed487f1b4bc
|
||||
mega-version.bat;mega-version.bat;b69c2f0acc58d45ae4dae502892af08ce9abaa0de2433573a07e9a06fae3a255
|
||||
mega-webdav.bat;mega-webdav.bat;233717710c3ac45906e2cbd110a167d7779bd6697a508013c5b6559bbce97815
|
||||
mega-whoami.bat;mega-whoami.bat;b6ff6c05c78901dfc6291751bab1ae93a0ac836d8d506e57d2bb6fb927facc7d
|
||||
mega-cat.bat;mega-cat.bat;6225ce58605e8795fe2e48220607ac193744cb313cd181fb6e90a190484a9bbf
|
||||
mega-tree.bat;mega-tree.bat;0f03785c46a12893100f360da48fb473de9011bffd9562a327aa76626078d263
|
||||
mega-mediainfo.bat;mega-mediainfo.bat;7364d4c609c2030136837f70765586494d6951058530d828b75e57eedcac2626
|
||||
MEGAclient.exe;MEGAclient.exe;609973b7c98f7e089fdb06666b34b5763b83e89c115a16faa022b5d48e1f8b0d
|
||||
MEGAcmdServer.exe;MEGAcmdServer.exe;5b1f129311566b77e551796c2e80e2ba5f871679ed9e38cde74070ddffca4e92
|
||||
MEGAcmdShell.exe;MEGAcmdShell.exe;04e8baf8d95166e5f1b21a896b01ff315c81edded845ae1690db51f16f8d75ee
|
||||
|
2
sdk
2
sdk
@ -1 +1 @@
|
||||
Subproject commit 527147cdb886c0dc62cd2a3e7cde93aa91d830f6
|
||||
Subproject commit 4a7c53c9c6a45b7374e72c42635d16b73f5a85f7
|
2
src/client/mega-df
Executable file
2
src/client/mega-df
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
mega-exec df "$@"
|
0
src/client/mega-tree
Normal file → Executable file
0
src/client/mega-tree
Normal file → Executable file
@ -2,7 +2,7 @@
|
||||
* @file src/client/megacmdclient.cpp
|
||||
* @brief MEGAcmdClient: Client application of MEGAcmd
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -16,6 +16,7 @@
|
||||
* program.
|
||||
*/
|
||||
|
||||
#include "../megacmdcommonutils.h"
|
||||
#include "../megacmdshell/megacmdshellcommunications.h"
|
||||
#include "../megacmdshell/megacmdshellcommunicationsnamedpipes.h"
|
||||
|
||||
@ -38,8 +39,23 @@
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
#include <sys/ioctl.h> // console size
|
||||
#endif
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#define PROGRESS_COMPLETE -2
|
||||
#define SPROGRESS_COMPLETE "-2"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define SSTR( x ) static_cast< const std::ostringstream & >( \
|
||||
( std::ostringstream() << std::dec << x ) ).str()
|
||||
|
||||
void printprogress(long long completed, long long total, const char *title = "TRANSFERRING");
|
||||
|
||||
#ifdef _WIN32
|
||||
// convert UTF-8 to Windows Unicode
|
||||
void path2local(string* path, string* local)
|
||||
@ -122,7 +138,7 @@ wstring getWAbsPath(wstring localpath)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
string clientID; //identifier for a registered state listener
|
||||
|
||||
string getAbsPath(string relativePath)
|
||||
{
|
||||
@ -206,6 +222,68 @@ string parseArgs(int argc, char* argv[])
|
||||
{
|
||||
absolutedargs.push_back(argv[1]);
|
||||
|
||||
if (!strcmp(argv[1],"get")
|
||||
|| !strcmp(argv[1],"put")
|
||||
|| !strcmp(argv[1],"login")
|
||||
|| !strcmp(argv[1],"reload") )
|
||||
{
|
||||
int waittime = 15000;
|
||||
while (waittime > 0 && !clientID.size())
|
||||
{
|
||||
sleepMilliSeconds(100);
|
||||
waittime -= 100;
|
||||
}
|
||||
if (clientID.size())
|
||||
{
|
||||
string sclientID = "--clientID=";
|
||||
sclientID+=clientID;
|
||||
absolutedargs.push_back(sclientID);
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1],"backup")
|
||||
|| !strcmp(argv[1],"du")
|
||||
|| !strcmp(argv[1],"mediainfo")
|
||||
|| !strcmp(argv[1],"sync")
|
||||
|| !strcmp(argv[1],"transfers") )
|
||||
{
|
||||
unsigned int width = getNumberOfCols(80);
|
||||
int pathSize = width/2;
|
||||
|
||||
if ( !strcmp(argv[1],"transfers") )
|
||||
{
|
||||
pathSize = int((width-46)/2);
|
||||
}
|
||||
else if ( !strcmp(argv[1],"du") )
|
||||
{
|
||||
pathSize = int(width-13);
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (strstr(argv[i], "--versions"))
|
||||
{
|
||||
pathSize -= 11;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( !strcmp(argv[1],"sync") )
|
||||
{
|
||||
pathSize = int((width-46)/2);
|
||||
}
|
||||
else if ( !strcmp(argv[1],"mediainfo") )
|
||||
{
|
||||
pathSize = int(width - 28);
|
||||
}
|
||||
else if ( !strcmp(argv[1],"backup") )
|
||||
{
|
||||
pathSize = int((width-21)/2);
|
||||
}
|
||||
|
||||
string spathSize = "--path-display-size=";
|
||||
spathSize+=SSTR(pathSize);
|
||||
absolutedargs.push_back(spathSize);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1],"sync"))
|
||||
{
|
||||
for (int i = 2; i < argc; i++)
|
||||
@ -344,7 +422,6 @@ string parseArgs(int argc, char* argv[])
|
||||
|
||||
wstring parsewArgs(int argc, wchar_t* argv[])
|
||||
{
|
||||
|
||||
for (int i=1;i<argc;i++)
|
||||
{
|
||||
if (i<(argc-1) && !wcscmp(argv[i],L"-o"))
|
||||
@ -362,6 +439,73 @@ wstring parsewArgs(int argc, wchar_t* argv[])
|
||||
{
|
||||
absolutedargs.push_back(argv[1]);
|
||||
|
||||
if (!wcscmp(argv[1],L"get")
|
||||
|| !wcscmp(argv[1],L"put")
|
||||
|| !wcscmp(argv[1],L"login")
|
||||
|| !wcscmp(argv[1],L"reload") )
|
||||
{
|
||||
int waittime = 5000;
|
||||
while (waittime > 0 && !clientID.size())
|
||||
{
|
||||
sleepMilliSeconds(100);
|
||||
waittime -= 100;
|
||||
}
|
||||
if (clientID.size())
|
||||
{
|
||||
wstring sclientID = L"--clientID=";
|
||||
std::wstring wclientID(clientID.begin(), clientID.end());
|
||||
sclientID+=wclientID;
|
||||
absolutedargs.push_back(sclientID);
|
||||
}
|
||||
}
|
||||
|
||||
if (!wcscmp(argv[1],L"backup")
|
||||
|| !wcscmp(argv[1],L"du")
|
||||
|| !wcscmp(argv[1],L"mediainfo")
|
||||
|| !wcscmp(argv[1],L"sync")
|
||||
|| !wcscmp(argv[1],L"transfers") )
|
||||
{
|
||||
unsigned int width = getNumberOfCols(80);
|
||||
int pathSize = width/2;
|
||||
|
||||
if ( !wcscmp(argv[1],L"transfers") )
|
||||
{
|
||||
pathSize = int((width-46)/2);
|
||||
}
|
||||
else if ( !wcscmp(argv[1],L"du") )
|
||||
{
|
||||
pathSize = int(width-13);
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (wcsstr(argv[i], L"--versions"))
|
||||
{
|
||||
pathSize -= 11;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ( !wcscmp(argv[1],L"sync") )
|
||||
{
|
||||
pathSize = int((width-46)/2);
|
||||
}
|
||||
else if ( !wcscmp(argv[1],L"mediainfo") )
|
||||
{
|
||||
pathSize = int(width - 28);
|
||||
}
|
||||
else if ( !wcscmp(argv[1],L"backup") )
|
||||
{
|
||||
pathSize = int((width-21)/2);
|
||||
}
|
||||
|
||||
wstring spathSize = L"--path-display-size=";
|
||||
string sps = SSTR(pathSize);
|
||||
std::wstring wspathSize(sps.begin(), sps.end());
|
||||
spathSize+=wspathSize;
|
||||
absolutedargs.push_back(spathSize);
|
||||
}
|
||||
|
||||
if (!wcscmp(argv[1],L"sync"))
|
||||
{
|
||||
for (int i = 2; i < argc; i++)
|
||||
@ -504,6 +648,194 @@ std::string readresponse(const char *question)
|
||||
return response;
|
||||
}
|
||||
|
||||
void printprogress(long long completed, long long total, const char *title)
|
||||
{
|
||||
static bool alreadyFinished = false; //flag to show progress
|
||||
static float percentDowloaded = 0.0;
|
||||
|
||||
float oldpercent = percentDowloaded;
|
||||
if (total == 0)
|
||||
{
|
||||
percentDowloaded = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
percentDowloaded = float(completed * 1.0 / total * 100.0);
|
||||
}
|
||||
if (completed != PROGRESS_COMPLETE && (alreadyFinished || ( ( percentDowloaded == oldpercent ) && ( oldpercent != 0 ) ) ))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (percentDowloaded < 0)
|
||||
{
|
||||
percentDowloaded = 0;
|
||||
}
|
||||
|
||||
if (total < 0)
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
}
|
||||
if (completed != PROGRESS_COMPLETE && completed < 0.001 * total)
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
}
|
||||
if (completed == PROGRESS_COMPLETE)
|
||||
{
|
||||
alreadyFinished = true;
|
||||
completed = total;
|
||||
percentDowloaded = 100;
|
||||
}
|
||||
|
||||
printPercentageLineCerr(title, completed, total, percentDowloaded, !alreadyFinished);
|
||||
}
|
||||
|
||||
void statechangehandle(string statestring)
|
||||
{
|
||||
char statedelim[2]={(char)0x1F,'\0'};
|
||||
size_t nextstatedelimitpos = statestring.find(statedelim);
|
||||
static bool shown_partial_progress = false;
|
||||
|
||||
while (nextstatedelimitpos!=string::npos && statestring.size())
|
||||
{
|
||||
string newstate = statestring.substr(0,nextstatedelimitpos);
|
||||
statestring=statestring.substr(nextstatedelimitpos+1);
|
||||
nextstatedelimitpos = statestring.find(statedelim);
|
||||
if (newstate.compare(0, strlen("prompt:"), "prompt:") == 0)
|
||||
{
|
||||
//ignore prompt state
|
||||
}
|
||||
else if (newstate.compare(0, strlen("endtransfer:"), "endtransfer:") == 0)
|
||||
{
|
||||
string rest = newstate.substr(strlen("endtransfer:"));
|
||||
if (rest.size() >=3)
|
||||
{
|
||||
bool isdown = rest.at(0) == 'D';
|
||||
string path = rest.substr(2);
|
||||
|
||||
stringstream os;
|
||||
if (shown_partial_progress)
|
||||
{
|
||||
os << endl;
|
||||
}
|
||||
|
||||
os << (isdown?"Download":"Upload") << " finished: " << path << endl;
|
||||
|
||||
#ifdef _WIN32
|
||||
wstring wbuffer;
|
||||
stringtolocalw((const char*)os.str().data(),&wbuffer);
|
||||
int oldmode;
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
oldmode = _setmode(_fileno(stdout), _O_U8TEXT);
|
||||
OUTSTREAM << wbuffer << flush;
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
|
||||
#else
|
||||
OUTSTREAM << os.str();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (newstate.compare(0, strlen("message:"), "message:") == 0)
|
||||
{
|
||||
string contents = newstate.substr(strlen("message:"));
|
||||
unsigned int width = getNumberOfCols(80);
|
||||
if (width > 1 ) width--;
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
if (shown_partial_progress)
|
||||
{
|
||||
cerr << endl;
|
||||
}
|
||||
if (contents.find("-----") != 0)
|
||||
{
|
||||
printCenteredContentsCerr(contents, width);
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << endl << contents << endl;
|
||||
}
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
}
|
||||
else if (newstate.compare(0, strlen("clientID:"), "clientID:") == 0)
|
||||
{
|
||||
clientID = newstate.substr(strlen("clientID:")).c_str();
|
||||
}
|
||||
else if (newstate.compare(0, strlen("progress:"), "progress:") == 0)
|
||||
{
|
||||
string rest = newstate.substr(strlen("progress:"));
|
||||
|
||||
size_t nexdel = rest.find(":");
|
||||
string received = rest.substr(0,nexdel);
|
||||
|
||||
rest = rest.substr(nexdel+1);
|
||||
nexdel = rest.find(":");
|
||||
string total = rest.substr(0,nexdel);
|
||||
|
||||
string title;
|
||||
if ( (nexdel != string::npos) && (nexdel < rest.size() ) )
|
||||
{
|
||||
rest = rest.substr(nexdel+1);
|
||||
nexdel = rest.find(":");
|
||||
title = rest.substr(0,nexdel);
|
||||
}
|
||||
|
||||
if (received!=SPROGRESS_COMPLETE)
|
||||
{
|
||||
shown_partial_progress = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
shown_partial_progress = false;
|
||||
}
|
||||
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
if (title.size())
|
||||
{
|
||||
if (received==SPROGRESS_COMPLETE)
|
||||
{
|
||||
printprogress(PROGRESS_COMPLETE, charstoll(total.c_str()),title.c_str());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printprogress(charstoll(received.c_str()), charstoll(total.c_str()),title.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (received==SPROGRESS_COMPLETE)
|
||||
{
|
||||
printprogress(PROGRESS_COMPLETE, charstoll(total.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
printprogress(charstoll(received.c_str()), charstoll(total.c_str()));
|
||||
}
|
||||
}
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
}
|
||||
else if (newstate == "ack")
|
||||
{
|
||||
// do nothing, all good
|
||||
}
|
||||
else if (newstate == "restart")
|
||||
{
|
||||
// ignore restart command
|
||||
}
|
||||
else
|
||||
{
|
||||
//received unrecognized state change. sleep a while to avoid continuous looping
|
||||
sleepMilliSeconds(1000);
|
||||
}
|
||||
|
||||
if (newstate.compare(0, strlen("progress:"), "progress:") != 0)
|
||||
{
|
||||
shown_partial_progress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@ -532,6 +864,9 @@ int main(int argc, char* argv[])
|
||||
#else
|
||||
MegaCmdShellCommunications *comms = new MegaCmdShellCommunications();
|
||||
#endif
|
||||
|
||||
comms->registerForStateChanges(statechangehandle);
|
||||
|
||||
#ifdef _WIN32
|
||||
int wargc;
|
||||
LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(),&wargc);
|
||||
|
2
src/client/win/mega-df.bat
Normal file
2
src/client/win/mega-df.bat
Normal file
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
"%~dp0MegaClient.exe" df %*
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanager.cpp
|
||||
* @brief MEGAcmd: Communications manager non supporting non-interactive mode
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanager.h
|
||||
* @brief MEGAcmd: Communications manager non supporting non-interactive mode
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -20,6 +20,7 @@
|
||||
#define COMUNICATIONSMANAGER_H
|
||||
|
||||
#include "megacmd.h"
|
||||
#include "megacmdcommonutils.h"
|
||||
|
||||
static const int MAXCMDSTATELISTENERS = 300;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagerfilesockets.cpp
|
||||
* @brief MEGAcmd: Communications manager using Network Sockets
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -135,6 +135,7 @@ ComunicationsManagerFileSockets::ComunicationsManagerFileSockets()
|
||||
{
|
||||
count = 0;
|
||||
mtx = new MegaMutex();
|
||||
informerMutex = new MegaMutex(false);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@ -357,35 +358,43 @@ void ComunicationsManagerFileSockets::sendPartialOutput(CmdPetition *inf, OUTSTR
|
||||
return;
|
||||
}
|
||||
|
||||
int outCode = MCMD_PARTIALOUT;
|
||||
int n = send(connectedsocket, (void*)&outCode, sizeof( outCode ), MSG_NOSIGNAL);
|
||||
if (n < 0)
|
||||
if (s->size())
|
||||
{
|
||||
std::cerr << "ERROR writing MCMD_PARTIALOUT to socket: " << errno << endl;
|
||||
if (errno == EPIPE)
|
||||
size_t size = s->size();
|
||||
|
||||
int outCode = MCMD_PARTIALOUT;
|
||||
int n = send(connectedsocket, (void*)&outCode, sizeof( outCode ), MSG_NOSIGNAL);
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "WARNING: Client disconnected, the rest of the output will be discarded" << endl;
|
||||
inf->clientDisconnected = true;
|
||||
std::cerr << "ERROR writing MCMD_PARTIALOUT to socket: " << errno << endl;
|
||||
if (errno == EPIPE)
|
||||
{
|
||||
std::cerr << "WARNING: Client disconnected, the rest of the output will be discarded" << endl;
|
||||
inf->clientDisconnected = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
n = send(connectedsocket, (void*)&size, sizeof( size ), MSG_NOSIGNAL);
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "ERROR writing size of partial output to socket: " << errno << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
n = send(connectedsocket, s->data(), size, MSG_NOSIGNAL); // for some reason without the max recv never quits in the client for empty responses
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "ERROR writing to socket partial output: " << errno << endl;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
size_t size = s->size() > 1 ? s->size() : 1;
|
||||
n = send(connectedsocket, (void*)&size, sizeof( size ), MSG_NOSIGNAL);
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "ERROR writing size of partial output to socket: " << errno << endl;
|
||||
return;
|
||||
}
|
||||
n = send(connectedsocket, s->data(), size, MSG_NOSIGNAL); // for some reason without the max recv never quits in the client for empty responses
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "ERROR writing to socket partial output: " << errno << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int ComunicationsManagerFileSockets::informStateListener(CmdPetition *inf, string &s)
|
||||
{
|
||||
MutexGuard g(*informerMutex);
|
||||
LOG_verbose << "Inform State Listener: Output to write in socket " << ((CmdPetitionPosixSockets *)inf)->outSocket << ": <<" << s << ">>";
|
||||
|
||||
sockaddr_in cliAddr;
|
||||
@ -657,4 +666,5 @@ string ComunicationsManagerFileSockets::get_petition_details(CmdPetition *inf)
|
||||
ComunicationsManagerFileSockets::~ComunicationsManagerFileSockets()
|
||||
{
|
||||
delete mtx;
|
||||
delete informerMutex;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagerfilesockets.h
|
||||
* @brief MEGAcmd: Communications manager using Network Sockets
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -59,6 +59,7 @@ private:
|
||||
// to get next socket id
|
||||
int count;
|
||||
mega::MegaMutex *mtx;
|
||||
mega::MegaMutex *informerMutex;
|
||||
|
||||
/**
|
||||
* @brief create_new_socket
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagernamedPipes.cpp
|
||||
* @brief MegaCMD: Communications manager using Network NamedPipes
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -129,6 +129,7 @@ ComunicationsManagerNamedPipes::ComunicationsManagerNamedPipes()
|
||||
{
|
||||
count = 0;
|
||||
mtx = new MegaMutex();
|
||||
informerMutex = new MegaMutex(false);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@ -415,6 +416,8 @@ void ComunicationsManagerNamedPipes::sendPartialOutput(CmdPetition *inf, char *s
|
||||
|
||||
int ComunicationsManagerNamedPipes::informStateListener(CmdPetition *inf, string &s)
|
||||
{
|
||||
MutexGuard g(*informerMutex);
|
||||
|
||||
LOG_verbose << "Inform State Listener: Output to write in namedPipe " << ((CmdPetitionNamedPipes *)inf)->outNamedPipe << ": <<" << s << ">>";
|
||||
HANDLE outNamedPipe = ((CmdPetitionNamedPipes *)inf)->outNamedPipe;
|
||||
|
||||
@ -439,7 +442,7 @@ int ComunicationsManagerNamedPipes::informStateListener(CmdPetition *inf, string
|
||||
DWORD n;
|
||||
if (!WriteFile(outNamedPipe, s.data(), DWORD(s.size()), &n, NULL))
|
||||
{
|
||||
if (ERRNO == 32) //namedPipe closed
|
||||
if (ERRNO == 32 || ERRNO == 109 || (ERRNO == 232 && s == "ack")) //namedPipe closed | pipe has been ended
|
||||
{
|
||||
LOG_debug << "namedPipe closed. Client probably disconnected. Original petition: " << *inf;
|
||||
return -1;
|
||||
@ -618,6 +621,7 @@ string ComunicationsManagerNamedPipes::get_petition_details(CmdPetition *inf)
|
||||
ComunicationsManagerNamedPipes::~ComunicationsManagerNamedPipes()
|
||||
{
|
||||
delete mtx;
|
||||
delete informerMutex;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagerportnamedPipes.h
|
||||
* @brief MegaCMD: Communications manager using Network NamedPipes
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -58,6 +58,7 @@ private:
|
||||
// to get next namedPipe id
|
||||
int count;
|
||||
mega::MegaMutex *mtx;
|
||||
mega::MegaMutex *informerMutex;
|
||||
|
||||
/**
|
||||
* @brief create_new_namedPipe
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagerportsockets.cpp
|
||||
* @brief MEGAcmd: Communications manager using Network Sockets
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/comunicationsmanagerportsockets.h
|
||||
* @brief MEGAcmd: Communications manager using Network Sockets
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/configurationmanager.cpp
|
||||
* @brief MEGAcmd: configuration manager
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/configurationmanager.h
|
||||
* @brief MEGAcmd: configuration manager
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -8,29 +8,29 @@ noinst_HEADERS=
|
||||
MEGACMD = mega-cmd mega-exec mega-cmd-server
|
||||
bin_PROGRAMS += $(MEGACMD)
|
||||
$(MEGACMD): $(top_builddir)/sdk/src/libmega.la
|
||||
noinst_HEADERS += src/comunicationsmanager.h src/configurationmanager.h src/megacmd.h src/megacmdlogger.h src/megacmdsandbox.h src/megacmdutils.h src/listeners.h src/megacmdexecuter.h src/megacmdversion.h src/megacmdplatform.h src/comunicationsmanagerportsockets.h
|
||||
noinst_HEADERS += src/comunicationsmanager.h src/configurationmanager.h src/megacmd.h src/megacmdlogger.h src/megacmdsandbox.h src/megacmdutils.h src/megacmdcommonutils.h src/listeners.h src/megacmdexecuter.h src/megacmdversion.h src/megacmdplatform.h src/comunicationsmanagerportsockets.h
|
||||
megacmdcompletiondir = $(sysconfdir)/bash_completion.d/
|
||||
megacmdcompletion_DATA = src/client/megacmd_completion.sh
|
||||
megacmdscripts_bindir = $(bindir)
|
||||
|
||||
megacmdscripts_bin_SCRIPTS = src/client/mega-attr src/client/mega-cd src/client/mega-confirm src/client/mega-cp src/client/mega-debug src/client/mega-du src/client/mega-export src/client/mega-find src/client/mega-get src/client/mega-help src/client/mega-https src/client/mega-webdav src/client/mega-permissions src/client/mega-deleteversions src/client/mega-transfers src/client/mega-import src/client/mega-invite src/client/mega-ipc src/client/mega-killsession src/client/mega-lcd src/client/mega-log src/client/mega-login src/client/mega-logout src/client/mega-lpwd src/client/mega-ls src/client/mega-backup src/client/mega-mkdir src/client/mega-mount src/client/mega-mv src/client/mega-passwd src/client/mega-preview src/client/mega-put src/client/mega-speedlimit src/client/mega-pwd src/client/mega-quit src/client/mega-reload src/client/mega-rm src/client/mega-session src/client/mega-share src/client/mega-showpcr src/client/mega-signup src/client/mega-sync src/client/mega-exclude src/client/mega-thumbnail src/client/mega-userattr src/client/mega-users src/client/mega-version src/client/mega-whoami src/client/mega-cat src/client/mega-tree src/client/mega-mediainfo src/client/mega-graphics src/client/mega-ftp src/client/mega-cancel src/client/mega-confirmcancel src/client/mega-errorcode
|
||||
megacmdscripts_bin_SCRIPTS = src/client/mega-attr src/client/mega-cd src/client/mega-confirm src/client/mega-cp src/client/mega-debug src/client/mega-du src/client/mega-df src/client/mega-export src/client/mega-find src/client/mega-get src/client/mega-help src/client/mega-https src/client/mega-webdav src/client/mega-permissions src/client/mega-deleteversions src/client/mega-transfers src/client/mega-import src/client/mega-invite src/client/mega-ipc src/client/mega-killsession src/client/mega-lcd src/client/mega-log src/client/mega-login src/client/mega-logout src/client/mega-lpwd src/client/mega-ls src/client/mega-backup src/client/mega-mkdir src/client/mega-mount src/client/mega-mv src/client/mega-passwd src/client/mega-preview src/client/mega-put src/client/mega-speedlimit src/client/mega-pwd src/client/mega-quit src/client/mega-reload src/client/mega-rm src/client/mega-session src/client/mega-share src/client/mega-showpcr src/client/mega-signup src/client/mega-sync src/client/mega-exclude src/client/mega-thumbnail src/client/mega-userattr src/client/mega-users src/client/mega-version src/client/mega-whoami src/client/mega-cat src/client/mega-tree src/client/mega-mediainfo src/client/mega-graphics src/client/mega-ftp src/client/mega-cancel src/client/mega-confirmcancel src/client/mega-errorcode
|
||||
|
||||
mega_cmd_server_SOURCES = src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp
|
||||
mega_cmd_server_SOURCES = src/megacmd.cpp src/comunicationsmanager.cpp src/megacmdutils.cpp src/megacmdcommonutils.cpp src/configurationmanager.cpp src/megacmdlogger.cpp src/megacmdsandbox.cpp src/listeners.cpp src/megacmdexecuter.cpp src/comunicationsmanagerportsockets.cpp
|
||||
|
||||
mega_cmddir=examples
|
||||
|
||||
#CMDCLIENT
|
||||
noinst_HEADERS += src/megacmdshell/megacmdshellcommunications.h src/megacmdshell/megacmdshell.h sdk/include/mega/thread.h
|
||||
noinst_HEADERS += src/megacmdcommonutils.h src/megacmdshell/megacmdshellcommunications.h src/megacmdshell/megacmdshell.h sdk/include/mega/thread.h
|
||||
|
||||
mega_exec_SOURCES = src/client/megacmdclient.cpp src/megacmdshell/megacmdshellcommunications.cpp
|
||||
mega_exec_SOURCES = src/megacmdcommonutils.cpp src/client/megacmdclient.cpp src/megacmdshell/megacmdshellcommunications.cpp
|
||||
mega_execdir=examples
|
||||
#mega_exec_CXXFLAGS = -std=c++11 -DUSE_CPPTHREAD=1 -Iinclude/
|
||||
#mega_exec_CXXFLAGS = -Iinclude/
|
||||
mega_exec_CXXFLAGS = -Isdk/include/ $(LMEGAINC)
|
||||
|
||||
#CMDSHELL
|
||||
noinst_HEADERS += src/megacmdshell/megacmdshellcommunications.h src/megacmdshell/megacmdshell.h sdk/include/mega/thread.h
|
||||
mega_cmd_SOURCES = src/megacmdshell/megacmdshellcommunications.cpp src/megacmdshell/megacmdshell.cpp
|
||||
noinst_HEADERS += src/megacmdcommonutils.h src/megacmdshell/megacmdshellcommunications.h src/megacmdshell/megacmdshell.h sdk/include/mega/thread.h
|
||||
mega_cmd_SOURCES = src/megacmdcommonutils.cpp src/megacmdshell/megacmdshellcommunications.cpp src/megacmdshell/megacmdshell.cpp
|
||||
|
||||
mega_cmd_CXXFLAGS = $(RL_CXXFLAGS) -Isdk/include/ $(LMEGAINC)
|
||||
mega_cmd_LDADD = $(RL_LDFLAGS) $(RL_LIBS) $(TERMCAP_LDFLAGS) $(TERMCAP_LIBS)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/listeners.cpp
|
||||
* @brief MEGAcmd: Listeners
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -175,6 +175,7 @@ void MegaCmdGlobalListener::onEvent(MegaApi *api, MegaEvent *event)
|
||||
}
|
||||
else if (event->getType() == MegaEvent::EVENT_CONNECTIVITY_CHANGED)
|
||||
{
|
||||
LOG_debug << "Received event connectivity changed: " << event->getNumber();
|
||||
if (event->getNumber() == RETRY_CONNECTIVITY)
|
||||
{
|
||||
broadcastMessage(SSTR(event->getNumber()), "connectivity:");
|
||||
@ -184,6 +185,43 @@ void MegaCmdGlobalListener::onEvent(MegaApi *api, MegaEvent *event)
|
||||
broadcastMessage(SSTR(event->getNumber()), "connectivity:");
|
||||
}
|
||||
}
|
||||
else if (event->getType() == MegaEvent::EVENT_STORAGE)
|
||||
{
|
||||
if (event->getNumber() == MegaApi::STORAGE_STATE_CHANGE)
|
||||
{
|
||||
api->getAccountDetails();
|
||||
}
|
||||
else
|
||||
{
|
||||
int previousStatus = sandboxCMD->storageStatus;
|
||||
sandboxCMD->storageStatus = event->getNumber();
|
||||
if (sandboxCMD->storageStatus == MegaApi::STORAGE_STATE_RED || sandboxCMD->storageStatus == MegaApi::STORAGE_STATE_ORANGE)
|
||||
{
|
||||
ConfigurationManager::savePropertyValue("ask4storage",true);
|
||||
|
||||
if (previousStatus < sandboxCMD->storageStatus)
|
||||
{
|
||||
string s;
|
||||
if (sandboxCMD->storageStatus == MegaApi::STORAGE_STATE_RED)
|
||||
{
|
||||
s+= "You have exeeded your available storage.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
s+= "You are running out of available storage.\n";
|
||||
}
|
||||
s+="You can change your account plan to increase your quota limit.\nSee \"help --upgrade\" for further details";
|
||||
broadcastMessage(s);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigurationManager::savePropertyValue("ask4storage",false);
|
||||
}
|
||||
|
||||
}
|
||||
LOG_info << "Received event storage changed: " << event->getNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -193,7 +231,16 @@ void MegaCmdGlobalListener::onEvent(MegaApi *api, MegaEvent *event)
|
||||
|
||||
void MegaCmdMegaListener::onRequestFinish(MegaApi *api, MegaRequest *request, MegaError *e)
|
||||
{
|
||||
if (e && ( e->getErrorCode() == MegaError::API_ESID ))
|
||||
if (request->getType() == MegaRequest::TYPE_APP_VERSION)
|
||||
{
|
||||
LOG_verbose << "TYPE_APP_VERSION finished";
|
||||
}
|
||||
else if (request->getType() == MegaRequest::TYPE_LOGOUT)
|
||||
{
|
||||
LOG_debug << "Session closed";
|
||||
sandboxCMD->resetSandBox();
|
||||
}
|
||||
else if (e && ( e->getErrorCode() == MegaError::API_ESID ))
|
||||
{
|
||||
LOG_err << "Session is no longer valid (it might have been invalidated from elsewhere) ";
|
||||
changeprompt(prompts[COMMAND]);
|
||||
@ -204,10 +251,11 @@ void MegaCmdMegaListener::onRequestFinish(MegaApi *api, MegaRequest *request, Me
|
||||
}
|
||||
}
|
||||
|
||||
MegaCmdMegaListener::MegaCmdMegaListener(MegaApi *megaApi, MegaListener *parent)
|
||||
MegaCmdMegaListener::MegaCmdMegaListener(MegaApi *megaApi, MegaListener *parent, MegaCmdSandbox *sandboxCMD)
|
||||
{
|
||||
this->megaApi = megaApi;
|
||||
this->listener = parent;
|
||||
this->sandboxCMD = sandboxCMD;
|
||||
}
|
||||
|
||||
MegaCmdMegaListener::~MegaCmdMegaListener()
|
||||
@ -239,6 +287,14 @@ void MegaCmdMegaListener::onBackupStart(MegaApi *api, MegaBackup *backup)
|
||||
void MegaCmdMegaListener::onBackupFinish(MegaApi* api, MegaBackup *backup, MegaError* error)
|
||||
{
|
||||
LOG_verbose << " At onBackupFinish";
|
||||
if (error->getErrorCode() == MegaError::API_EEXPIRED)
|
||||
{
|
||||
LOG_warn << "Backup skipped (the time for the next one has been reached)";
|
||||
}
|
||||
else if (error->getErrorCode() != MegaError::API_OK)
|
||||
{
|
||||
LOG_err << "Backup failed: " << error->getErrorString();
|
||||
}
|
||||
}
|
||||
|
||||
void MegaCmdMegaListener::onBackupUpdate(MegaApi *api, MegaBackup *backup)
|
||||
@ -249,6 +305,10 @@ void MegaCmdMegaListener::onBackupUpdate(MegaApi *api, MegaBackup *backup)
|
||||
void MegaCmdMegaListener::onBackupTemporaryError(MegaApi *api, MegaBackup *backup, MegaError* error)
|
||||
{
|
||||
LOG_verbose << " At onBackupTemporaryError";
|
||||
if (error->getErrorCode() != MegaError::API_OK)
|
||||
{
|
||||
LOG_err << "Backup temporary error: " << error->getErrorString();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
////////////////////////////////////////
|
||||
@ -317,7 +377,6 @@ void MegaCmdListener::doOnRequestFinish(MegaApi* api, MegaRequest *request, Mega
|
||||
}
|
||||
#endif
|
||||
informProgressUpdate(PROGRESS_COMPLETE, request->getTotalBytes(), this->clientID, "Fetching nodes");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -382,7 +441,16 @@ void MegaCmdListener::onRequestUpdate(MegaApi* api, MegaRequest *request)
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
}
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", request->getTransferredBytes() / 1024 / 1024, request->getTotalBytes() / 1024 / 1024, percentFetchnodes);
|
||||
|
||||
if (request->getTotalBytes() < 1048576)
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld KB: %.2f %%) ", request->getTransferredBytes() / 1024, request->getTotalBytes() / 1024, percentFetchnodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", request->getTransferredBytes() / 1024 / 1024, request->getTotalBytes() / 1024 / 1024, percentFetchnodes);
|
||||
}
|
||||
|
||||
sprintf((char *)outputString.c_str() + cols - strlen(aux), "%s", aux);
|
||||
for (int i = 0; i <= ( cols - strlen("Fetching nodes ||") - strlen(aux)) * 1.0 * percentFetchnodes / 100.0; i++)
|
||||
{
|
||||
@ -523,7 +591,16 @@ void MegaCmdTransferListener::onTransferUpdate(MegaApi* api, MegaTransfer *trans
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
}
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", (long long)(transfer->getTransferredBytes() / 1024 / 1024), (long long)(transfer->getTotalBytes() / 1024 / 1024), (float)percentDownloaded);
|
||||
|
||||
if (transfer->getTotalBytes() < 1048576)
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld KB: %.2f %%) ", (long long)(transfer->getTransferredBytes() / 1024), (long long)(transfer->getTotalBytes() / 1024), (float)percentDownloaded);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", (long long)(transfer->getTransferredBytes() / 1024 / 1024), (long long)(transfer->getTotalBytes() / 1024 / 1024), (float)percentDownloaded);
|
||||
}
|
||||
sprintf((char *)outputString.c_str() + cols - strlen(aux), "%s", aux);
|
||||
for (int i = 0; i <= ( cols - strlen("TRANSFERRING ||") - strlen(aux)) * 1.0 * percentDownloaded / 100.0; i++)
|
||||
{
|
||||
@ -614,6 +691,33 @@ void MegaCmdMultiTransferListener::doOnTransferFinish(MegaApi* api, MegaTransfer
|
||||
}
|
||||
|
||||
LOG_verbose << "doOnTransferFinish MegaCmdMultiTransferListener Transfer->getType(): " << transfer->getType() << " transferring " << transfer->getFileName();
|
||||
|
||||
if (e->getErrorCode() == API_OK)
|
||||
{
|
||||
// communicate status info
|
||||
string s= "endtransfer:";
|
||||
s+=((transfer->getType() == MegaTransfer::TYPE_DOWNLOAD)?"D":"U");
|
||||
s+=":";
|
||||
if (transfer->getType() == MegaTransfer::TYPE_UPLOAD)
|
||||
{
|
||||
MegaNode *n = api->getNodeByHandle(transfer->getNodeHandle());
|
||||
if (n)
|
||||
{
|
||||
const char *path = api->getNodePath(n);
|
||||
if (path)
|
||||
{
|
||||
s+=path;
|
||||
}
|
||||
delete [] path;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s+=transfer->getPath();
|
||||
}
|
||||
informStateListenerByClientId(this->clientID, s);
|
||||
}
|
||||
|
||||
map<int, long long>::iterator itr = ongoingtransferredbytes.find(transfer->getTag());
|
||||
if ( itr!= ongoingtransferredbytes.end())
|
||||
{
|
||||
@ -693,7 +797,14 @@ void MegaCmdMultiTransferListener::onTransferUpdate(MegaApi* api, MegaTransfer *
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
}
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", (transferredbytes + getOngoingTransferredBytes()) / 1024 / 1024, (totalbytes + getOngoingTotalBytes() ) / 1024 / 1024, percentDownloaded);
|
||||
if (totalbytes + getOngoingTotalBytes() < 1048576)
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld KB: %.2f %%) ", (transferredbytes + getOngoingTransferredBytes()) / 1024, (totalbytes + getOngoingTotalBytes() ) / 1024, percentDownloaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld MB: %.2f %%) ", (transferredbytes + getOngoingTransferredBytes()) / 1024 / 1024, (totalbytes + getOngoingTotalBytes() ) / 1024 / 1024, percentDownloaded);
|
||||
}
|
||||
sprintf((char *)outputString.c_str() + cols - strlen(aux), "%s", aux);
|
||||
for (int i = 0; i <= ( cols - strlen("TRANSFERRING ||") - strlen(aux)) * 1.0 * min (100.0f, percentDownloaded) / 100.0; i++)
|
||||
{
|
||||
@ -713,7 +824,7 @@ void MegaCmdMultiTransferListener::onTransferUpdate(MegaApi* api, MegaTransfer *
|
||||
LOG_verbose << "onTransferUpdate transfer->getType(): " << transfer->getType() << " clientID=" << this->clientID;
|
||||
|
||||
informProgressUpdate((transferredbytes + getOngoingTransferredBytes()),(totalbytes + getOngoingTotalBytes() ), clientID);
|
||||
|
||||
progressinformed = true;
|
||||
|
||||
}
|
||||
|
||||
@ -757,6 +868,11 @@ long long MegaCmdMultiTransferListener::getOngoingTotalBytes()
|
||||
return total;
|
||||
}
|
||||
|
||||
bool MegaCmdMultiTransferListener::getProgressinformed() const
|
||||
{
|
||||
return progressinformed;
|
||||
}
|
||||
|
||||
MegaCmdMultiTransferListener::MegaCmdMultiTransferListener(MegaApi *megaApi, MegaCmdSandbox *sandboxCMD, MegaTransferListener *listener, int clientID)
|
||||
{
|
||||
this->megaApi = megaApi;
|
||||
@ -771,6 +887,8 @@ MegaCmdMultiTransferListener::MegaCmdMultiTransferListener(MegaApi *megaApi, Meg
|
||||
totalbytes = 0;
|
||||
transferredbytes = 0;
|
||||
|
||||
progressinformed = false;
|
||||
|
||||
finalerror = MegaError::API_OK;
|
||||
|
||||
}
|
||||
@ -827,15 +945,14 @@ void MegaCmdGlobalTransferListener::onTransferStart(MegaApi* api, MegaTransfer *
|
||||
void MegaCmdGlobalTransferListener::onTransferUpdate(MegaApi* api, MegaTransfer *transfer) {};
|
||||
void MegaCmdGlobalTransferListener::onTransferTemporaryError(MegaApi *api, MegaTransfer *transfer, MegaError* e)
|
||||
{
|
||||
|
||||
if (e && e->getErrorCode() == MegaError::API_EOVERQUOTA)
|
||||
if (e && e->getErrorCode() == MegaError::API_EOVERQUOTA && e->getValue())
|
||||
{
|
||||
if (!sandboxCMD->isOverquota())
|
||||
{
|
||||
LOG_warn << "Reached bandwidth quota. Your download could not proceed "
|
||||
"because it would take you over the current free transfer allowance for your IP address. "
|
||||
"This limit is dynamic and depends on the amount of unused bandwidth we have available. "
|
||||
"You can change your account plan to increse such bandwidth. "
|
||||
"You can change your account plan to increase such bandwidth. "
|
||||
"See \"help --upgrade\" for further details";
|
||||
}
|
||||
sandboxCMD->setOverquota(true);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/listeners.h
|
||||
* @brief MEGAcmd: Listeners
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -99,6 +99,8 @@ private:
|
||||
long long getOngoingTransferredBytes();
|
||||
long long getOngoingTotalBytes();
|
||||
|
||||
bool progressinformed;
|
||||
|
||||
public:
|
||||
MegaCmdMultiTransferListener(mega::MegaApi *megaApi, MegaCmdSandbox * sandboxCMD, mega::MegaTransferListener *listener = NULL, int clientID=-1);
|
||||
virtual ~MegaCmdMultiTransferListener();
|
||||
@ -118,6 +120,8 @@ public:
|
||||
|
||||
long long getTotalbytes() const;
|
||||
|
||||
bool getProgressinformed() const;
|
||||
|
||||
protected:
|
||||
mega::MegaTransferListener *listener;
|
||||
};
|
||||
@ -144,7 +148,7 @@ class MegaCmdMegaListener : public mega::MegaListener
|
||||
{
|
||||
|
||||
public:
|
||||
MegaCmdMegaListener(mega::MegaApi *megaApi, mega::MegaListener *parent=NULL);
|
||||
MegaCmdMegaListener(mega::MegaApi *megaApi, mega::MegaListener *parent=NULL, MegaCmdSandbox *sandboxCMD = NULL);
|
||||
virtual ~MegaCmdMegaListener();
|
||||
|
||||
virtual void onRequestFinish(mega::MegaApi* api, mega::MegaRequest *request, mega::MegaError* e);
|
||||
@ -164,6 +168,7 @@ public:
|
||||
protected:
|
||||
mega::MegaApi *megaApi;
|
||||
mega::MegaListener *listener;
|
||||
MegaCmdSandbox *sandboxCMD;
|
||||
};
|
||||
|
||||
class MegaCmdGlobalTransferListener : public mega::MegaTransferListener
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/loader/megacmdloader.cpp
|
||||
* @brief MEGAcmdClient: Loader application of MEGAcmd for MAC
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
358
src/megacmd.cpp
358
src/megacmd.cpp
@ -2,7 +2,7 @@
|
||||
* @file src/megacmd.cpp
|
||||
* @brief MEGAcmd: Interactive CLI and service application
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -75,70 +75,6 @@ typedef char *completionfunction_t PARAMS((const char *, int));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// convert UTF-8 to Windows Unicode wstring
|
||||
void stringtolocalw(const char* path, std::wstring* local)
|
||||
{
|
||||
// make space for the worst case
|
||||
local->resize((strlen(path) + 1) * sizeof(wchar_t));
|
||||
|
||||
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, path,-1, NULL,0);
|
||||
local->resize(wchars_num);
|
||||
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, path,-1, (wchar_t*)local->data(), wchars_num);
|
||||
|
||||
if (len)
|
||||
{
|
||||
local->resize(len-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
local->clear();
|
||||
}
|
||||
}
|
||||
|
||||
//widechar to utf8 string
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte)
|
||||
{
|
||||
if( !wide->empty() )
|
||||
{
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), NULL, 0, NULL, NULL);
|
||||
multibyte->resize(size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), (char*)multibyte->data(), size_needed, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//override << operators for wostream for string and const char *
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str.c_str(),&toout);
|
||||
ostr << toout;
|
||||
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str,&toout);
|
||||
ostr << toout;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
//override for the log. This is required for compiling, otherwise SimpleLog won't compile.
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str)
|
||||
{
|
||||
std::string s;
|
||||
localwtostring(&str,&s);
|
||||
ostr << s;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef USE_PORT_COMMS
|
||||
#include "comunicationsmanagerportsockets.h"
|
||||
@ -197,7 +133,7 @@ vector<string> remotepatterncommands(aremotepatterncommands, aremotepatterncomma
|
||||
string aremotefolderspatterncommands[] = {"cd", "share"};
|
||||
vector<string> remotefolderspatterncommands(aremotefolderspatterncommands, aremotefolderspatterncommands + sizeof aremotefolderspatterncommands / sizeof aremotefolderspatterncommands[0]);
|
||||
|
||||
string amultipleremotepatterncommands[] = {"ls", "tree", "mkdir", "rm", "du", "find", "mv", "deleteversions", "cat"
|
||||
string amultipleremotepatterncommands[] = {"ls", "tree", "mkdir", "rm", "du", "find", "mv", "deleteversions", "cat", "mediainfo"
|
||||
#ifdef HAVE_LIBUV
|
||||
, "webdav", "ftp"
|
||||
#endif
|
||||
@ -210,17 +146,17 @@ vector<string> remoteremotepatterncommands(aremoteremotepatterncommands, aremote
|
||||
string aremotelocalpatterncommands[] = {"get", "thumbnail", "preview"};
|
||||
vector<string> remotelocalpatterncommands(aremotelocalpatterncommands, aremotelocalpatterncommands + sizeof aremotelocalpatterncommands / sizeof aremotelocalpatterncommands[0]);
|
||||
|
||||
string alocalpatterncommands [] = {"lcd"};
|
||||
vector<string> localpatterncommands(alocalpatterncommands, alocalpatterncommands + sizeof alocalpatterncommands / sizeof alocalpatterncommands[0]);
|
||||
string alocalfolderpatterncommands [] = {"lcd"};
|
||||
vector<string> localfolderpatterncommands(alocalfolderpatterncommands, alocalfolderpatterncommands + sizeof alocalfolderpatterncommands / sizeof alocalfolderpatterncommands[0]);
|
||||
|
||||
string aemailpatterncommands [] = {"invite", "signup", "ipc", "users"};
|
||||
vector<string> emailpatterncommands(aemailpatterncommands, aemailpatterncommands + sizeof aemailpatterncommands / sizeof aemailpatterncommands[0]);
|
||||
|
||||
string avalidCommands [] = { "login", "signup", "confirm", "session", "mount", "ls", "cd", "log", "debug", "pwd", "lcd", "lpwd", "import", "masterkey",
|
||||
"put", "get", "attr", "userattr", "mkdir", "rm", "du", "mv", "cp", "sync", "export", "share", "invite", "ipc",
|
||||
"put", "get", "attr", "userattr", "mkdir", "rm", "du", "mv", "cp", "sync", "export", "share", "invite", "ipc", "df",
|
||||
"showpcr", "users", "speedlimit", "killsession", "whoami", "help", "passwd", "reload", "logout", "version", "quit",
|
||||
"thumbnail", "preview", "find", "completion", "clear", "https", "transfers", "exclude", "exit", "errorcode", "graphics",
|
||||
"cancel", "confirmcancel", "cat", "tree"
|
||||
"cancel", "confirmcancel", "cat", "tree", "psa"
|
||||
, "mediainfo"
|
||||
#ifdef HAVE_LIBUV
|
||||
, "webdav", "ftp"
|
||||
@ -236,7 +172,7 @@ string avalidCommands [] = { "login", "signup", "confirm", "session", "mount", "
|
||||
#else
|
||||
, "permissions"
|
||||
#endif
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
, "update"
|
||||
#endif
|
||||
};
|
||||
@ -358,6 +294,17 @@ void changeprompt(const char *newprompt)
|
||||
cm->informStateListeners(s);
|
||||
}
|
||||
|
||||
void informStateListener(string message, int clientID)
|
||||
{
|
||||
string s;
|
||||
if (message.size())
|
||||
{
|
||||
s += "message:";
|
||||
s+=message;
|
||||
}
|
||||
cm->informStateListenerByClientId(s, clientID);
|
||||
}
|
||||
|
||||
void broadcastMessage(string message, const char *suffix)
|
||||
{
|
||||
string s;
|
||||
@ -374,6 +321,11 @@ void informTransferUpdate(MegaTransfer *transfer, int clientID)
|
||||
informProgressUpdate(transfer->getTransferredBytes(),transfer->getTotalBytes(), clientID);
|
||||
}
|
||||
|
||||
void informStateListenerByClientId(int clientID, string s)
|
||||
{
|
||||
cm->informStateListenerByClientId(s, clientID);
|
||||
}
|
||||
|
||||
void informProgressUpdate(long long transferred, long long total, int clientID, string title)
|
||||
{
|
||||
string s = "progress:";
|
||||
@ -387,7 +339,7 @@ void informProgressUpdate(long long transferred, long long total, int clientID,
|
||||
s+=title;
|
||||
}
|
||||
|
||||
cm->informStateListenerByClientId(s, clientID);
|
||||
informStateListenerByClientId(clientID, s);
|
||||
}
|
||||
|
||||
void insertValidParamsPerCommand(set<string> *validParams, string thecommand, set<string> *validOptValues = NULL)
|
||||
@ -413,6 +365,7 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
else if ("passwd" == thecommand)
|
||||
{
|
||||
validParams->insert("f");
|
||||
validOptValues->insert("auth-code");
|
||||
}
|
||||
else if ("du" == thecommand)
|
||||
{
|
||||
@ -467,6 +420,10 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
{
|
||||
validParams->insert("l");
|
||||
}
|
||||
else if ("df" == thecommand)
|
||||
{
|
||||
validParams->insert("h");
|
||||
}
|
||||
else if ("mediainfo" == thecommand)
|
||||
{
|
||||
validOptValues->insert("path-display-size");
|
||||
@ -622,6 +579,7 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
{
|
||||
validOptValues->insert("user");
|
||||
validParams->insert("s");
|
||||
validParams->insert("list");
|
||||
}
|
||||
else if ("ipc" == thecommand)
|
||||
{
|
||||
@ -668,6 +626,11 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
else if ("login" == thecommand)
|
||||
{
|
||||
validOptValues->insert("clientID");
|
||||
validOptValues->insert("auth-code");
|
||||
}
|
||||
else if ("psa" == thecommand)
|
||||
{
|
||||
validParams->insert("discard");
|
||||
}
|
||||
else if ("reload" == thecommand)
|
||||
{
|
||||
@ -676,6 +639,7 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
else if ("transfers" == thecommand)
|
||||
{
|
||||
validParams->insert("show-completed");
|
||||
validParams->insert("summary");
|
||||
validParams->insert("only-uploads");
|
||||
validParams->insert("only-completed");
|
||||
validParams->insert("only-downloads");
|
||||
@ -691,7 +655,7 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
||||
{
|
||||
validParams->insert("only-shell");
|
||||
}
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
else if ("update" == thecommand)
|
||||
{
|
||||
validOptValues->insert("auto");
|
||||
@ -792,7 +756,7 @@ char * flags_completion(const char*text, int state)
|
||||
{
|
||||
validparams.clear();
|
||||
char *saved_line = strdup(getCurrentThreadLine().c_str());
|
||||
vector<string> words = getlistOfWords(saved_line);
|
||||
vector<string> words = getlistOfWords(saved_line, !getCurrentThreadIsCmdShell());
|
||||
free(saved_line);
|
||||
if (words.size())
|
||||
{
|
||||
@ -851,7 +815,7 @@ char * flags_value_completion(const char*text, int state)
|
||||
validValues.clear();
|
||||
|
||||
char *saved_line = strdup(getCurrentThreadLine().c_str());
|
||||
vector<string> words = getlistOfWords(saved_line);
|
||||
vector<string> words = getlistOfWords(saved_line, !getCurrentThreadIsCmdShell());
|
||||
free(saved_line);
|
||||
saved_line = NULL;
|
||||
if (words.size() > 1)
|
||||
@ -927,10 +891,8 @@ char * flags_value_completion(const char*text, int state)
|
||||
end = string::npos;
|
||||
}
|
||||
|
||||
string location = stext.substr(begin, end);
|
||||
validValues = cmdexecuter->getlistfilesfolders(location.size()?location:"./");
|
||||
validValues = cmdexecuter->listlocalpathsstartingby(stext.substr(begin));
|
||||
string prefix = strncmp(text, cflag, strlen(cflag))?"":cflag;
|
||||
prefix.append(location);
|
||||
for (unsigned int i=0;i<validValues.size();i++)
|
||||
{
|
||||
validValues.at(i)=prefix+validValues.at(i);
|
||||
@ -950,7 +912,8 @@ void unescapeifRequired(string &what)
|
||||
}
|
||||
}
|
||||
|
||||
char* remotepaths_completion(const char* text, int state)
|
||||
|
||||
char* remotepaths_completion(const char* text, int state, bool onlyfolders)
|
||||
{
|
||||
static vector<string> validpaths;
|
||||
if (state == 0)
|
||||
@ -970,7 +933,7 @@ char* remotepaths_completion(const char* text, int state)
|
||||
|
||||
unescapeEspace(wildtext);
|
||||
|
||||
validpaths = cmdexecuter->listpaths(usepcre, wildtext);
|
||||
validpaths = cmdexecuter->listpaths(usepcre, wildtext, onlyfolders);
|
||||
|
||||
// we need to escape '\' to fit what's done when parsing words
|
||||
if (!getCurrentThreadIsCmdShell())
|
||||
@ -985,26 +948,14 @@ char* remotepaths_completion(const char* text, int state)
|
||||
return generic_completion(text, state, validpaths);
|
||||
}
|
||||
|
||||
char* remotepaths_completion(const char* text, int state)
|
||||
{
|
||||
return remotepaths_completion(text, state, false);
|
||||
}
|
||||
|
||||
char* remotefolders_completion(const char* text, int state)
|
||||
{
|
||||
static vector<string> validpaths;
|
||||
if (state == 0)
|
||||
{
|
||||
string wildtext(text);
|
||||
bool usepcre = false; //pcre makes no sense in paths completion
|
||||
if (usepcre)
|
||||
{
|
||||
#ifdef USE_PCRE
|
||||
wildtext += ".";
|
||||
#elif __cplusplus >= 201103L
|
||||
wildtext += ".";
|
||||
#endif
|
||||
}
|
||||
wildtext += "*";
|
||||
|
||||
validpaths = cmdexecuter->listpaths(usepcre, wildtext, true);
|
||||
}
|
||||
return generic_completion(text, state, validpaths);
|
||||
return remotepaths_completion(text, state, true);
|
||||
}
|
||||
|
||||
char* loglevels_completion(const char* text, int state)
|
||||
@ -1022,6 +973,18 @@ char* loglevels_completion(const char* text, int state)
|
||||
return generic_completion(text, state, validloglevels);
|
||||
}
|
||||
|
||||
char* localfolders_completion(const char* text, int state)
|
||||
{
|
||||
static vector<string> validpaths;
|
||||
if (state == 0)
|
||||
{
|
||||
string what(text);
|
||||
unescapeEspace(what);
|
||||
validpaths = cmdexecuter->listlocalpathsstartingby(what.c_str(), true);
|
||||
}
|
||||
return generic_completion(text, state, validpaths);
|
||||
}
|
||||
|
||||
char* transfertags_completion(const char* text, int state)
|
||||
{
|
||||
static vector<string> validtransfertags;
|
||||
@ -1088,7 +1051,7 @@ char* nodeattrs_completion(const char* text, int state)
|
||||
{
|
||||
validAttrs.clear();
|
||||
char *saved_line = strdup(getCurrentThreadLine().c_str());
|
||||
vector<string> words = getlistOfWords(saved_line);
|
||||
vector<string> words = getlistOfWords(saved_line, !getCurrentThreadIsCmdShell());
|
||||
free(saved_line);
|
||||
saved_line = NULL;
|
||||
if (words.size() > 1)
|
||||
@ -1122,23 +1085,6 @@ char* userattrs_completion(const char* text, int state)
|
||||
return generic_completion(text, state, validAttrs);
|
||||
}
|
||||
|
||||
void discardOptionsAndFlags(vector<string> *ws)
|
||||
{
|
||||
for (std::vector<string>::iterator it = ws->begin(); it != ws->end(); )
|
||||
{
|
||||
/* std::cout << *it; ... */
|
||||
string w = ( string ) * it;
|
||||
if (w.length() && ( w.at(0) == '-' )) //begins with "-"
|
||||
{
|
||||
it = ws->erase(it);
|
||||
}
|
||||
else //not an option/flag
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
completionfunction_t *getCompletionFunction(vector<string> words)
|
||||
{
|
||||
// Strip words without flags
|
||||
@ -1184,11 +1130,11 @@ completionfunction_t *getCompletionFunction(vector<string> words)
|
||||
return remotepaths_completion;
|
||||
}
|
||||
}
|
||||
else if (thecommand == "backup") //TODO: offer local folder completion
|
||||
else if (thecommand == "backup")
|
||||
{
|
||||
if (currentparameter == 1)
|
||||
{
|
||||
return local_completion;
|
||||
return localfolders_completion;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1216,11 +1162,11 @@ completionfunction_t *getCompletionFunction(vector<string> words)
|
||||
return remotepaths_completion;
|
||||
}
|
||||
}
|
||||
else if (stringcontained(thecommand.c_str(), localpatterncommands))
|
||||
else if (stringcontained(thecommand.c_str(), localfolderpatterncommands))
|
||||
{
|
||||
if (currentparameter == 1)
|
||||
{
|
||||
return local_completion;
|
||||
return localfolders_completion;
|
||||
}
|
||||
}
|
||||
else if (stringcontained(thecommand.c_str(), remoteremotepatterncommands))
|
||||
@ -1314,6 +1260,22 @@ string getListOfCompletionValues(vector<string> words, char separator = ' ', con
|
||||
return toret;
|
||||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
// // let MEGAcmdShell handle the local folder completion (available via autocomplete.cpp stuff that takes into account units/unicode/etc...)
|
||||
// else if (compfunction == localfolders_completion)
|
||||
// {
|
||||
// if (!interactiveThread())
|
||||
// {
|
||||
// return "MEGACMD_USE_LOCAL_COMPLETIONFOLDERS";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// string toret="MEGACMD_USE_LOCAL_COMPLETIONFOLDERS";
|
||||
// toret+=cmdexecuter->getLPWD();
|
||||
// return toret;
|
||||
// }
|
||||
// }
|
||||
#endif
|
||||
int state=0;
|
||||
if (words.size()>1)
|
||||
while (true)
|
||||
@ -1380,13 +1342,17 @@ const char * getUsageStr(const char *command)
|
||||
{
|
||||
if (interactiveThread())
|
||||
{
|
||||
return "login [email [password]] | exportedfolderurl#key | session";
|
||||
return "login [--auth-code=XXXX] [email [password]] | exportedfolderurl#key | session";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "login email password | exportedfolderurl#key | session";
|
||||
return "login [--auth-code=XXXX] email password | exportedfolderurl#key | session";
|
||||
}
|
||||
}
|
||||
if (!strcmp(command, "psa"))
|
||||
{
|
||||
return "psa [--discard]";
|
||||
}
|
||||
if (!strcmp(command, "cancel"))
|
||||
{
|
||||
return "cancel";
|
||||
@ -1524,7 +1490,7 @@ const char * getUsageStr(const char *command)
|
||||
}
|
||||
if (!strcmp(command, "userattr"))
|
||||
{
|
||||
return "userattr [-s attribute value|attribute] [--user=user@email]";
|
||||
return "userattr [-s attribute value|attribute|--list] [--user=user@email]";
|
||||
}
|
||||
if (!strcmp(command, "mkdir"))
|
||||
{
|
||||
@ -1653,12 +1619,16 @@ const char * getUsageStr(const char *command)
|
||||
}
|
||||
if (!strcmp(command, "killsession"))
|
||||
{
|
||||
return "killsession [-a|sessionid]";
|
||||
return "killsession [-a | sessionid1 sessionid2 ... ]";
|
||||
}
|
||||
if (!strcmp(command, "whoami"))
|
||||
{
|
||||
return "whoami [-l]";
|
||||
}
|
||||
if (!strcmp(command, "df"))
|
||||
{
|
||||
return "df [-h]";
|
||||
}
|
||||
if (!strcmp(command, "cat"))
|
||||
{
|
||||
return "cat remotepath1 remotepath2 ...";
|
||||
@ -1671,11 +1641,11 @@ const char * getUsageStr(const char *command)
|
||||
{
|
||||
if (interactiveThread())
|
||||
{
|
||||
return "passwd [-f] [newpassword]";
|
||||
return "passwd [-f] [--auth-code=XXXX] [newpassword]";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "passwd [-f] newpassword";
|
||||
return "passwd [-f] [--auth-code=XXXX] newpassword";
|
||||
}
|
||||
}
|
||||
if (!strcmp(command, "retry"))
|
||||
@ -1784,7 +1754,7 @@ const char * getUsageStr(const char *command)
|
||||
return "codepage [N [M]]";
|
||||
}
|
||||
#endif
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
if (!strcmp(command, "update"))
|
||||
{
|
||||
return "update [--auto=on|off]";
|
||||
@ -1831,6 +1801,9 @@ string getHelpStr(const char *command)
|
||||
os << " You can log in either with email and password, with session ID," << endl;
|
||||
os << " or into a folder (an exported/public folder)" << endl;
|
||||
os << " If logging into a folder indicate url#key" << endl;
|
||||
os << endl;
|
||||
os << "Options:" << endl;
|
||||
os << " --auth-code=XXXX" << "\t" << "Two-factor Authentication code. More info: https://mega.nz/blog_48" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "cancel"))
|
||||
{
|
||||
@ -1841,6 +1814,14 @@ string getHelpStr(const char *command)
|
||||
os << "The cancellation will not take place inmediately. You will need to confirm the cancellation" << endl;
|
||||
os << "using a link that will be delivered to your email. See \"confirmcancel --help\"" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "psa"))
|
||||
{
|
||||
os << "Shows the next available Public Service Announcement (PSA)" << endl;
|
||||
os << endl;
|
||||
os << "Options:" << endl;
|
||||
os << " --discard" << "\t" << "Discards last received PSA" << endl;
|
||||
os << endl;
|
||||
}
|
||||
else if (!strcmp(command, "confirmcancel"))
|
||||
{
|
||||
os << "Confirms the cancellation of your MEGA account" << endl;
|
||||
@ -1963,7 +1944,7 @@ string getHelpStr(const char *command)
|
||||
os << endl;
|
||||
os << "This is similar to \"ls --tree\"" << endl;
|
||||
}
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
else if (!strcmp(command, "update"))
|
||||
{
|
||||
os << "Updates MEGAcmd" << endl;
|
||||
@ -1977,6 +1958,8 @@ string getHelpStr(const char *command)
|
||||
os << "If auto updates are enabled it will be checked while MEGAcmd server is running." << endl;
|
||||
os << " If there is an update available, it will be downloaded and applied. " << endl;
|
||||
os << " This will cause MEGAcmd to be restarted whenever the updates are applied." << endl;
|
||||
os << endl;
|
||||
os << "Further info at https://github.com/meganz/megacmd#megacmd-updates";
|
||||
}
|
||||
#endif
|
||||
else if (!strcmp(command, "cd"))
|
||||
@ -2113,6 +2096,7 @@ string getHelpStr(const char *command)
|
||||
os << "Options:" << endl;
|
||||
os << " -s" << "\tattribute value \t" << "sets an attribute to a value" << endl;
|
||||
os << " --user=user@email" << "\t" << "select the user to query" << endl;
|
||||
os << " --list" << "\t" << "lists valid attributes" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "mkdir"))
|
||||
{
|
||||
@ -2228,6 +2212,7 @@ string getHelpStr(const char *command)
|
||||
#endif
|
||||
os << endl;
|
||||
os << "*If you serve more than one location, these parameters will be ignored and use those of the first location served." << endl;
|
||||
os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl;
|
||||
os << endl;
|
||||
os << "Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz" << endl;
|
||||
os << endl;
|
||||
@ -2253,6 +2238,7 @@ string getHelpStr(const char *command)
|
||||
#endif
|
||||
os << endl;
|
||||
os << "*If you serve more than one location, these parameters will be ignored and used those of the first location served." << endl;
|
||||
os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl;
|
||||
os << endl;
|
||||
os << "Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz" << endl;
|
||||
os << endl;
|
||||
@ -2325,8 +2311,8 @@ string getHelpStr(const char *command)
|
||||
os << " \t" << "If MEGAcmd server stops during a transfer, it will be considered MISCARRIED" << endl;
|
||||
os << " \t" << " Notice that currently when MEGAcmd server is restarted, ongoing and scheduled transfers " << endl;
|
||||
os << " \t" << " will be carried out nevertheless." << endl;
|
||||
os << " \t" << "If MEGAcmd server is not running when a backup is scheduled and the time for the next one has already arrived,"
|
||||
" an empty BACKUP will be created with state SKIPPED" << endl;
|
||||
os << " \t" << "If MEGAcmd server is not running when a backup is scheduled and the time for the next one has already arrived," << endl;
|
||||
os << " \t" << " an empty BACKUP will be created with state SKIPPED" << endl;
|
||||
os << " \t" << "If a backup(1) is ONGOING and the time for the next backup(2) arrives, it won't start untill the previous one(1) " << endl;
|
||||
os << " \t" << " is completed, and if by the time the first one(1) ends the time for the next one(3) has already arrived," << endl;
|
||||
os << " \t" << " an empty BACKUP(2) will be created with state SKIPPED" << endl;
|
||||
@ -2369,7 +2355,6 @@ string getHelpStr(const char *command)
|
||||
os << "-a TAG|localpath\t" << "Aborts ongoing backup" << endl;
|
||||
os << endl;
|
||||
os << "Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz" << endl;
|
||||
os << endl;
|
||||
}
|
||||
else if (!strcmp(command, "export"))
|
||||
{
|
||||
@ -2519,12 +2504,21 @@ string getHelpStr(const char *command)
|
||||
}
|
||||
else if (!strcmp(command, "whoami"))
|
||||
{
|
||||
os << "Print info of the user" << endl;
|
||||
os << "Prints info of the user" << endl;
|
||||
os << endl;
|
||||
os << "Options:" << endl;
|
||||
os << " -l" << "\t" << "Show extended info: total storage used, storage per main folder " << endl;
|
||||
os << " " << "\t" << "(see mount), pro level, account balance, and also the active sessions" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "df"))
|
||||
{
|
||||
os << "Shows storage info" << endl;
|
||||
os << endl;
|
||||
os << "Shows total storage used in the account, storage per main folder (see mount)" << endl;
|
||||
os << endl;
|
||||
os << "Options:" << endl;
|
||||
os << " -h" << "\t" << "Human readable sizes. Otherwise, size will be expressed in Bytes" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "cat"))
|
||||
{
|
||||
os << "Prints the contents of remote files" << endl;
|
||||
@ -2550,7 +2544,7 @@ string getHelpStr(const char *command)
|
||||
os << endl;
|
||||
os << "Options:" << endl;
|
||||
os << " -f " << "\t" << "Force (no asking)" << endl;
|
||||
|
||||
os << " --auth-code=XXXX" << "\t" << "Two-factor Authentication code. More info: https://mega.nz/blog_48" << endl;
|
||||
}
|
||||
else if (!strcmp(command, "reload"))
|
||||
{
|
||||
@ -2636,15 +2630,29 @@ string getHelpStr(const char *command)
|
||||
os << " -c (TAG|-a)" << "\t" << "Cancel transfer with TAG (or all with -a)" << endl;
|
||||
os << " -p (TAG|-a)" << "\t" << "Pause transfer with TAG (or all with -a)" << endl;
|
||||
os << " -r (TAG|-a)" << "\t" << "Resume transfer with TAG (or all with -a)" << endl;
|
||||
os << " -only-uploads" << "\t" << "Show/Operate only upload transfers" << endl;
|
||||
os << " -only-downloads" << "\t" << "Show/Operate only download transfers" << endl;
|
||||
os << " --only-uploads" << "\t" << "Show/Operate only upload transfers" << endl;
|
||||
os << " --only-downloads" << "\t" << "Show/Operate only download transfers" << endl;
|
||||
os << endl;
|
||||
os << "Show options:" << endl;
|
||||
os << " -show-syncs" << "\t" << "Show synchronization transfers" << endl;
|
||||
os << " -show-completed" << "\t" << "Show completed transfers" << endl;
|
||||
os << " -only-completed" << "\t" << "Show only completed download" << endl;
|
||||
os << " --summary" << "\t" << "Prints summary of on going transfers" << endl;
|
||||
os << " --show-syncs" << "\t" << "Show synchronization transfers" << endl;
|
||||
os << " --show-completed" << "\t" << "Show completed transfers" << endl;
|
||||
os << " --only-completed" << "\t" << "Show only completed download" << endl;
|
||||
os << " --limit=N" << "\t" << "Show only first N transfers" << endl;
|
||||
os << " --path-display-size=N" << "\t" << "Use a fixed size of N characters for paths" << endl;
|
||||
os << endl;
|
||||
os << "TYPE legend correspondence:" << endl;
|
||||
#ifdef _WIN32
|
||||
os << " D = \t" << "Download transfer" << endl;
|
||||
os << " U = \t" << "Upload transfer" << endl;
|
||||
os << " S = \t" << "Sync transfer. The transfer is done in the context of a synchronization" << endl;
|
||||
os << " B = \t" << "Backup transfer. The transfer is done in the context of a backup" << endl;
|
||||
#else
|
||||
os << " \u21d3 = \t" << "Download transfer" << endl;
|
||||
os << " \u21d1 = \t" << "Upload transfer" << endl;
|
||||
os << " \u21f5 = \t" << "Sync transfer. The transfer is done in the context of a synchronization" << endl;
|
||||
os << " \u23eb = \t" << "Backup transfer. The transfer is done in the context of a backup" << endl;
|
||||
#endif
|
||||
}
|
||||
#if defined(_WIN32) && defined(NO_READLINE)
|
||||
else if (!strcmp(command, "autocomplete"))
|
||||
@ -2730,7 +2738,7 @@ void printAvailableCommands(int extensive = 0)
|
||||
|
||||
void executecommand(char* ptr)
|
||||
{
|
||||
vector<string> words = getlistOfWords(ptr);
|
||||
vector<string> words = getlistOfWords(ptr, !getCurrentThreadIsCmdShell());
|
||||
if (!words.size())
|
||||
{
|
||||
return;
|
||||
@ -2794,7 +2802,7 @@ void executecommand(char* ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
words = getlistOfWords(ptr,true); //Get words again ignoring trailing spaces (only reasonable for completion)
|
||||
words = getlistOfWords(ptr, !getCurrentThreadIsCmdShell(), true); //Get words again ignoring trailing spaces (only reasonable for completion)
|
||||
|
||||
map<string, string> cloptions;
|
||||
map<string, int> clflags;
|
||||
@ -3279,7 +3287,7 @@ static bool process_line(char* l)
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
else if (!strcmp(l, "update") || !strcmp(l, "update ")) //if extra args are received, it'll be processed by executer
|
||||
{
|
||||
string confirmationQuery("This might require restarting MEGAcmd. Are you sure to continue");
|
||||
@ -3680,11 +3688,6 @@ void megacmd()
|
||||
|
||||
cm->informStateListener(inf,s);
|
||||
|
||||
// communicate status info
|
||||
s = "prompt:";
|
||||
s+=dynamicprompt;
|
||||
s+=(char)0x1F;
|
||||
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
string message="";
|
||||
ostringstream os;
|
||||
@ -3778,11 +3781,25 @@ void megacmd()
|
||||
if (isOSdeprecated)
|
||||
{
|
||||
s += "message:";
|
||||
s += "---------------------------------------------------------------------\n";
|
||||
s += "-- Your Operative System is too old. --\n";
|
||||
s += "-- You might not receive new updates for this application. --\n";
|
||||
s += "-- We strongly recommend you to update to a new version. --\n";
|
||||
s += "---------------------------------------------------------------------\n";
|
||||
s += "Your Operative System is too old.\n";
|
||||
s += "You might not receive new updates for this application.\n";
|
||||
s += "We strongly recommend you to update to a new version.\n";
|
||||
s+=(char)0x1F;
|
||||
}
|
||||
|
||||
if (sandboxCMD->storageStatus != MegaApi::STORAGE_STATE_GREEN)
|
||||
{
|
||||
s += "message:";
|
||||
|
||||
if (sandboxCMD->storageStatus == MegaApi::STORAGE_STATE_RED)
|
||||
{
|
||||
s+= "You have exeeded your available storage.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
s+= "You are running out of available storage.\n";
|
||||
}
|
||||
s+="You can change your account plan to increase your quota limit.\nSee \"help --upgrade\" for further details";
|
||||
s+=(char)0x1F;
|
||||
}
|
||||
|
||||
@ -3802,6 +3819,13 @@ void megacmd()
|
||||
s += SSTR(api->isWaiting());
|
||||
s += (char)0x1F;
|
||||
|
||||
// communicate status info
|
||||
s+= "prompt:";
|
||||
s+=dynamicprompt;
|
||||
s+=(char)0x1F;
|
||||
|
||||
cmdexecuter->checkAndInformPSA(inf);
|
||||
|
||||
cm->informStateListener(inf,s);
|
||||
}
|
||||
else
|
||||
@ -3832,24 +3856,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void printCenteredLine(string msj, unsigned int width, bool encapsulated = true)
|
||||
{
|
||||
if (msj.size()>width)
|
||||
{
|
||||
width = (unsigned int)msj.size();
|
||||
}
|
||||
if (encapsulated)
|
||||
COUT << "|";
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2; i++)
|
||||
COUT << " ";
|
||||
COUT << msj;
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2 + (width-msj.size())%2 ; i++)
|
||||
COUT << " ";
|
||||
if (encapsulated)
|
||||
COUT << "|";
|
||||
COUT << endl;
|
||||
}
|
||||
|
||||
void printWelcomeMsg()
|
||||
{
|
||||
unsigned int width = getNumberOfCols(75);
|
||||
@ -3885,16 +3891,6 @@ void printWelcomeMsg()
|
||||
|
||||
}
|
||||
|
||||
int quote_detector(char *line, int index)
|
||||
{
|
||||
return (
|
||||
index > 0 &&
|
||||
line[index - 1] == '\\' &&
|
||||
!quote_detector(line, index - 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __MACH__
|
||||
|
||||
|
||||
@ -4519,7 +4515,7 @@ int main(int argc, char* argv[])
|
||||
cmdexecuter = new MegaCmdExecuter(api, loggerCMD, sandboxCMD);
|
||||
|
||||
megaCmdGlobalListener = new MegaCmdGlobalListener(loggerCMD, sandboxCMD);
|
||||
megaCmdMegaListener = new MegaCmdMegaListener(api, NULL);
|
||||
megaCmdMegaListener = new MegaCmdMegaListener(api, NULL, sandboxCMD);
|
||||
api->addGlobalListener(megaCmdGlobalListener);
|
||||
api->addListener(megaCmdMegaListener);
|
||||
|
||||
@ -4559,7 +4555,7 @@ int main(int argc, char* argv[])
|
||||
atexit(finalize);
|
||||
|
||||
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
if (!ConfigurationManager::getConfigurationValue("updaterregistered", false))
|
||||
{
|
||||
LOG_debug << "Registering automatic updater";
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmd.h
|
||||
* @brief MEGAcmd: Interactive CLI and service application
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -30,35 +30,13 @@ using std::max;
|
||||
using std::min;
|
||||
using std::flush;
|
||||
using std::left;
|
||||
using std::setw;
|
||||
using std::cerr;
|
||||
using std::istringstream;
|
||||
using std::locale;
|
||||
using std::stringstream;
|
||||
using std::exception;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define OUTSTREAMTYPE std::wostream
|
||||
#define OUTSTRINGSTREAM std::wostringstream
|
||||
#define OUTSTRING std::wstring
|
||||
#define COUT std::wcout
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str );
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str );
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str);
|
||||
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte);
|
||||
|
||||
#else
|
||||
#define OUTSTREAMTYPE std::ostream
|
||||
#define OUTSTRINGSTREAM std::ostringstream
|
||||
#define OUTSTRING std::string
|
||||
#define COUT std::cout
|
||||
#endif
|
||||
|
||||
#include "megaapi_impl.h"
|
||||
|
||||
@ -131,6 +109,7 @@ enum confirmresponse
|
||||
|
||||
void changeprompt(const char *newprompt);
|
||||
|
||||
void informStateListener(std::string message, int clientID);
|
||||
void broadcastMessage(std::string message, const char *suffix = "message:");
|
||||
|
||||
mega::MegaApi* getFreeApiFolder();
|
||||
@ -156,6 +135,8 @@ void stopcheckingForUpdates();
|
||||
void startcheckingForUpdates();
|
||||
|
||||
void informTransferUpdate(mega::MegaTransfer *transfer, int clientID);
|
||||
void informStateListenerByClientId(int clientID, std::string s);
|
||||
|
||||
|
||||
void informProgressUpdate(long long transferred, long long total, int clientID, std::string title = "");
|
||||
|
||||
|
923
src/megacmdcommonutils.cpp
Normal file
923
src/megacmdcommonutils.cpp
Normal file
@ -0,0 +1,923 @@
|
||||
/**
|
||||
* @file src/megacmdcommonutils.cpp
|
||||
* @brief MEGAcmd: Auxiliary methods
|
||||
*
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
* MEGAcmd is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @copyright Simplified (2-clause) BSD License.
|
||||
*
|
||||
* You should have received a copy of the license along with this
|
||||
* program.
|
||||
*/
|
||||
|
||||
#include "megacmdcommonutils.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Shlwapi.h> //PathAppend
|
||||
#include <Shellapi.h> //CommandLineToArgvW
|
||||
#else
|
||||
#include <sys/ioctl.h> // console size
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <limits.h>
|
||||
#include <iterator>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
//override << operators for wostream for string and const char *
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str.c_str(),&toout);
|
||||
ostr << toout;
|
||||
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str,&toout);
|
||||
ostr << toout;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
//override for the log. This is required for compiling, otherwise SimpleLog won't compile.
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str)
|
||||
{
|
||||
std::string s;
|
||||
localwtostring(&str,&s);
|
||||
ostr << s;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
// convert UTF-8 to Windows Unicode wstring
|
||||
void stringtolocalw(const char* path, std::wstring* local)
|
||||
{
|
||||
// make space for the worst case
|
||||
local->resize((strlen(path) + 1) * sizeof(wchar_t));
|
||||
|
||||
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, path,-1, NULL,0);
|
||||
local->resize(wchars_num);
|
||||
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, path,-1, (wchar_t*)local->data(), wchars_num);
|
||||
|
||||
if (len)
|
||||
{
|
||||
local->resize(len-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
local->clear();
|
||||
}
|
||||
}
|
||||
|
||||
//widechar to utf8 string
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte)
|
||||
{
|
||||
if( !wide->empty() )
|
||||
{
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), NULL, 0, NULL, NULL);
|
||||
multibyte->resize(size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), (char*)multibyte->data(), size_needed, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// convert Windows Unicode to UTF-8
|
||||
void utf16ToUtf8(const wchar_t* utf16data, int utf16size, string* utf8string)
|
||||
{
|
||||
if(!utf16size)
|
||||
{
|
||||
utf8string->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
utf8string->resize((utf16size + 1) * 4);
|
||||
|
||||
utf8string->resize(WideCharToMultiByte(CP_UTF8, 0, utf16data,
|
||||
utf16size,
|
||||
(char*)utf8string->data(),
|
||||
int(utf8string->size() + 1),
|
||||
NULL, NULL));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
bool canWrite(string path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// TODO: Check permissions
|
||||
return true;
|
||||
#else
|
||||
if (access(path.c_str(), W_OK) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isPublicLink(string link)
|
||||
{
|
||||
if (( link.find("http") == 0 ) && ( link.find("#") != string::npos ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isEncryptedLink(string link)
|
||||
{
|
||||
if (( link.find("http") == 0 ) && ( link.find("#") != string::npos ) && (link.substr(link.find("#"),3) == "#P!") )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasWildCards(string &what)
|
||||
{
|
||||
return what.find('*') != string::npos || what.find('?') != string::npos;
|
||||
}
|
||||
|
||||
long long charstoll(const char *instr)
|
||||
{
|
||||
long long retval;
|
||||
|
||||
retval = 0;
|
||||
for (; *instr; instr++) {
|
||||
retval = 10*retval + (*instr - '0');
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::string <rim(std::string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_first_not_of(c);
|
||||
s = s.substr(pos == string::npos ? s.length() : pos, s.length());
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string &rtrim(std::string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_last_of(c);
|
||||
size_t last = pos == string::npos ? s.length() : pos;
|
||||
if (last + 1 < s.length())
|
||||
{
|
||||
if (s.at(last + 1) != c)
|
||||
{
|
||||
last = s.length();
|
||||
}
|
||||
}
|
||||
|
||||
s = s.substr(0, last);
|
||||
return s;
|
||||
}
|
||||
|
||||
vector<string> getlistOfWords(char *ptr, bool escapeBackSlashInCompletion, bool ignoreTrailingSpaces)
|
||||
{
|
||||
vector<string> words;
|
||||
|
||||
char* wptr;
|
||||
|
||||
// split line into words with quoting and escaping
|
||||
for (;; )
|
||||
{
|
||||
// skip leading blank space
|
||||
while (*(const signed char*)ptr > 0 && *ptr <= ' ' && (ignoreTrailingSpaces || *(ptr+1)))
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (!*ptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// quoted arg / regular arg
|
||||
if (*ptr == '"')
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '"' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '"' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*ptr == '\'') // quoted arg / regular arg
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '\'' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '\'' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*ptr == ' ') ptr++;// only possible if ptr+1 is the end
|
||||
|
||||
wptr = ptr;
|
||||
|
||||
char *prev = ptr;
|
||||
//while ((unsigned char)*ptr > ' ')
|
||||
while ((*ptr != '\0') && !(*ptr ==' ' && *prev !='\\'))
|
||||
{
|
||||
if (*ptr == '"')
|
||||
{
|
||||
while (*++ptr != '"' && *ptr != '\0')
|
||||
{ }
|
||||
}
|
||||
prev=ptr;
|
||||
ptr++;
|
||||
}
|
||||
string newword(wptr, ptr - wptr);
|
||||
words.push_back(newword);
|
||||
}
|
||||
}
|
||||
|
||||
if (escapeBackSlashInCompletion && words.size()> 1 && words[0] == "completion")
|
||||
{
|
||||
for (int i = 1; i < (int)words.size(); i++)
|
||||
{
|
||||
replaceAll(words[i],"\\","\\\\");
|
||||
}
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
bool stringcontained(const char * s, vector<string> list)
|
||||
{
|
||||
for (int i = 0; i < (int)list.size(); i++)
|
||||
{
|
||||
if (list[i] == s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
char * dupstr(char* s)
|
||||
{
|
||||
char *r;
|
||||
|
||||
r = (char*)malloc(sizeof( char ) * ( strlen(s) + 1 ));
|
||||
strcpy(r, s);
|
||||
return( r );
|
||||
}
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
size_t start_pos = str.find(from);
|
||||
if (start_pos == std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
size_t start_pos = 0;
|
||||
while (( start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
int toInteger(string what, int failValue)
|
||||
{
|
||||
if (what.empty())
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
if (!isdigit(what[0]) && !( what[0] != '-' ) && ( what[0] != '+' ))
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
|
||||
char * p;
|
||||
long l = strtol(what.c_str(), &p, 10);
|
||||
|
||||
if (*p != 0)
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
|
||||
if (( l < INT_MIN ) || ( l > INT_MAX ))
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
return (int)l;
|
||||
}
|
||||
|
||||
string joinStrings(const vector<string>& vec, const char* delim, bool quoted)
|
||||
{
|
||||
stringstream res;
|
||||
if (!quoted)
|
||||
{
|
||||
std:copy(vec.begin(), vec.end(), ostream_iterator<string>(res, delim));
|
||||
}
|
||||
else
|
||||
{
|
||||
for(vector<string>::const_iterator i = vec.begin(); i != vec.end(); ++i)
|
||||
{
|
||||
res << "\"" << *i << "\"" << delim;
|
||||
}
|
||||
}
|
||||
if (vec.size()>1)
|
||||
{
|
||||
string toret = res.str();
|
||||
return toret.substr(0,toret.size()-strlen(delim));
|
||||
}
|
||||
return res.str();
|
||||
}
|
||||
|
||||
unsigned int getstringutf8size(const string &str) {
|
||||
int c,i,ix,q;
|
||||
for (q=0, i=0, ix=int(str.length()); i < ix; i++, q++)
|
||||
{
|
||||
c = (unsigned char) str[i];
|
||||
|
||||
if (c>=0 && c<=127) i+=0;
|
||||
else if ((c & 0xE0) == 0xC0) i+=1;
|
||||
#ifdef _WIN32
|
||||
else if ((c & 0xF0) == 0xE0) i+=2;
|
||||
#else
|
||||
else if ((c & 0xF0) == 0xE0) {i+=2;q++;} //these gliphs may occupy 2 characters! Problem: not always. Let's assume the worse
|
||||
#endif
|
||||
else if ((c & 0xF8) == 0xF0) i+=3;
|
||||
else return 0;//invalid utf8
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
string getFixLengthString(const string origin, unsigned int size, const char delim, bool alignedright)
|
||||
{
|
||||
string toret;
|
||||
size_t printableSize = getstringutf8size(origin);
|
||||
size_t bytesSize = origin.size();
|
||||
if (printableSize <= size){
|
||||
if (alignedright)
|
||||
{
|
||||
toret.insert(0,size-printableSize,delim);
|
||||
toret.insert(size-bytesSize,origin,0,bytesSize);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
toret.insert(0,origin,0,bytesSize);
|
||||
toret.insert(bytesSize,size-printableSize,delim);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
toret.insert(0,origin,0,(size+1)/2-2);
|
||||
if (size > 3) toret.insert((size+1)/2-2,3,'.');
|
||||
if (size > 1) toret.insert((size+1)/2+1,origin,bytesSize-(size)/2+1,(size)/2-1); //TODO: This could break characters if multibyte! //alternative: separate in multibyte strings and print one by one?
|
||||
}
|
||||
|
||||
return toret;
|
||||
}
|
||||
|
||||
string getRightAlignedString(const string origin, unsigned int minsize)
|
||||
{
|
||||
ostringstream os;
|
||||
os << std::setw(minsize) << origin;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void printCenteredLine(OUTSTREAMTYPE &os, string msj, unsigned int width, bool encapsulated)
|
||||
{
|
||||
if (msj.size()>width)
|
||||
{
|
||||
width = unsigned(msj.size());
|
||||
}
|
||||
if (encapsulated)
|
||||
os << "|";
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2; i++)
|
||||
os << " ";
|
||||
os << msj;
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2 + (width-msj.size())%2 ; i++)
|
||||
os << " ";
|
||||
if (encapsulated)
|
||||
os << "|";
|
||||
os << endl;
|
||||
}
|
||||
|
||||
void printCenteredContents(OUTSTREAMTYPE &os, string msj, unsigned int width, bool encapsulated)
|
||||
{
|
||||
string headfoot = " ";
|
||||
headfoot.append(width, '-');
|
||||
if (msj.size())
|
||||
{
|
||||
string header;
|
||||
if (msj.at(0) == '<')
|
||||
{
|
||||
size_t possenditle = msj.find(">");
|
||||
if (width >= 2 && possenditle < (width -2))
|
||||
{
|
||||
header.append(" ");
|
||||
header.append((width - possenditle ) / 2, '-');
|
||||
header.append(msj.substr(0,possenditle+1));
|
||||
header.append(width - header.size() + 1, '-');
|
||||
msj = msj.substr(possenditle + 1);
|
||||
}
|
||||
}
|
||||
|
||||
os << (header.size()?header:headfoot) << endl;
|
||||
}
|
||||
|
||||
size_t possepnewline = msj.find("\n");
|
||||
size_t possep = msj.find(" ");
|
||||
|
||||
if (possepnewline != string::npos && possepnewline < width)
|
||||
{
|
||||
possep = possepnewline;
|
||||
}
|
||||
size_t possepprev = possep;
|
||||
|
||||
|
||||
while (msj.size())
|
||||
{
|
||||
|
||||
if (possepnewline != string::npos && possepnewline <= width)
|
||||
{
|
||||
possep = possepnewline;
|
||||
possepprev = possep;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (possep < width && possep != string::npos)
|
||||
{
|
||||
possepprev = possep;
|
||||
possep = msj.find_first_of(" ", possep+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (possep == string::npos)
|
||||
{
|
||||
printCenteredLine(os, msj, width, encapsulated);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
printCenteredLine(os, msj.substr(0,possepprev), width, encapsulated);
|
||||
if (possepprev < (msj.size() - 1))
|
||||
{
|
||||
msj = msj.substr(possepprev+1);
|
||||
possepnewline = msj.find("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
os << headfoot << endl;
|
||||
}
|
||||
|
||||
void printCenteredLine(string msj, unsigned int width, bool encapsulated)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
printCenteredLine(os, msj, width, encapsulated);
|
||||
COUT << os.str();
|
||||
}
|
||||
|
||||
void printCenteredContents(string msj, unsigned int width, bool encapsulated)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
printCenteredContents(os, msj, width, encapsulated);
|
||||
COUT << os.str();
|
||||
}
|
||||
|
||||
void printCenteredContentsCerr(string msj, unsigned int width, bool encapsulated)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
printCenteredContents(os, msj, width, encapsulated);
|
||||
CERR << os.str();
|
||||
}
|
||||
|
||||
void printPercentageLineCerr(const char *title, long long completed, long long total, float percentDowloaded, bool cleanLineAfter)
|
||||
{
|
||||
int cols = getNumberOfCols(80);
|
||||
|
||||
string outputString;
|
||||
outputString.resize(cols + 1);
|
||||
for (int i = 0; i < cols; i++)
|
||||
{
|
||||
outputString[i] = '.';
|
||||
}
|
||||
|
||||
outputString[cols] = '\0';
|
||||
char *ptr = (char *)outputString.c_str();
|
||||
sprintf(ptr, "%s%s", title, " ||");
|
||||
ptr += strlen(title);
|
||||
ptr += strlen(" ||");
|
||||
*ptr = '.'; //replace \0 char
|
||||
|
||||
char aux[41];
|
||||
|
||||
if (total < 1048576)
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld KB: %6.2f %%) ", completed / 1024, total / 1024, percentDowloaded);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(aux,"||(%lld/%lld MB: %6.2f %%) ", completed / 1024 / 1024, total / 1024 / 1024, percentDowloaded);
|
||||
}
|
||||
|
||||
|
||||
sprintf((char *)outputString.c_str() + cols - strlen(aux), "%s", aux);
|
||||
for (int i = 0; i < ( cols - (strlen(title) + strlen(" ||")) - strlen(aux)) * 1.0 * min(100.0f,percentDowloaded) / 100.0; i++)
|
||||
{
|
||||
*ptr++ = '#';
|
||||
}
|
||||
|
||||
if (cleanLineAfter)
|
||||
{
|
||||
cerr << outputString << '\r' << flush;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << outputString << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int getFlag(map<string, int> *flags, const char * optname)
|
||||
{
|
||||
return flags->count(optname) ? ( *flags )[optname] : 0;
|
||||
}
|
||||
|
||||
string getOption(map<string, string> *cloptions, const char * optname, string defaultValue)
|
||||
{
|
||||
return cloptions->count(optname) ? ( *cloptions )[optname] : defaultValue;
|
||||
}
|
||||
|
||||
int getintOption(map<string, string> *cloptions, const char * optname, int defaultValue)
|
||||
{
|
||||
if (cloptions->count(optname))
|
||||
{
|
||||
int i = defaultValue;
|
||||
istringstream is(( *cloptions )[optname]);
|
||||
is >> i;
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
void discardOptionsAndFlags(vector<string> *ws)
|
||||
{
|
||||
for (std::vector<string>::iterator it = ws->begin(); it != ws->end(); )
|
||||
{
|
||||
/* std::cout << *it; ... */
|
||||
string w = ( string ) * it;
|
||||
if (w.length() && ( w.at(0) == '-' )) //begins with "-"
|
||||
{
|
||||
it = ws->erase(it);
|
||||
}
|
||||
else //not an option/flag
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string sizeProgressToText(long long partialSize, long long totalSize, bool equalizeUnitsLength, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
string unit;
|
||||
unit = ( equalizeUnitsLength ? " B" : "B" );
|
||||
double reducedPartSize = (double)totalSize;
|
||||
double reducedSize = (double)totalSize;
|
||||
|
||||
if ( totalSize > 1099511627776LL *2 )
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1099511627776ull;
|
||||
reducedSize = totalSize / (double) 1099511627776ull;
|
||||
unit = "TB";
|
||||
}
|
||||
else if ( totalSize > 1073741824LL *2 )
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1073741824L;
|
||||
reducedSize = totalSize / (double) 1073741824L;
|
||||
unit = "GB";
|
||||
}
|
||||
else if (totalSize > 1048576 * 2)
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1048576;
|
||||
reducedSize = totalSize / (double) 1048576;
|
||||
unit = "MB";
|
||||
}
|
||||
else if (totalSize > 1024 * 2)
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1024;
|
||||
reducedSize = totalSize / (double) 1024;
|
||||
unit = "KB";
|
||||
}
|
||||
os << fixed << reducedPartSize << "/" << reducedSize;
|
||||
os << " " << unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << partialSize << "/" << totalSize;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string sizeToText(long long totalSize, bool equalizeUnitsLength, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
string unit;
|
||||
unit = ( equalizeUnitsLength ? " B" : "B" );
|
||||
double reducedSize = (double)totalSize;
|
||||
|
||||
if ( totalSize > 1099511627776LL *2 )
|
||||
{
|
||||
reducedSize = totalSize / (double) 1099511627776ull;
|
||||
unit = "TB";
|
||||
}
|
||||
else if ( totalSize > 1073741824LL *2 )
|
||||
{
|
||||
reducedSize = totalSize / (double) 1073741824L;
|
||||
unit = "GB";
|
||||
}
|
||||
else if (totalSize > 1048576 * 2)
|
||||
{
|
||||
reducedSize = totalSize / (double) 1048576;
|
||||
unit = "MB";
|
||||
}
|
||||
else if (totalSize > 1024 * 2)
|
||||
{
|
||||
reducedSize = totalSize / (double) 1024;
|
||||
unit = "KB";
|
||||
}
|
||||
os << fixed << reducedSize;
|
||||
os << " " << unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << totalSize;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int64_t textToSize(const char *text)
|
||||
{
|
||||
int64_t sizeinbytes = 0;
|
||||
|
||||
char * ptr = (char *)text;
|
||||
char * last = (char *)text;
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
if (( *ptr < '0' ) || ( *ptr > '9' ) || ( *ptr == '.' ) )
|
||||
{
|
||||
switch (*ptr)
|
||||
{
|
||||
case 'b': //Bytes
|
||||
case 'B':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(atof(last));
|
||||
break;
|
||||
|
||||
case 'k': //KiloBytes
|
||||
case 'K':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1024.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 'm': //MegaBytes
|
||||
case 'M':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1048576.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 'g': //GigaBytes
|
||||
case 'G':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1073741824.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 't': //TeraBytes
|
||||
case 'T':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1125899906842624.0 * atof(last));
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
last = ptr + 1;
|
||||
}
|
||||
char *prev = ptr;
|
||||
ptr++;
|
||||
if (*ptr == '\0' && ( ( *prev == '.' ) || ( ( *prev >= '0' ) && ( *prev <= '9' ) ) ) ) //reach the end with a number or dot
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return sizeinbytes;
|
||||
|
||||
}
|
||||
|
||||
string percentageToText(float percentage)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (percentage != percentage) //NaN
|
||||
{
|
||||
os << "----%";
|
||||
}
|
||||
else
|
||||
{
|
||||
os << fixed << percentage*100.0 << "%";
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
unsigned int getNumberOfCols(unsigned int defaultwidth)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
int columns = defaultwidth;
|
||||
|
||||
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
||||
{
|
||||
columns = csbi.srWindow.Right - csbi.srWindow.Left - 1;
|
||||
}
|
||||
|
||||
return columns;
|
||||
#else
|
||||
struct winsize size;
|
||||
if ( ioctl(STDOUT_FILENO,TIOCGWINSZ,&size) != -1
|
||||
|| (ioctl(STDIN_FILENO,TIOCGWINSZ,&size) != -1))
|
||||
{
|
||||
if (size.ws_col > 2)
|
||||
{
|
||||
return size.ws_col - 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return defaultwidth;
|
||||
}
|
||||
|
||||
void sleepSeconds(int seconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(1000*seconds);
|
||||
#else
|
||||
sleep(seconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sleepMilliSeconds(long milliseconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds *1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isValidEmail(string email)
|
||||
{
|
||||
return !( (email.find("@") == string::npos)
|
||||
|| (email.find_last_of(".") == string::npos)
|
||||
|| (email.find("@") > email.find_last_of(".")));
|
||||
}
|
||||
|
||||
string <rimProperty(string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_first_not_of(c);
|
||||
s = s.substr(pos == string::npos ? s.length() : pos, s.length());
|
||||
return s;
|
||||
}
|
||||
|
||||
string &rtrimProperty(string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_last_not_of(c);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
s = s.substr(0, pos);
|
||||
return s;
|
||||
}
|
||||
|
||||
string &trimProperty(string &what)
|
||||
{
|
||||
rtrimProperty(what,' ');
|
||||
ltrimProperty(what,' ');
|
||||
if (what.size() > 1)
|
||||
{
|
||||
if (what[0] == '\'' || what[0] == '"')
|
||||
{
|
||||
rtrimProperty(what, what[0]);
|
||||
ltrimProperty(what, what[0]);
|
||||
}
|
||||
}
|
||||
return what;
|
||||
}
|
||||
|
||||
string getPropertyFromFile(const char *configFile, const char *propertyName)
|
||||
{
|
||||
ifstream infile(configFile);
|
||||
string line;
|
||||
|
||||
while (getline(infile, line))
|
||||
{
|
||||
if (line.length() > 0 && line[0] != '#')
|
||||
{
|
||||
if (!strlen(propertyName)) //if empty return first line
|
||||
{
|
||||
return trimProperty(line);
|
||||
}
|
||||
string key, value;
|
||||
size_t pos = line.find("=");
|
||||
if (pos != string::npos && ((pos + 1) < line.size()))
|
||||
{
|
||||
key = line.substr(0, pos);
|
||||
rtrimProperty(key, ' ');
|
||||
|
||||
if (!strcmp(key.c_str(), propertyName))
|
||||
{
|
||||
value = line.substr(pos + 1);
|
||||
return trimProperty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string();
|
||||
}
|
177
src/megacmdcommonutils.h
Normal file
177
src/megacmdcommonutils.h
Normal file
@ -0,0 +1,177 @@
|
||||
/**
|
||||
* @file src/megacmdcommonutils.h
|
||||
* @brief MEGAcmd: Auxiliary methods
|
||||
*
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
* MEGAcmd is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* @copyright Simplified (2-clause) BSD License.
|
||||
*
|
||||
* You should have received a copy of the license along with this
|
||||
* program.
|
||||
*/
|
||||
|
||||
#ifndef MEGACMDCOMMONUTILS_H
|
||||
#define MEGACMDCOMMONUTILS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using std::setw;
|
||||
using std::left;
|
||||
|
||||
/* platform dependent */
|
||||
#ifdef _WIN32
|
||||
|
||||
#define OUTSTREAMTYPE std::wostream
|
||||
#define OUTSTRINGSTREAM std::wostringstream
|
||||
#define OUTSTRING std::wstring
|
||||
#define COUT std::wcout
|
||||
#define CERR std::wcerr
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str );
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str );
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str);
|
||||
|
||||
void stringtolocalw(const char* path, std::wstring* local);
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte);
|
||||
void utf16ToUtf8(const wchar_t* utf16data, int utf16size, std::string* utf8string);
|
||||
|
||||
#else
|
||||
#define OUTSTREAMTYPE std::ostream
|
||||
#define OUTSTRINGSTREAM std::ostringstream
|
||||
#define OUTSTRING std::string
|
||||
#define COUT std::cout
|
||||
#define CERR std::cerr
|
||||
|
||||
#endif
|
||||
|
||||
#define OUTSTREAM COUT
|
||||
|
||||
/* Files and folders */
|
||||
|
||||
//tests if a path is writable //TODO: move to fsAccess
|
||||
bool canWrite(std::string path);
|
||||
|
||||
bool isPublicLink(std::string link);
|
||||
|
||||
bool isEncryptedLink(std::string link);
|
||||
|
||||
bool hasWildCards(std::string &what);
|
||||
|
||||
|
||||
/* Strings related */
|
||||
|
||||
long long charstoll(const char *instr);
|
||||
|
||||
// trim from start
|
||||
std::string <rim(std::string &s, const char &c);
|
||||
|
||||
// trim at the end
|
||||
std::string &rtrim(std::string &s, const char &c);
|
||||
|
||||
std::vector<std::string> getlistOfWords(char *ptr, bool escapeBackSlashInCompletion = false, bool ignoreTrailingSpaces = false);
|
||||
|
||||
bool stringcontained(const char * s, std::vector<std::string> list);
|
||||
|
||||
char * dupstr(char* s);
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
int toInteger(std::string what, int failValue = -1);
|
||||
|
||||
std::string joinStrings(const std::vector<std::string>& vec, const char* delim = " ", bool quoted=true);
|
||||
|
||||
unsigned int getstringutf8size(const std::string &str);
|
||||
|
||||
std::string getFixLengthString(const std::string origin, unsigned int size, const char delimm=' ', bool alignedright = false);
|
||||
|
||||
std::string getRightAlignedString(const std::string origin, unsigned int minsize);
|
||||
|
||||
template<typename T>
|
||||
OUTSTRING getLeftAlignedStr(T what, int n)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
os << setw(n) << left << what;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
OUTSTRING getRightAlignedStr(T what, int n)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
os << setw(n) << what;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void printCenteredLine(std::string msj, unsigned int width, bool encapsulated = true);
|
||||
void printCenteredContents(std::string msj, unsigned int width, bool encapsulated = true);
|
||||
void printCenteredContentsCerr(std::string msj, unsigned int width, bool encapsulated = true);
|
||||
void printCenteredLine(OUTSTREAMTYPE &os, std::string msj, unsigned int width, bool encapsulated = true);
|
||||
void printCenteredContents(OUTSTREAMTYPE &os, std::string msj, unsigned int width, bool encapsulated = true);
|
||||
|
||||
void printPercentageLineCerr(const char *title, long long completed, long long total, float percentDowloaded, bool cleanLineAfter = true);
|
||||
|
||||
/* Flags and Options */
|
||||
int getFlag(std::map<std::string, int> *flags, const char * optname);
|
||||
|
||||
std::string getOption(std::map<std::string, std::string> *cloptions, const char * optname, std::string defaultValue = "");
|
||||
|
||||
int getintOption(std::map<std::string, std::string> *cloptions, const char * optname, int defaultValue = 0);
|
||||
|
||||
void discardOptionsAndFlags(std::vector<std::string> *ws);
|
||||
|
||||
//This has been defined in megacmdutils.h because it depends on logging. If ever require offer a version without it here
|
||||
//bool setOptionsAndFlags(map<string, string> *opts, map<string, int> *flags, vector<string> *ws, set<string> vvalidOptions, bool global)
|
||||
|
||||
|
||||
/* Others */
|
||||
std::string sizeToText(long long totalSize, bool equalizeUnitsLength = true, bool humanreadable = true);
|
||||
std::string sizeProgressToText(long long partialSize, long long totalSize, bool equalizeUnitsLength = true, bool humanreadable = true);
|
||||
|
||||
int64_t textToSize(const char *text);
|
||||
|
||||
std::string percentageToText(float percentage);
|
||||
|
||||
unsigned int getNumberOfCols(unsigned int defaultwidth = 90);
|
||||
|
||||
void sleepSeconds(int seconds);
|
||||
void sleepMilliSeconds(long microseconds);
|
||||
|
||||
bool isValidEmail(std::string email);
|
||||
|
||||
|
||||
/* Properties */
|
||||
std::string <rimProperty(std::string &s, const char &c);
|
||||
std::string &rtrimProperty(std::string &s, const char &c);
|
||||
std::string &trimProperty(std::string &what);
|
||||
std::string getPropertyFromFile(const char *configFile, const char *propertyName);
|
||||
template <typename T>
|
||||
T getValueFromFile(const char *configFile, const char *propertyName, T defaultValue)
|
||||
{
|
||||
std::string propValue = getPropertyFromFile(configFile, propertyName);
|
||||
if (!propValue.size()) return defaultValue;
|
||||
|
||||
T i;
|
||||
std::istringstream is(propValue);
|
||||
is >> i;
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
#endif // MEGACMDCOMMONUTILS_H
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdexecuter.h
|
||||
* @brief MEGAcmd: Executer of the commands
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -103,7 +103,7 @@ public:
|
||||
|
||||
//acting
|
||||
void loginWithPassword(char *password);
|
||||
void changePassword(const char *newpassword);
|
||||
void changePassword(const char *newpassword, std::string pin2fa = "");
|
||||
void actUponGetExtendedAccountDetails(mega::SynchronousRequestListener *srl, int timeout = -1);
|
||||
bool actUponFetchNodes(mega::MegaApi * api, mega::SynchronousRequestListener *srl, int timeout = -1);
|
||||
int actUponLogin(mega::SynchronousRequestListener *srl, int timeout = -1);
|
||||
@ -119,6 +119,7 @@ public:
|
||||
void disableShare(mega::MegaNode *n, std::string with);
|
||||
void createOrModifyBackup(std::string local, std::string remote, std::string speriod, int numBackups);
|
||||
std::vector<std::string> listpaths(bool usepcre, std::string askedPath = "", bool discardFiles = false);
|
||||
std::vector<std::string> listlocalpathsstartingby(std::string askedPath = "", bool discardFiles = false);
|
||||
std::vector<std::string> getlistusers();
|
||||
std::vector<std::string> getNodeAttrs(std::string nodePath);
|
||||
std::vector<std::string> getUserAttrs();
|
||||
@ -173,6 +174,9 @@ public:
|
||||
mega::MegaNode *getBaseNode(std::string thepath, std::string &rest, bool *isrelative = NULL);
|
||||
void getPathParts(std::string path, std::deque<std::string> *c);
|
||||
|
||||
bool checkAndInformPSA(CmdPetition *inf, bool enforce = false);
|
||||
|
||||
bool checkNoErrors(int errorCode, std::string message = "");
|
||||
bool checkNoErrors(mega::MegaError *error, std::string message = "");
|
||||
|
||||
void confirmCancel(const char* confirmlink, const char* pass);
|
||||
@ -189,6 +193,7 @@ public:
|
||||
void removeFtpLocation(mega::MegaNode *n, bool firstone, std::string name = std::string());
|
||||
void addFtpLocation(mega::MegaNode *n, bool firstone, std::string name = std::string());
|
||||
#endif
|
||||
bool printUserAttribute(int a, std::string user, bool onlylist = false);
|
||||
};
|
||||
|
||||
#endif // MEGACMDEXECUTER_H
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdlogger.cpp
|
||||
* @brief MEGAcmd: Controls message logging
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -22,6 +22,18 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _O_U16TEXT
|
||||
#define _O_U16TEXT 0x00020000
|
||||
#endif
|
||||
#ifndef _O_U8TEXT
|
||||
#define _O_U8TEXT 0x00040000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace mega;
|
||||
|
||||
@ -166,7 +178,13 @@ void setCurrentPetition(CmdPetition *petition)
|
||||
MegaCMDLogger::MegaCMDLogger()
|
||||
{
|
||||
this->output = &LCOUT;
|
||||
this->apiLoggerLevel = mega::MegaApi::LOG_LEVEL_ERROR;
|
||||
this->apiLoggerLevel = MegaApi::LOG_LEVEL_ERROR;
|
||||
this->outputmutex = new MegaMutex(false);
|
||||
}
|
||||
|
||||
MegaCMDLogger::~MegaCMDLogger()
|
||||
{
|
||||
delete this->outputmutex;
|
||||
}
|
||||
|
||||
void MegaCMDLogger::log(const char *time, int loglevel, const char *source, const char *message)
|
||||
@ -180,7 +198,16 @@ void MegaCMDLogger::log(const char *time, int loglevel, const char *source, cons
|
||||
{
|
||||
if (loglevel <= cmdLoggerLevel)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
MutexGuard g(*outputmutex);
|
||||
int oldmode;
|
||||
oldmode = _setmode(_fileno(stdout), _O_U8TEXT);
|
||||
*output << "[" << SimpleLogger::toStr(LogLevel(loglevel)) << ": " << time << "] " << message << endl;
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
#else
|
||||
*output << "[" << SimpleLogger::toStr(LogLevel(loglevel)) << ": " << time << "] " << message << endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int currentThreadLogLevel = getCurrentThreadLogLevel();
|
||||
@ -205,8 +232,15 @@ void MegaCMDLogger::log(const char *time, int loglevel, const char *source, cons
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
MutexGuard g(*outputmutex);
|
||||
int oldmode;
|
||||
oldmode = _setmode(_fileno(stdout), _O_U8TEXT);
|
||||
*output << "[API:" << SimpleLogger::toStr(LogLevel(loglevel)) << ": " << time << "] " << message << endl;
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
#else
|
||||
*output << "[API:" << SimpleLogger::toStr(LogLevel(loglevel)) << ": " << time << "] " << message << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
int currentThreadLogLevel = getCurrentThreadLogLevel();
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdlogger.h
|
||||
* @brief MEGAcmd: Controls message logging
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -112,8 +112,11 @@ private:
|
||||
int apiLoggerLevel;
|
||||
int cmdLoggerLevel;
|
||||
LoggedStream * output;
|
||||
mega::MegaMutex *outputmutex;
|
||||
|
||||
public:
|
||||
MegaCMDLogger();
|
||||
~MegaCMDLogger();
|
||||
|
||||
void log(const char *time, int loglevel, const char *source, const char *message);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdsandbox.cpp
|
||||
* @brief MegaCMD: A sandbox class to store status variables
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -30,6 +30,21 @@ void MegaCmdSandbox::setOverquota(bool value)
|
||||
overquota = value;
|
||||
}
|
||||
|
||||
void MegaCmdSandbox::resetSandBox()
|
||||
{
|
||||
this->overquota = false;
|
||||
this->istemporalbandwidthvalid = false;
|
||||
this->temporalbandwidth = 0;
|
||||
this->temporalbandwithinterval = 0;
|
||||
this->lastQuerytemporalBandwith = m_time();
|
||||
this->timeOfOverquota = m_time();
|
||||
this->secondsOverQuota = 0;
|
||||
this->accounthasbeenblocked = false;
|
||||
this->storageStatus = 0;
|
||||
this->timeOfPSACheck = 0;
|
||||
this->lastPSAnumreceived = -1;
|
||||
}
|
||||
|
||||
MegaCmdSandbox::MegaCmdSandbox()
|
||||
{
|
||||
this->overquota = false;
|
||||
@ -40,5 +55,8 @@ MegaCmdSandbox::MegaCmdSandbox()
|
||||
this->timeOfOverquota = m_time();
|
||||
this->secondsOverQuota = 0;
|
||||
this->accounthasbeenblocked = false;
|
||||
this->storageStatus = 0;
|
||||
this->timeOfPSACheck = 0;
|
||||
this->lastPSAnumreceived = -1;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdsandbox.h
|
||||
* @brief MegaCMD: A sandbox class to store status variables
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -34,12 +34,18 @@ public:
|
||||
::mega::m_time_t lastQuerytemporalBandwith;
|
||||
::mega::m_time_t timeOfOverquota;
|
||||
::mega::m_time_t secondsOverQuota;
|
||||
|
||||
::mega::m_time_t timeOfPSACheck;
|
||||
int lastPSAnumreceived;
|
||||
|
||||
bool accounthasbeenblocked;
|
||||
std::string reasonblocked;
|
||||
int storageStatus;
|
||||
public:
|
||||
MegaCmdSandbox();
|
||||
bool isOverquota() const;
|
||||
void setOverquota(bool value);
|
||||
void resetSandBox();
|
||||
};
|
||||
|
||||
#endif // MEGACMDSANDBOX_H
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @brief MEGAcmd: Interactive CLI and service application
|
||||
* This is the shell application
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is distributed under the terms of the GNU General Public
|
||||
* License, see http://www.gnu.org/copyleft/gpl.txt
|
||||
@ -17,6 +17,7 @@
|
||||
#include "megacmdshell.h"
|
||||
#include "megacmdshellcommunications.h"
|
||||
#include "megacmdshellcommunicationsnamedpipes.h"
|
||||
#include "../megacmdcommonutils.h"
|
||||
|
||||
#include "megaapi.h"
|
||||
|
||||
@ -76,29 +77,6 @@ CONSOLE_CLASS* console = NULL;
|
||||
|
||||
|
||||
// utility functions
|
||||
char * dupstr(char* s)
|
||||
{
|
||||
char *r;
|
||||
|
||||
r = (char*)malloc(sizeof( char ) * ( strlen(s) + 1 ));
|
||||
strcpy(r, s);
|
||||
return( r );
|
||||
}
|
||||
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
size_t start_pos = 0;
|
||||
while (( start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_READLINE
|
||||
string getCurrentLine()
|
||||
{
|
||||
@ -110,154 +88,11 @@ string getCurrentLine()
|
||||
}
|
||||
#endif
|
||||
|
||||
void sleepSeconds(int seconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(1000*seconds);
|
||||
#else
|
||||
sleep(seconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sleepMilliSeconds(long milliseconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(milliseconds);
|
||||
#else
|
||||
usleep(milliseconds *1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
vector<string> getlistOfWords(const char *ptr, bool ignoreTrailingSpaces = true)
|
||||
{
|
||||
vector<string> words;
|
||||
|
||||
const char* wptr;
|
||||
|
||||
// split line into words with quoting and escaping
|
||||
for (;; )
|
||||
{
|
||||
// skip leading blank space
|
||||
while (*(const signed char*)ptr > 0 && *ptr <= ' ' && (ignoreTrailingSpaces || *(ptr+1)))
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (!*ptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// quoted arg / regular arg
|
||||
if (*ptr == '"')
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '"' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '"' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*ptr == '\'') // quoted arg / regular arg
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '\'' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '\'' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*ptr == ' ') ptr++;// only possible if ptr+1 is the end
|
||||
|
||||
wptr = ptr;
|
||||
|
||||
const char *prev = ptr;
|
||||
//while ((unsigned char)*ptr > ' ')
|
||||
while ((*ptr != '\0') && !(*ptr ==' ' && *prev !='\\'))
|
||||
{
|
||||
if (*ptr == '"')
|
||||
{
|
||||
while (*++ptr != '"' && *ptr != '\0')
|
||||
{ }
|
||||
}
|
||||
prev=ptr;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
words.push_back(string(wptr, ptr - wptr));
|
||||
}
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
void discardOptionsAndFlags(vector<string> *ws)
|
||||
{
|
||||
for (std::vector<string>::iterator it = ws->begin(); it != ws->end(); )
|
||||
{
|
||||
/* std::cout << *it; ... */
|
||||
string w = ( string ) * it;
|
||||
if (w.length() && ( w.at(0) == '-' )) //begins with "-"
|
||||
{
|
||||
it = ws->erase(it);
|
||||
}
|
||||
else //not an option/flag
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// end utily functions
|
||||
|
||||
string clientID; //identifier for a registered state listener
|
||||
|
||||
long long charstoll(const char *instr)
|
||||
{
|
||||
long long retval;
|
||||
|
||||
retval = 0;
|
||||
for (; *instr; instr++) {
|
||||
retval = 10*retval + (*instr - '0');
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
// Console related functions:
|
||||
void console_readpwchar(char* pw_buf, int pw_buf_size, int* pw_buf_pos, char** line)
|
||||
{
|
||||
@ -329,40 +164,9 @@ void console_setecho(bool echo)
|
||||
#endif
|
||||
}
|
||||
|
||||
int getNumberOfCols(unsigned int defaultwidth=0)
|
||||
{
|
||||
unsigned int width = defaultwidth;
|
||||
int rows = 1, cols = width;
|
||||
#ifdef NO_READLINE
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
BOOL ok = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &sbi);
|
||||
assert(ok);
|
||||
if (ok)
|
||||
{
|
||||
cols = sbi.dwSize.X ;
|
||||
}
|
||||
#elif defined( RL_ISSTATE ) && defined( RL_STATE_INITIALIZED )
|
||||
|
||||
if (RL_ISSTATE(RL_STATE_INITIALIZED))
|
||||
{
|
||||
rl_resize_terminal();
|
||||
rl_get_screen_size(&rows, &cols);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cols)
|
||||
{
|
||||
width = cols-2;
|
||||
#ifdef _WIN32
|
||||
width--;
|
||||
#endif
|
||||
}
|
||||
return width;
|
||||
}
|
||||
bool alreadyFinished = false; //flag to show progress
|
||||
float percentDowloaded = 0.0; // to show progress
|
||||
|
||||
|
||||
// password change-related state information
|
||||
string oldpasswd;
|
||||
string newpasswd;
|
||||
@ -406,25 +210,6 @@ bool queryinguser = false;
|
||||
|
||||
void printWelcomeMsg(unsigned int width = 0);
|
||||
|
||||
unsigned int getstringutf8size(const string &str) {
|
||||
int c,i,ix,q;
|
||||
for (q=0, i=0, ix=int(str.length()); i < ix; i++, q++)
|
||||
{
|
||||
c = (unsigned char) str[i];
|
||||
|
||||
if (c>=0 && c<=127) i+=0;
|
||||
else if ((c & 0xE0) == 0xC0) i+=1;
|
||||
#ifdef _WIN32
|
||||
else if ((c & 0xF0) == 0xE0) i+=2;
|
||||
#else
|
||||
else if ((c & 0xF0) == 0xE0) {i+=2;q++;} //these gliphs may occupy 2 characters! Problem: not always. Let's assume the worse
|
||||
#endif
|
||||
else if ((c & 0xF8) == 0xF0) i+=3;
|
||||
else return 0;//invalid utf8
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
#ifdef NO_READLINE
|
||||
std::string toUtf8String(const std::wstring& ws, UINT codepage)
|
||||
{
|
||||
@ -509,10 +294,12 @@ void *warner(void * pointer)
|
||||
}
|
||||
|
||||
bool firstpromptreceived = false;
|
||||
|
||||
void statechangehandle(string statestring)
|
||||
{
|
||||
char statedelim[2]={(char)0x1F,'\0'};
|
||||
size_t nextstatedelimitpos = statestring.find(statedelim);
|
||||
static bool shown_partial_progress = false;
|
||||
|
||||
while (nextstatedelimitpos!=string::npos && statestring.size())
|
||||
{
|
||||
@ -524,9 +311,55 @@ void statechangehandle(string statestring)
|
||||
firstpromptreceived = true;
|
||||
changeprompt(newstate.substr(strlen("prompt:")).c_str(),true);
|
||||
}
|
||||
else if (newstate.compare(0, strlen("endtransfer:"), "endtransfer:") == 0)
|
||||
{
|
||||
string rest = newstate.substr(strlen("endtransfer:"));
|
||||
if (rest.size() >=3)
|
||||
{
|
||||
bool isdown = rest.at(0) == 'D';
|
||||
string path = rest.substr(2);
|
||||
stringstream os;
|
||||
if (shown_partial_progress)
|
||||
{
|
||||
os << endl;
|
||||
}
|
||||
os << (isdown?"Download":"Upload") << " finished: " << path << endl;
|
||||
|
||||
#ifdef _WIN32
|
||||
wstring wbuffer;
|
||||
stringtolocalw((const char*)os.str().data(),&wbuffer);
|
||||
int oldmode;
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
oldmode = _setmode(_fileno(stdout), _O_U8TEXT);
|
||||
OUTSTREAM << wbuffer << flush;
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
#else
|
||||
OUTSTREAM << os.str();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (newstate.compare(0, strlen("message:"), "message:") == 0)
|
||||
{
|
||||
OUTSTREAM << endl << newstate.substr(strlen("message:")) << endl;
|
||||
string contents = newstate.substr(strlen("message:"));
|
||||
unsigned int width = getNumberOfCols(75);
|
||||
if (width > 1 ) width--;
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
if (contents.find("-----") != 0)
|
||||
{
|
||||
if (!procesingline || shown_partial_progress)
|
||||
{
|
||||
OUTSTREAM << endl;
|
||||
}
|
||||
printCenteredContents(contents, width);
|
||||
}
|
||||
else
|
||||
{
|
||||
OUTSTREAM << endl << contents << endl;
|
||||
}
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
|
||||
requirepromptinstall = true;
|
||||
}
|
||||
else if (newstate.compare(0, strlen("clientID:"), "clientID:") == 0)
|
||||
{
|
||||
@ -585,6 +418,16 @@ void statechangehandle(string statestring)
|
||||
title = rest.substr(0,nexdel);
|
||||
}
|
||||
|
||||
if (received!=SPROGRESS_COMPLETE)
|
||||
{
|
||||
shown_partial_progress = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
shown_partial_progress = false;
|
||||
}
|
||||
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
if (title.size())
|
||||
{
|
||||
if (received==SPROGRESS_COMPLETE)
|
||||
@ -608,7 +451,7 @@ void statechangehandle(string statestring)
|
||||
printprogress(charstoll(received.c_str()), charstoll(total.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
}
|
||||
else if (newstate == "ack")
|
||||
{
|
||||
@ -621,16 +464,26 @@ void statechangehandle(string statestring)
|
||||
if (!comms->updating)
|
||||
{
|
||||
comms->updating = true; // to avoid mensajes about server down
|
||||
sleepSeconds(3); // Give a while for server to restart
|
||||
changeprompt("RESTART REQUIRED BY SERVER (due to an update). Press any key to continue.", true);
|
||||
}
|
||||
sleepSeconds(3); // Give a while for server to restart
|
||||
changeprompt("RESTART REQUIRED BY SERVER (due to an update). Press any key to continue.", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shown_partial_progress)
|
||||
{
|
||||
OUTSTREAM << endl;
|
||||
}
|
||||
cerr << "received unrecognized state change: [" << newstate << "]" << endl;
|
||||
//sleep a while to avoid continuous looping
|
||||
sleepSeconds(1);
|
||||
}
|
||||
|
||||
|
||||
if (newstate.compare(0, strlen("progress:"), "progress:") != 0)
|
||||
{
|
||||
shown_partial_progress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -663,25 +516,8 @@ void sigint_handler(int signum)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void printprogress(long long completed, long long total, const char *title)
|
||||
{
|
||||
int cols = getNumberOfCols(80);
|
||||
|
||||
string outputString;
|
||||
outputString.resize(cols + 1);
|
||||
for (int i = 0; i < cols; i++)
|
||||
{
|
||||
outputString[i] = '.';
|
||||
}
|
||||
|
||||
outputString[cols] = '\0';
|
||||
char *ptr = (char *)outputString.c_str();
|
||||
sprintf(ptr, "%s%s", title, " ||");
|
||||
ptr += strlen(title);
|
||||
ptr += strlen(" ||");
|
||||
*ptr = '.'; //replace \0 char
|
||||
|
||||
float oldpercent = percentDowloaded;
|
||||
if (total == 0)
|
||||
{
|
||||
@ -700,7 +536,6 @@ void printprogress(long long completed, long long total, const char *title)
|
||||
percentDowloaded = 0;
|
||||
}
|
||||
|
||||
char aux[41];
|
||||
if (total < 0)
|
||||
{
|
||||
return; // after a 100% this happens
|
||||
@ -715,22 +550,7 @@ void printprogress(long long completed, long long total, const char *title)
|
||||
completed = total;
|
||||
percentDowloaded = 100;
|
||||
}
|
||||
sprintf(aux,"||(%lld/%lld MB: %6.2f %%) ", completed / 1024 / 1024, total / 1024 / 1024, percentDowloaded);
|
||||
sprintf((char *)outputString.c_str() + cols - strlen(aux), "%s", aux);
|
||||
for (int i = 0; i < ( cols - (strlen(title) + strlen(" ||")) - strlen(aux)) * 1.0 * min(100.0f,percentDowloaded) / 100.0; i++)
|
||||
{
|
||||
*ptr++ = '#';
|
||||
}
|
||||
|
||||
if (alreadyFinished)
|
||||
{
|
||||
cerr << outputString << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << outputString << '\r' << flush;
|
||||
}
|
||||
|
||||
printPercentageLineCerr(title, completed, total, percentDowloaded, !alreadyFinished);
|
||||
}
|
||||
|
||||
|
||||
@ -1093,13 +913,6 @@ char* generic_completion(const char* text, int state, vector<string> validOption
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline bool ends_with(std::string const & value, std::string const & ending)
|
||||
{
|
||||
if (ending.size() > value.size()) return false;
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
|
||||
char* local_completion(const char* text, int state)
|
||||
{
|
||||
return((char*)NULL ); //matches will be NULL: readline will use local completion
|
||||
@ -1367,13 +1180,23 @@ vector<autocomplete::ACState::Completion> remote_completion(string linetocomplet
|
||||
|
||||
if (outputcommand.find("MEGACMD_USE_LOCAL_COMPLETION") == 0)
|
||||
{
|
||||
string where = outputcommand.substr(strlen("MEGACMD_USE_LOCAL_COMPLETION"));
|
||||
string where;
|
||||
bool folders = false;
|
||||
if (outputcommand.find("MEGACMD_USE_LOCAL_COMPLETIONFOLDERS") == 0)
|
||||
{
|
||||
where = outputcommand.substr(strlen("MEGACMD_USE_LOCAL_COMPLETIONFOLDERS"));
|
||||
folders = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
where = outputcommand.substr(strlen("MEGACMD_USE_LOCAL_COMPLETION"));
|
||||
}
|
||||
changedir(where);
|
||||
|
||||
if (acs.words.size())
|
||||
{
|
||||
string l = completionword.getQuoted();
|
||||
CompletionState cs = autoComplete(l, l.size(), acs.words[0].s == "lcd" ? localFSFolder() : localFSPath(), console->getAutocompleteStyle());
|
||||
CompletionState cs = autoComplete(l, l.size(), folders ? localFSFolder() : localFSPath(), console->getAutocompleteStyle());
|
||||
result.swap(cs.completions);
|
||||
}
|
||||
return result;
|
||||
@ -1542,8 +1365,9 @@ void process_line(const char * line)
|
||||
confirmcommand+=linktoconfirm;
|
||||
confirmcommand+=" " ;
|
||||
confirmcommand+=loginname;
|
||||
confirmcommand+=" " ;
|
||||
confirmcommand+=" \"";
|
||||
confirmcommand+=line;
|
||||
confirmcommand+="\"" ;
|
||||
OUTSTREAM << endl;
|
||||
comms->executeCommand(confirmcommand.c_str(), readresponse);
|
||||
}
|
||||
@ -1551,8 +1375,9 @@ void process_line(const char * line)
|
||||
{
|
||||
string confirmcommand("confirmcancel ");
|
||||
confirmcommand+=linktoconfirm;
|
||||
confirmcommand+=" " ;
|
||||
confirmcommand+=" \"";
|
||||
confirmcommand+=line;
|
||||
confirmcommand+="\"" ;
|
||||
OUTSTREAM << endl;
|
||||
comms->executeCommand(confirmcommand.c_str(), readresponse);
|
||||
}
|
||||
@ -1566,8 +1391,9 @@ void process_line(const char * line)
|
||||
logincommand+=" ";
|
||||
}
|
||||
logincommand+=loginname;
|
||||
logincommand+=" " ;
|
||||
logincommand+=" \"" ;
|
||||
logincommand+=line;
|
||||
logincommand+="\"" ;
|
||||
OUTSTREAM << endl;
|
||||
comms->executeCommand(logincommand.c_str(), readresponse);
|
||||
}
|
||||
@ -1604,8 +1430,9 @@ void process_line(const char * line)
|
||||
|
||||
if (signingup)
|
||||
{
|
||||
signupline += " ";
|
||||
signupline += " \"";
|
||||
signupline += newpasswd;
|
||||
signupline += "\"";
|
||||
comms->executeCommand(signupline.c_str(), readresponse);
|
||||
|
||||
signingup = false;
|
||||
@ -1614,9 +1441,16 @@ void process_line(const char * line)
|
||||
{
|
||||
string changepasscommand(passwdline);
|
||||
passwdline = " ";
|
||||
changepasscommand+=oldpasswd;
|
||||
changepasscommand+=" " ;
|
||||
if (oldpasswd.size())
|
||||
{
|
||||
changepasscommand+="\"" ;
|
||||
changepasscommand+=oldpasswd;
|
||||
changepasscommand+="\"" ;
|
||||
}
|
||||
changepasscommand+=" \"" ;
|
||||
changepasscommand+=newpasswd;
|
||||
changepasscommand+="\"" ;
|
||||
comms->executeCommand(changepasscommand.c_str(), readresponse);
|
||||
}
|
||||
}
|
||||
@ -1645,7 +1479,7 @@ void process_line(const char * line)
|
||||
line = refactoredline.c_str();
|
||||
#endif
|
||||
|
||||
vector<string> words = getlistOfWords(line);
|
||||
vector<string> words = getlistOfWords((char *)line);
|
||||
bool helprequested = false;
|
||||
for (unsigned int i = 1; i< words.size(); i++)
|
||||
{
|
||||
@ -1668,7 +1502,7 @@ void process_line(const char * line)
|
||||
doExit = true;
|
||||
}
|
||||
}
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
else if (words[0] == "update")
|
||||
{
|
||||
MegaCmdShellCommunications::updating = true;
|
||||
@ -1732,7 +1566,8 @@ void process_line(const char * line)
|
||||
{
|
||||
discardOptionsAndFlags(&words);
|
||||
|
||||
if (words.size() == 2 && (words[1].find("@") != string::npos))
|
||||
if ( (words.size() == 2 || ( words.size() == 3 && !words[2].size() ) )
|
||||
&& (words[1].find("@") != string::npos))
|
||||
{
|
||||
loginname = words[1];
|
||||
setprompt(LOGINPASSWORD);
|
||||
@ -1835,6 +1670,8 @@ void process_line(const char * line)
|
||||
}
|
||||
/* Move the cursor home */
|
||||
SetConsoleCursorPosition( hStdOut, { 0, 0 } );
|
||||
#elif __linux__
|
||||
printf("\033[H\033[J");
|
||||
#else
|
||||
rl_clear_screen(0,0);
|
||||
#endif
|
||||
@ -1873,6 +1710,10 @@ void process_line(const char * line)
|
||||
{
|
||||
unsigned int width = getNumberOfCols(75);
|
||||
int pathSize = int(width-13);
|
||||
if (strstr(line, "--versions"))
|
||||
{
|
||||
pathSize -= 11;
|
||||
}
|
||||
|
||||
toexec+=words[0];
|
||||
toexec+=" --path-display-size=";
|
||||
@ -2020,10 +1861,12 @@ void readloop()
|
||||
|
||||
readline_fd = fileno(rl_instream);
|
||||
|
||||
procesingline = true;
|
||||
comms->registerForStateChanges(statechangehandle);
|
||||
|
||||
//give it a while to communicate the state
|
||||
sleepMilliSeconds(700);
|
||||
procesingline = false;
|
||||
|
||||
#if defined(_WIN32) && defined(USE_PORT_COMMS)
|
||||
// due to a failure in reconnecting to the socket, if the server was initiated in while registeringForStateChanges
|
||||
@ -2264,24 +2107,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void printCenteredLine(string msj, unsigned int width, bool encapsulated = true)
|
||||
{
|
||||
if (msj.size()>width)
|
||||
{
|
||||
width = unsigned(msj.size());
|
||||
}
|
||||
if (encapsulated)
|
||||
COUT << "|";
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2; i++)
|
||||
COUT << " ";
|
||||
COUT << msj;
|
||||
for (unsigned int i = 0; i < (width-msj.size())/2 + (width-msj.size())%2 ; i++)
|
||||
COUT << " ";
|
||||
if (encapsulated)
|
||||
COUT << "|";
|
||||
COUT << endl;
|
||||
}
|
||||
|
||||
void printWelcomeMsg(unsigned int width)
|
||||
{
|
||||
if (!width)
|
||||
@ -2336,7 +2161,6 @@ int quote_detector(char *line, int index)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
bool runningInBackground()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
@ -2383,10 +2207,12 @@ void mycompletefunct(char **c, int num_matches, int max_length)
|
||||
{
|
||||
string option = c[i];
|
||||
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.lock();
|
||||
OUTSTREAM << setw(min(cols-1,max_length+1)) << left;
|
||||
int oldmode = _setmode(_fileno(stdout), _O_U16TEXT);
|
||||
OUTSTREAM << c[i];
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.unlock();
|
||||
|
||||
if ( (i%nelements_per_col == 0) && (i != num_matches))
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @brief MEGAcmd: Interactive CLI and service application
|
||||
* This is the shell application
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is distributed under the terms of the GNU General Public
|
||||
* License, see http://www.gnu.org/copyleft/gpl.txt
|
||||
@ -34,7 +34,7 @@ static const char* const prompts[] =
|
||||
|
||||
void sleepSeconds(int seconds);
|
||||
|
||||
void sleepMilliSeconds(long microseconds);
|
||||
void sleepMilliSeconds(long milliseconds);
|
||||
|
||||
void restoreprompt();
|
||||
|
||||
@ -54,13 +54,5 @@ void printHistory();
|
||||
|
||||
std::string readresponse(const char *question);
|
||||
|
||||
#ifdef _WIN32
|
||||
void stringtolocalw(const char* path, std::wstring* local);
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte);
|
||||
|
||||
void utf16ToUtf8(const wchar_t* utf16data, int utf16size, std::string* utf8string);
|
||||
#endif
|
||||
|
||||
|
||||
#endif // MEGACMDSHELL_H
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdshellcommunications.cpp
|
||||
* @brief MEGAcmd: Communications module to connect to server
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -80,88 +80,7 @@ bool MegaCmdShellCommunications::stopListener;
|
||||
bool MegaCmdShellCommunications::updating;
|
||||
::mega::Thread *MegaCmdShellCommunications::listenerThread;
|
||||
SOCKET MegaCmdShellCommunications::newsockfd = INVALID_SOCKET;
|
||||
|
||||
#ifdef _WIN32
|
||||
// UNICODE SUPPORT FOR WINDOWS
|
||||
|
||||
//widechar to utf8 string
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte)
|
||||
{
|
||||
if( !wide->empty() )
|
||||
{
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), NULL, 0, NULL, NULL);
|
||||
multibyte->resize(size_needed);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide->data(), (int)wide->size(), (char*)multibyte->data(), size_needed, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// convert UTF-8 to Windows Unicode wstring
|
||||
void stringtolocalw(const char* path, std::wstring* local)
|
||||
{
|
||||
// make space for the worst case
|
||||
local->resize((strlen(path) + 1) * sizeof(wchar_t));
|
||||
|
||||
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, path,-1, NULL,0);
|
||||
local->resize(wchars_num);
|
||||
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, path,-1, (wchar_t*)local->data(), wchars_num);
|
||||
|
||||
if (len)
|
||||
{
|
||||
local->resize(len-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
local->clear();
|
||||
}
|
||||
}
|
||||
|
||||
//override << operators for wostream for string and const char *
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str.c_str(),&toout);
|
||||
ostr << toout;
|
||||
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str )
|
||||
{
|
||||
std::wstring toout;
|
||||
stringtolocalw(str,&toout);
|
||||
ostr << toout;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
//override for the log. This is required for compiling, otherwise SimpleLog won't compile. FIXME
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str)
|
||||
{
|
||||
std::string s;
|
||||
localwtostring(&str,&s);
|
||||
ostr << s;
|
||||
return ( ostr );
|
||||
}
|
||||
|
||||
// convert Windows Unicode to UTF-8
|
||||
void utf16ToUtf8(const wchar_t* utf16data, int utf16size, string* utf8string)
|
||||
{
|
||||
if(!utf16size)
|
||||
{
|
||||
utf8string->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
utf8string->resize((utf16size + 1) * 4);
|
||||
|
||||
utf8string->resize(WideCharToMultiByte(CP_UTF8, 0, utf16data,
|
||||
utf16size,
|
||||
(char*)utf8string->data(),
|
||||
int(utf8string->size() + 1),
|
||||
NULL, NULL));
|
||||
}
|
||||
#endif
|
||||
MegaMutex MegaCmdShellCommunications::megaCmdStdoutputing;
|
||||
|
||||
bool MegaCmdShellCommunications::socketValid(SOCKET socket)
|
||||
{
|
||||
@ -180,7 +99,6 @@ void MegaCmdShellCommunications::closeSocket(SOCKET socket){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
string createAndRetrieveConfigFolder()
|
||||
{
|
||||
string configFolder;
|
||||
@ -565,6 +483,7 @@ MegaCmdShellCommunications::MegaCmdShellCommunications()
|
||||
stopListener = false;
|
||||
updating = false;
|
||||
listenerThread = NULL;
|
||||
MegaCmdShellCommunications::megaCmdStdoutputing.init(false);
|
||||
}
|
||||
|
||||
|
||||
@ -736,8 +655,11 @@ int MegaCmdShellCommunications::executeCommand(string command, std::string (*rea
|
||||
n = recv(newsockfd, (char *)&partialoutsize, sizeof(partialoutsize), MSG_NOSIGNAL);
|
||||
if (n && partialoutsize > 0)
|
||||
{
|
||||
megaCmdStdoutputing.lock();
|
||||
|
||||
do{
|
||||
char *buffer = new char[partialoutsize+1];
|
||||
|
||||
n = recv(newsockfd, (char *)buffer, partialoutsize, MSG_NOSIGNAL);
|
||||
if (n)
|
||||
{
|
||||
@ -757,6 +679,7 @@ int MegaCmdShellCommunications::executeCommand(string command, std::string (*rea
|
||||
}
|
||||
delete[] buffer;
|
||||
} while(n != 0 && partialoutsize && n !=SOCKET_ERROR);
|
||||
megaCmdStdoutputing.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -821,6 +744,8 @@ int MegaCmdShellCommunications::executeCommand(string command, std::string (*rea
|
||||
n = recv(newsockfd, buffer, BUFFERSIZE, MSG_NOSIGNAL);
|
||||
if (n)
|
||||
{
|
||||
megaCmdStdoutputing.lock();
|
||||
|
||||
#ifdef _WIN32
|
||||
buffer[n]='\0';
|
||||
|
||||
@ -835,6 +760,7 @@ int MegaCmdShellCommunications::executeCommand(string command, std::string (*rea
|
||||
output << string(buffer,n) << flush;
|
||||
}
|
||||
#endif
|
||||
megaCmdStdoutputing.unlock();
|
||||
}
|
||||
} while(n != 0 && n !=SOCKET_ERROR);
|
||||
|
||||
@ -998,7 +924,6 @@ int MegaCmdShellCommunications::registerForStateChanges(void (*statechangehandle
|
||||
registerAgainRequired = true;
|
||||
return -1;
|
||||
}
|
||||
OUTSTREAM << " \r" << flush;
|
||||
|
||||
int receiveSocket = SOCKET_ERROR ;
|
||||
|
||||
@ -1010,6 +935,9 @@ int MegaCmdShellCommunications::registerForStateChanges(void (*statechangehandle
|
||||
return -1;
|
||||
}
|
||||
|
||||
OUTSTREAM << "\r \r" << flush;
|
||||
|
||||
|
||||
if (listenerThread != NULL)
|
||||
{
|
||||
stopListener = true;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdshellcommunications.h
|
||||
* @brief MEGAcmd: Communications module to connect to server
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -22,6 +22,8 @@
|
||||
#ifndef MEGACMDSHELLCOMMUNICATIONS_H
|
||||
#define MEGACMDSHELLCOMMUNICATIONS_H
|
||||
|
||||
#include "../megacmdcommonutils.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
@ -51,33 +53,10 @@ class MegaThread : public ::mega::PosixThread {};
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define OUTSTREAMTYPE std::wostream
|
||||
#define OUTSTRINGSTREAM std::wostringstream
|
||||
#define OUTSTRING std::wstring
|
||||
#define COUT std::wcout
|
||||
|
||||
std::wostream & operator<< ( std::wostream & ostr, std::string const & str );
|
||||
std::wostream & operator<< ( std::wostream & ostr, const char * str );
|
||||
std::ostringstream & operator<< ( std::ostringstream & ostr, std::wstring const &str);
|
||||
|
||||
#else
|
||||
#define OUTSTREAMTYPE std::ostream
|
||||
#define OUTSTRINGSTREAM std::ostringstream
|
||||
#define OUTSTRING std::string
|
||||
#define COUT std::cout
|
||||
typedef int SOCKET;
|
||||
#endif
|
||||
|
||||
#define OUTSTREAM COUT
|
||||
|
||||
#ifdef _WIN32
|
||||
void stringtolocalw(const char* path, std::wstring* local);
|
||||
void localwtostring(const std::wstring* wide, std::string *multibyte);
|
||||
void utf16ToUtf8(const wchar_t* utf16data, int utf16size, std::string* utf8string);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define ERRNO WSAGetLastError()
|
||||
@ -115,7 +94,7 @@ enum
|
||||
MCMD_REQSTRING = -61, ///< String required
|
||||
MCMD_PARTIALOUT = -62, ///< Partial output provided
|
||||
|
||||
#ifndef __linux__
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
MCMD_REQRESTART = -71, ///< Restart required
|
||||
#endif
|
||||
};
|
||||
@ -139,6 +118,7 @@ public:
|
||||
MegaCmdShellCommunications();
|
||||
virtual ~MegaCmdShellCommunications();
|
||||
|
||||
static MegaMutex megaCmdStdoutputing;
|
||||
virtual int executeCommand(std::string command, std::string (*readresponse)(const char *) = NULL, OUTSTREAMTYPE &output = COUT, bool interactiveshell = true, std::wstring = L"");
|
||||
virtual int executeCommandW(std::wstring command, std::string (*readresponse)(const char *) = NULL, OUTSTREAMTYPE &output = COUT, bool interactiveshell = true);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdshellcommunicationsnamedpipes.cpp
|
||||
* @brief MEGAcmd: Communications module to connect to server using NamedPipes
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -574,6 +574,7 @@ int MegaCmdShellCommunicationsNamedPipes::executeCommand(string command, std::st
|
||||
|
||||
if (partialoutsize > 0)
|
||||
{
|
||||
megaCmdStdoutputing.lock();
|
||||
int oldmode;
|
||||
|
||||
if (binaryoutput)
|
||||
@ -612,6 +613,7 @@ int MegaCmdShellCommunicationsNamedPipes::executeCommand(string command, std::st
|
||||
{
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
}
|
||||
megaCmdStdoutputing.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -697,10 +699,11 @@ int MegaCmdShellCommunicationsNamedPipes::executeCommand(string command, std::st
|
||||
// in unusable output, So we disable the UTF-16 in such cases (this might cause that the output could be truncated!).
|
||||
// oldmode = _setmode(_fileno(stdout), _O_U16TEXT);
|
||||
// }
|
||||
|
||||
megaCmdStdoutputing.lock();
|
||||
oldmode = _setmode(_fileno(stdout), _O_U8TEXT);
|
||||
output << wbuffer << flush;
|
||||
_setmode(_fileno(stdout), oldmode);
|
||||
megaCmdStdoutputing.unlock();
|
||||
|
||||
// if (interactiveshell || outputtobinaryorconsole() || true)
|
||||
// {
|
||||
@ -839,8 +842,6 @@ int MegaCmdShellCommunicationsNamedPipes::registerForStateChanges(void (*statech
|
||||
cerr << "ERROR writing command to namedPipe: " << ERRNO << endl;
|
||||
return -1;
|
||||
}
|
||||
OUTSTREAM << " \r" << flush;
|
||||
|
||||
|
||||
int receiveNamedPipeNum = -1;
|
||||
|
||||
@ -850,6 +851,8 @@ int MegaCmdShellCommunicationsNamedPipes::registerForStateChanges(void (*statech
|
||||
return -1;
|
||||
}
|
||||
|
||||
OUTSTREAM << "\r \r" << flush;
|
||||
|
||||
if (listenerThread != NULL)
|
||||
{
|
||||
stopListener = true;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdshellcommunicationsnamedpipes.h
|
||||
* @brief MEGAcmd: Communications module to connect to server using NamedPipes
|
||||
*
|
||||
* (c) 2013-2017 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdutils.cpp
|
||||
* @brief MEGAcmd: Auxiliary methods
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
#include "megacmdutils.h"
|
||||
#include "listeners.h"
|
||||
|
||||
#ifdef USE_PCRE
|
||||
#include <pcrecpp.h>
|
||||
@ -106,98 +105,6 @@ const char* getAccessLevelStr(int level)
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
|
||||
const char* getAttrStr(int attr)
|
||||
{
|
||||
switch (attr)
|
||||
{
|
||||
case MegaApi::USER_ATTR_AVATAR:
|
||||
return "avatar";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_FIRSTNAME:
|
||||
return "firstname";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_LASTNAME:
|
||||
return "lastname";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_AUTHRING:
|
||||
return "authring";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_LAST_INTERACTION:
|
||||
return "lastinteraction";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_ED25519_PUBLIC_KEY:
|
||||
return "ed25519";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_CU25519_PUBLIC_KEY:
|
||||
return "cu25519";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_KEYRING:
|
||||
return "keyring";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_SIG_RSA_PUBLIC_KEY:
|
||||
return "rsa";
|
||||
|
||||
|
||||
case MegaApi::USER_ATTR_SIG_CU255_PUBLIC_KEY:
|
||||
return "cu255";
|
||||
}
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
int getAttrNum(const char* attr)
|
||||
{
|
||||
if (!strcmp(attr, "avatar"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_AVATAR;
|
||||
}
|
||||
if (!strcmp(attr, "firstname"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_FIRSTNAME;
|
||||
}
|
||||
if (!strcmp(attr, "lastname"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_LASTNAME;
|
||||
}
|
||||
if (!strcmp(attr, "authring"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_AUTHRING;
|
||||
}
|
||||
if (!strcmp(attr, "lastinteraction"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_LAST_INTERACTION;
|
||||
}
|
||||
if (!strcmp(attr, "ed25519"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_ED25519_PUBLIC_KEY;
|
||||
}
|
||||
if (!strcmp(attr, "cu25519"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_CU25519_PUBLIC_KEY;
|
||||
}
|
||||
if (!strcmp(attr, "keyring"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_KEYRING;
|
||||
}
|
||||
if (!strcmp(attr, "rsa"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_SIG_RSA_PUBLIC_KEY;
|
||||
}
|
||||
if (!strcmp(attr, "cu255"))
|
||||
{
|
||||
return MegaApi:: USER_ATTR_SIG_CU255_PUBLIC_KEY;
|
||||
}
|
||||
return atoi(attr);
|
||||
}
|
||||
|
||||
const char* getSyncPathStateStr(int state)
|
||||
{
|
||||
switch (state)
|
||||
@ -389,7 +296,15 @@ int getLogLevelNum(const char* level)
|
||||
{
|
||||
return MegaApi:: LOG_LEVEL_MAX;
|
||||
}
|
||||
return atoi(level);
|
||||
|
||||
int i = -1;
|
||||
istringstream is(level);
|
||||
is >> i;
|
||||
if (i == 0 && strcmp(level,"0"))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@ -528,24 +443,6 @@ string backupSatetStr(int backupstate)
|
||||
return "UNDEFINED";
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief tests if a path is writable
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
bool canWrite(string path) //TODO: move to fsAccess
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// TODO: Check permissions
|
||||
return true;
|
||||
#else
|
||||
if (access(path.c_str(), W_OK) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
int getLinkType(string link)
|
||||
{
|
||||
@ -561,28 +458,6 @@ int getLinkType(string link)
|
||||
return MegaNode::TYPE_FILE;
|
||||
}
|
||||
|
||||
bool isPublicLink(string link)
|
||||
{
|
||||
if (( link.find("http") == 0 ) && ( link.find("#") != string::npos ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isEncryptedLink(string link)
|
||||
{
|
||||
if (( link.find("http") == 0 ) && ( link.find("#") != string::npos ) && (link.substr(link.find("#"),3) == "#P!") )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasWildCards(string &what)
|
||||
{
|
||||
return what.find('*') != string::npos || what.find('?') != string::npos;
|
||||
}
|
||||
|
||||
const char *fillStructWithSYYmdHMS(string &stime, struct tm &dt)
|
||||
{
|
||||
@ -668,6 +543,23 @@ const char *getTimeFormatNameFromId(int strftimeformatid)
|
||||
}
|
||||
}
|
||||
|
||||
string secondsToText(m_time_t seconds, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
m_time_t reducedSize = m_time_t( seconds > 3600 * 2 ? seconds / 3600.0 : ( seconds > 60 * 2 ? seconds / 60.0 : seconds) );
|
||||
os << fixed << reducedSize;
|
||||
os << ( seconds > 3600 * 2 ? " hours" : ( seconds > 60 * 2 ? " minutes" : " seconds" ));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << seconds;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
const char *getTimeFormatFromSTR(string formatName)
|
||||
{
|
||||
@ -719,7 +611,6 @@ std::string getReadableShortTime(const m_time_t rawtime, bool showUTCDeviation)
|
||||
if (rawtime != -1)
|
||||
{
|
||||
return getReadableTime(rawtime, showUTCDeviation?MCMDTIME_SHORTWITHUTCDEVIATION:MCMDTIME_SHORT);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1049,181 +940,7 @@ bool getMinAndMaxSize(string sizestring, int64_t *minSize, int64_t *maxSize)
|
||||
|
||||
return true;
|
||||
}
|
||||
std::string <rim(std::string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_first_not_of(c);
|
||||
s = s.substr(pos == string::npos ? s.length() : pos, s.length());
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string &rtrim(std::string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_last_of(c);
|
||||
size_t last = pos == string::npos ? s.length() : pos;
|
||||
if (last + 1 < s.length())
|
||||
{
|
||||
if (s.at(last + 1) != c)
|
||||
{
|
||||
last = s.length();
|
||||
}
|
||||
}
|
||||
|
||||
s = s.substr(0, last);
|
||||
return s;
|
||||
}
|
||||
|
||||
vector<string> getlistOfWords(char *ptr, bool ignoreTrailingSpaces)
|
||||
{
|
||||
vector<string> words;
|
||||
|
||||
char* wptr;
|
||||
|
||||
// split line into words with quoting and escaping
|
||||
for (;; )
|
||||
{
|
||||
// skip leading blank space
|
||||
while (*(const signed char*)ptr > 0 && *ptr <= ' ' && (ignoreTrailingSpaces || *(ptr+1)))
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (!*ptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// quoted arg / regular arg
|
||||
if (*ptr == '"')
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '"' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '"' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*ptr == '\'') // quoted arg / regular arg
|
||||
{
|
||||
ptr++;
|
||||
wptr = ptr;
|
||||
words.push_back(string());
|
||||
|
||||
for (;; )
|
||||
{
|
||||
if (( *ptr == '\'' ) || ( *ptr == '\\' ) || !*ptr)
|
||||
{
|
||||
words[words.size() - 1].append(wptr, ptr - wptr);
|
||||
|
||||
if (!*ptr || ( *ptr++ == '\'' ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
wptr = ptr - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*ptr == ' ') ptr++;// only possible if ptr+1 is the end
|
||||
|
||||
wptr = ptr;
|
||||
|
||||
char *prev = ptr;
|
||||
//while ((unsigned char)*ptr > ' ')
|
||||
while ((*ptr != '\0') && !(*ptr ==' ' && *prev !='\\'))
|
||||
{
|
||||
if (*ptr == '"')
|
||||
{
|
||||
while (*++ptr != '"' && *ptr != '\0')
|
||||
{ }
|
||||
}
|
||||
prev=ptr;
|
||||
ptr++;
|
||||
}
|
||||
string newword(wptr, ptr - wptr);
|
||||
words.push_back(newword);
|
||||
}
|
||||
}
|
||||
|
||||
if (!getCurrentThreadIsCmdShell() && words.size()> 1 && words[0] == "completion")
|
||||
{
|
||||
for (int i = 1; i < (int)words.size(); i++)
|
||||
{
|
||||
replaceAll(words[i],"\\","\\\\");
|
||||
}
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
bool stringcontained(const char * s, vector<string> list)
|
||||
{
|
||||
for (int i = 0; i < (int)list.size(); i++)
|
||||
{
|
||||
if (list[i] == s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
char * dupstr(char* s)
|
||||
{
|
||||
char *r;
|
||||
|
||||
r = (char*)malloc(sizeof( char ) * ( strlen(s) + 1 ));
|
||||
strcpy(r, s);
|
||||
return( r );
|
||||
}
|
||||
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
size_t start_pos = str.find(from);
|
||||
if (start_pos == std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to)
|
||||
{
|
||||
if (from.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
size_t start_pos = 0;
|
||||
while (( start_pos = str.find(from, start_pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length();
|
||||
}
|
||||
}
|
||||
|
||||
bool isRegExp(string what)
|
||||
{
|
||||
@ -1402,131 +1119,22 @@ bool patternMatches(const char *what, const char *pattern, bool usepcre)
|
||||
return megacmdWildcardMatch(what,pattern);
|
||||
}
|
||||
|
||||
int toInteger(string what, int failValue)
|
||||
bool nodeNameIsVersion(string &nodeName)
|
||||
{
|
||||
if (what.empty())
|
||||
bool isversion = false;
|
||||
if (nodeName.size() > 12 && nodeName.at(nodeName.size()-11) =='#') //TODO: def version separator elswhere
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
if (!isdigit(what[0]) && !( what[0] != '-' ) && ( what[0] != '+' ))
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
|
||||
char * p;
|
||||
long l = strtol(what.c_str(), &p, 10);
|
||||
|
||||
if (*p != 0)
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
|
||||
if (( l < INT_MIN ) || ( l > INT_MAX ))
|
||||
{
|
||||
return failValue;
|
||||
}
|
||||
return (int)l;
|
||||
}
|
||||
|
||||
string joinStrings(const vector<string>& vec, const char* delim, bool quoted)
|
||||
{
|
||||
stringstream res;
|
||||
if (!quoted)
|
||||
{
|
||||
copy(vec.begin(), vec.end(), ostream_iterator<string>(res, delim));
|
||||
}
|
||||
else
|
||||
{
|
||||
for(vector<string>::const_iterator i = vec.begin(); i != vec.end(); ++i)
|
||||
for (size_t i = nodeName.size()-10; i < nodeName.size() ; i++)
|
||||
{
|
||||
res << "\"" << *i << "\"" << delim;
|
||||
if (nodeName.at(i) > '9' || nodeName.at(i) < '0')
|
||||
break;
|
||||
if (i == (nodeName.size() - 1))
|
||||
{
|
||||
isversion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vec.size()>1)
|
||||
{
|
||||
string toret = res.str();
|
||||
return toret.substr(0,toret.size()-strlen(delim));
|
||||
}
|
||||
return res.str();
|
||||
}
|
||||
|
||||
unsigned int getstringutf8size(const string &str) {
|
||||
int c,i,ix,q;
|
||||
for (q=0, i=0, ix=int(str.length()); i < ix; i++, q++)
|
||||
{
|
||||
c = (unsigned char) str[i];
|
||||
|
||||
if (c>=0 && c<=127) i+=0;
|
||||
else if ((c & 0xE0) == 0xC0) i+=1;
|
||||
#ifdef _WIN32
|
||||
else if ((c & 0xF0) == 0xE0) i+=2;
|
||||
#else
|
||||
else if ((c & 0xF0) == 0xE0) {i+=2;q++;} //these gliphs may occupy 2 characters! Problem: not always. Let's assume the worse
|
||||
#endif
|
||||
else if ((c & 0xF8) == 0xF0) i+=3;
|
||||
else return 0;//invalid utf8
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
string getFixLengthString(const string origin, unsigned int size, const char delim, bool alignedright)
|
||||
{
|
||||
string toret;
|
||||
size_t printableSize = getstringutf8size(origin);
|
||||
size_t bytesSize = origin.size();
|
||||
if (printableSize <= size){
|
||||
if (alignedright)
|
||||
{
|
||||
toret.insert(0,size-printableSize,delim);
|
||||
toret.insert(size-bytesSize,origin,0,bytesSize);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
toret.insert(0,origin,0,bytesSize);
|
||||
toret.insert(bytesSize,size-printableSize,delim);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
toret.insert(0,origin,0,(size+1)/2-2);
|
||||
if (size > 3) toret.insert((size+1)/2-2,3,'.');
|
||||
if (size > 1) toret.insert((size+1)/2+1,origin,bytesSize-(size)/2+1,(size)/2-1); //TODO: This could break characters if multibyte! //alternative: separate in multibyte strings and print one by one?
|
||||
}
|
||||
|
||||
return toret;
|
||||
}
|
||||
|
||||
string getRightAlignedString(const string origin, unsigned int minsize)
|
||||
{
|
||||
ostringstream os;
|
||||
os << std::setw(minsize) << origin;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int getFlag(map<string, int> *flags, const char * optname)
|
||||
{
|
||||
return flags->count(optname) ? ( *flags )[optname] : 0;
|
||||
}
|
||||
|
||||
string getOption(map<string, string> *cloptions, const char * optname, string defaultValue)
|
||||
{
|
||||
return cloptions->count(optname) ? ( *cloptions )[optname] : defaultValue;
|
||||
}
|
||||
|
||||
int getintOption(map<string, string> *cloptions, const char * optname, int defaultValue)
|
||||
{
|
||||
if (cloptions->count(optname))
|
||||
{
|
||||
int i = defaultValue;
|
||||
istringstream is(( *cloptions )[optname]);
|
||||
is >> i;
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return isversion;
|
||||
}
|
||||
|
||||
bool setOptionsAndFlags(map<string, string> *opts, map<string, int> *flags, vector<string> *ws, set<string> vvalidOptions, bool global)
|
||||
@ -1601,299 +1209,6 @@ bool setOptionsAndFlags(map<string, string> *opts, map<string, int> *flags, vect
|
||||
}
|
||||
|
||||
|
||||
string sizeProgressToText(long long partialSize, long long totalSize, bool equalizeUnitsLength, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
string unit;
|
||||
unit = ( equalizeUnitsLength ? " B" : "B" );
|
||||
double reducedPartSize = (double)totalSize;
|
||||
double reducedSize = (double)totalSize;
|
||||
|
||||
if ( totalSize > 1099511627776LL *2 )
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1099511627776ull;
|
||||
reducedSize = totalSize / (double) 1099511627776ull;
|
||||
unit = "TB";
|
||||
}
|
||||
else if ( totalSize > 1073741824LL *2 )
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1073741824L;
|
||||
reducedSize = totalSize / (double) 1073741824L;
|
||||
unit = "GB";
|
||||
}
|
||||
else if (totalSize > 1048576 * 2)
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1048576;
|
||||
reducedSize = totalSize / (double) 1048576;
|
||||
unit = "MB";
|
||||
}
|
||||
else if (totalSize > 1024 * 2)
|
||||
{
|
||||
reducedPartSize = totalSize / (double) 1024;
|
||||
reducedSize = totalSize / (double) 1024;
|
||||
unit = "KB";
|
||||
}
|
||||
os << fixed << reducedPartSize << "/" << reducedSize;
|
||||
os << " " << unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << partialSize << "/" << totalSize;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string sizeToText(long long totalSize, bool equalizeUnitsLength, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
string unit;
|
||||
unit = ( equalizeUnitsLength ? " B" : "B" );
|
||||
double reducedSize = (double)totalSize;
|
||||
|
||||
if ( totalSize > 1099511627776LL *2 )
|
||||
{
|
||||
reducedSize = totalSize / (double) 1099511627776ull;
|
||||
unit = "TB";
|
||||
}
|
||||
else if ( totalSize > 1073741824LL *2 )
|
||||
{
|
||||
reducedSize = totalSize / (double) 1073741824L;
|
||||
unit = "GB";
|
||||
}
|
||||
else if (totalSize > 1048576 * 2)
|
||||
{
|
||||
reducedSize = totalSize / (double) 1048576;
|
||||
unit = "MB";
|
||||
}
|
||||
else if (totalSize > 1024 * 2)
|
||||
{
|
||||
reducedSize = totalSize / (double) 1024;
|
||||
unit = "KB";
|
||||
}
|
||||
os << fixed << reducedSize;
|
||||
os << " " << unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << totalSize;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int64_t textToSize(const char *text)
|
||||
{
|
||||
int64_t sizeinbytes = 0;
|
||||
|
||||
char * ptr = (char *)text;
|
||||
char * last = (char *)text;
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
if (( *ptr < '0' ) || ( *ptr > '9' ) || ( *ptr == '.' ) )
|
||||
{
|
||||
switch (*ptr)
|
||||
{
|
||||
case 'b': //Bytes
|
||||
case 'B':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(atof(last));
|
||||
break;
|
||||
|
||||
case 'k': //KiloBytes
|
||||
case 'K':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1024.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 'm': //MegaBytes
|
||||
case 'M':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1048576.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 'g': //GigaBytes
|
||||
case 'G':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1073741824.0 * atof(last));
|
||||
break;
|
||||
|
||||
case 't': //TeraBytes
|
||||
case 'T':
|
||||
*ptr = '\0';
|
||||
sizeinbytes += int64_t(1125899906842624.0 * atof(last));
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
last = ptr + 1;
|
||||
}
|
||||
char *prev = ptr;
|
||||
ptr++;
|
||||
if (*ptr == '\0' && ( ( *prev == '.' ) || ( ( *prev >= '0' ) && ( *prev <= '9' ) ) ) ) //reach the end with a number or dot
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return sizeinbytes;
|
||||
|
||||
}
|
||||
|
||||
string secondsToText(m_time_t seconds, bool humanreadable)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (humanreadable)
|
||||
{
|
||||
m_time_t reducedSize = m_time_t( seconds > 3600 * 2 ? seconds / 3600.0 : ( seconds > 60 * 2 ? seconds / 60.0 : seconds) );
|
||||
os << fixed << reducedSize;
|
||||
os << ( seconds > 3600 * 2 ? " hours" : ( seconds > 60 * 2 ? " minutes" : " seconds" ));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << seconds;
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string percentageToText(float percentage)
|
||||
{
|
||||
ostringstream os;
|
||||
os.precision(2);
|
||||
if (percentage != percentage) //NaN
|
||||
{
|
||||
os << "----%";
|
||||
}
|
||||
else
|
||||
{
|
||||
os << fixed << percentage*100.0 << "%";
|
||||
}
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
unsigned int getNumberOfCols(unsigned int defaultwidth)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
int columns;
|
||||
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
columns = csbi.srWindow.Right - csbi.srWindow.Left - 1;
|
||||
|
||||
return columns;
|
||||
#else
|
||||
struct winsize size;
|
||||
if (ioctl(STDOUT_FILENO,TIOCGWINSZ,&size) != -1)
|
||||
{
|
||||
if (size.ws_col > 2)
|
||||
{
|
||||
return size.ws_col - 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return defaultwidth;
|
||||
}
|
||||
|
||||
void sleepSeconds(int seconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(1000*seconds);
|
||||
#else
|
||||
sleep(seconds);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sleepMilliSeconds(long microseconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(microseconds);
|
||||
#else
|
||||
usleep(microseconds*1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isValidEmail(string email)
|
||||
{
|
||||
return !( (email.find("@") == string::npos)
|
||||
|| (email.find_last_of(".") == string::npos)
|
||||
|| (email.find("@") > email.find_last_of(".")));
|
||||
}
|
||||
|
||||
string <rimProperty(string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_first_not_of(c);
|
||||
s = s.substr(pos == string::npos ? s.length() : pos, s.length());
|
||||
return s;
|
||||
}
|
||||
|
||||
string &rtrimProperty(string &s, const char &c)
|
||||
{
|
||||
size_t pos = s.find_last_not_of(c);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
s = s.substr(0, pos);
|
||||
return s;
|
||||
}
|
||||
|
||||
string &trimProperty(string &what)
|
||||
{
|
||||
rtrimProperty(what,' ');
|
||||
ltrimProperty(what,' ');
|
||||
if (what.size() > 1)
|
||||
{
|
||||
if (what[0] == '\'' || what[0] == '"')
|
||||
{
|
||||
rtrimProperty(what, what[0]);
|
||||
ltrimProperty(what, what[0]);
|
||||
}
|
||||
}
|
||||
return what;
|
||||
}
|
||||
|
||||
string getPropertyFromFile(const char *configFile, const char *propertyName)
|
||||
{
|
||||
ifstream infile(configFile);
|
||||
string line;
|
||||
|
||||
while (getline(infile, line))
|
||||
{
|
||||
if (line.length() > 0 && line[0] != '#')
|
||||
{
|
||||
if (!strlen(propertyName)) //if empty return first line
|
||||
{
|
||||
return trimProperty(line);
|
||||
}
|
||||
string key, value;
|
||||
size_t pos = line.find("=");
|
||||
if (pos != string::npos && ((pos + 1) < line.size()))
|
||||
{
|
||||
key = line.substr(0, pos);
|
||||
rtrimProperty(key, ' ');
|
||||
|
||||
if (!strcmp(key.c_str(), propertyName))
|
||||
{
|
||||
value = line.substr(pos + 1);
|
||||
return trimProperty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string();
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
string readablePermissions(int permvalue)
|
||||
@ -1925,22 +1240,3 @@ int permissionsFromReadable(string permissions)
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool nodeNameIsVersion(string &nodeName)
|
||||
{
|
||||
bool isversion = false;
|
||||
if (nodeName.size() > 12 && nodeName.at(nodeName.size()-11) =='#') //TODO: def version separator elswhere
|
||||
{
|
||||
for (size_t i = nodeName.size()-10; i < nodeName.size() ; i++)
|
||||
{
|
||||
if (nodeName.at(i) > '9' || nodeName.at(i) < '0')
|
||||
break;
|
||||
if (i == (nodeName.size() - 1))
|
||||
{
|
||||
isversion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isversion;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @file src/megacmdutils.h
|
||||
* @brief MEGAcmd: Auxiliary methods
|
||||
*
|
||||
* (c) 2013-2016 by Mega Limited, Auckland, New Zealand
|
||||
* (c) 2013 by Mega Limited, Auckland, New Zealand
|
||||
*
|
||||
* This file is part of the MEGAcmd.
|
||||
*
|
||||
@ -19,8 +19,11 @@
|
||||
#ifndef MEGACMDUTILS_H
|
||||
#define MEGACMDUTILS_H
|
||||
|
||||
#include "megacmdcommonutils.h"
|
||||
#include "megacmd.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using ::mega::m_time_t;
|
||||
|
||||
/* mega::MegaNode info extracting*/
|
||||
@ -30,10 +33,6 @@ std::string getUserInSharedNode(mega::MegaNode *n, mega::MegaApi *api);
|
||||
|
||||
|
||||
/* code translation*/
|
||||
const char* getAttrStr(int attr);
|
||||
|
||||
int getAttrNum(const char* attr);
|
||||
|
||||
const char* getAccessLevelStr(int level);
|
||||
|
||||
const char* getSyncPathStateStr(int state);
|
||||
@ -59,20 +58,10 @@ const char * getTransferStateStr(int transferState);
|
||||
std::string backupSatetStr(int backupstate);
|
||||
|
||||
|
||||
|
||||
/* Files and folders */
|
||||
|
||||
bool canWrite(std::string path);
|
||||
|
||||
int getLinkType(std::string link);
|
||||
|
||||
bool isPublicLink(std::string link);
|
||||
|
||||
bool isEncryptedLink(std::string link);
|
||||
|
||||
bool hasWildCards(std::string &what);
|
||||
|
||||
|
||||
/* Time related */
|
||||
const char *fillStructWithSYYmdHMS(std::string &stime, struct tm &dt);
|
||||
|
||||
@ -90,6 +79,8 @@ enum MegaCmdStrfTimeFormatId
|
||||
const char *getTimeFormatFromSTR(std::string formatName);
|
||||
const char *getFormatStrFromId(int strftimeformatid);
|
||||
const char *getTimeFormatNameFromId(int strftimeformatid);
|
||||
std::string secondsToText(m_time_t seconds, bool humanreadable = true);
|
||||
|
||||
std::string getReadableTime(const m_time_t rawtime, const char* strftimeformat);
|
||||
std::string getReadableTime(const m_time_t rawtime, int strftimeformatid = MCMDTIME_RFC2822);
|
||||
std::string getReadableShortTime(const m_time_t rawtime, bool showUTCDeviation = false);
|
||||
@ -110,106 +101,25 @@ bool getMinAndMaxTime(m_time_t initial, std::string m_timestring, m_time_t *minT
|
||||
|
||||
|
||||
/* Strings related */
|
||||
|
||||
// trim from start
|
||||
std::string <rim(std::string &s, const char &c);
|
||||
|
||||
// trim at the end
|
||||
std::string &rtrim(std::string &s, const char &c);
|
||||
|
||||
std::vector<std::string> getlistOfWords(char *ptr, bool ignoreTrailingSpaces = false);
|
||||
|
||||
bool stringcontained(const char * s, std::vector<std::string> list);
|
||||
|
||||
char * dupstr(char* s);
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
void replaceAll(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
bool isRegExp(std::string what);
|
||||
|
||||
std::string unquote(std::string what);
|
||||
|
||||
bool megacmdWildcardMatch(const char *pszString, const char *pszMatch);
|
||||
|
||||
bool patternMatches(const char *what, const char *pattern, bool usepcre);
|
||||
|
||||
int toInteger(std::string what, int failValue = -1);
|
||||
|
||||
std::string joinStrings(const std::vector<std::string>& vec, const char* delim = " ", bool quoted=true);
|
||||
|
||||
std::string getFixLengthString(const std::string origin, unsigned int size, const char delimm=' ', bool alignedright = false);
|
||||
|
||||
std::string getRightAlignedString(const std::string origin, unsigned int minsize);
|
||||
|
||||
|
||||
template<typename T>
|
||||
OUTSTRING getLeftAlignedStr(T what, int n)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
os << setw(n) << left << what;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
OUTSTRING getRightAlignedStr(T what, int n)
|
||||
{
|
||||
OUTSTRINGSTREAM os;
|
||||
os << setw(n) << what;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
bool nodeNameIsVersion(std::string &nodeName);
|
||||
|
||||
|
||||
/* Flags and Options */
|
||||
int getFlag(std::map<std::string, int> *flags, const char * optname);
|
||||
|
||||
std::string getOption(std::map<std::string, std::string> *cloptions, const char * optname, std::string defaultValue = "");
|
||||
|
||||
int getintOption(std::map<std::string, std::string> *cloptions, const char * optname, int defaultValue = 0);
|
||||
|
||||
bool setOptionsAndFlags(std::map<std::string, std::string> *opts, std::map<std::string, int> *flags, std::vector<std::string> *ws,
|
||||
std::set<std::string> vvalidOptions, bool global = false);
|
||||
|
||||
bool getMinAndMaxSize(std::string sizestring, int64_t *minSize, int64_t *maxSize);
|
||||
|
||||
/* Others */
|
||||
std::string sizeToText(long long totalSize, bool equalizeUnitsLength = true, bool humanreadable = true);
|
||||
std::string sizeProgressToText(long long partialSize, long long totalSize, bool equalizeUnitsLength = true, bool humanreadable = true);
|
||||
|
||||
int64_t textToSize(const char *text);
|
||||
|
||||
std::string secondsToText(m_time_t seconds, bool humanreadable = true);
|
||||
|
||||
std::string percentageToText(float percentage);
|
||||
|
||||
std::string readablePermissions(int permvalue);
|
||||
int permissionsFromReadable(std::string permissions);
|
||||
|
||||
unsigned int getNumberOfCols(unsigned int defaultwidth = 90);
|
||||
|
||||
void sleepSeconds(int seconds);
|
||||
void sleepMilliSeconds(long microseconds);
|
||||
|
||||
bool isValidEmail(std::string email);
|
||||
|
||||
|
||||
/* Properties */
|
||||
std::string <rimProperty(std::string &s, const char &c);
|
||||
std::string &rtrimProperty(std::string &s, const char &c);
|
||||
std::string &trimProperty(std::string &what);
|
||||
std::string getPropertyFromFile(const char *configFile, const char *propertyName);
|
||||
template <typename T>
|
||||
T getValueFromFile(const char *configFile, const char *propertyName, T defaultValue)
|
||||
{
|
||||
std::string propValue = getPropertyFromFile(configFile, propertyName);
|
||||
if (!propValue.size()) return defaultValue;
|
||||
|
||||
T i;
|
||||
std::istringstream is(propValue);
|
||||
is >> i;
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
#endif // MEGACMDUTILS_H
|
||||
|
@ -16,24 +16,26 @@
|
||||
#endif
|
||||
|
||||
const char * const megacmdchangelog =
|
||||
#if defined(_WIN32) && defined(NO_READLINE)
|
||||
"unicode support vastly improved (See \"help --unicode\")""\n"
|
||||
#endif
|
||||
"added FTP support (See \"ftp\")""\n"
|
||||
"renew path parsing & improved completion with special characters""\n"
|
||||
"fix truncated redirected output in MacOS""\n"
|
||||
"added support for account cancelation(See \"cancel\")""\n"
|
||||
"cp now allows multiple sourth paths and regular expresions""\n"
|
||||
"du path display size variable now""\n"
|
||||
"output error code always positive now""\n"
|
||||
"new command \"errorcode\" to translate error code into string""\n"
|
||||
"allow password protected links for PRO users""\n"
|
||||
"password changing no longer requires old one""\n"
|
||||
"webdav now allows stop serving all locations""\n"
|
||||
"added \"graphisc\" command to turn off thumbnails/previews generation""\n"
|
||||
"support login and password change using 2FA""\n"
|
||||
"limit one instance of server""\n"
|
||||
"many more minor fixes & adjustements"
|
||||
"added \"cat\" command to read text files (and potentially stream any file)""\n"
|
||||
"added update capabilities for Windows & MacOS (automatic updates are enabled by default)""\n"
|
||||
"added \"media-info\" command to show some information of multimedia files""\n"
|
||||
"added \"df\" command to show storage info""\n"
|
||||
"added tree-like listing command: \"tree\" or \"ls --tree\"""\n"
|
||||
"shown progress in non-interactive mode""\n"
|
||||
"improvements in progress and transfers results information""\n"
|
||||
"width output adjustments in non-interactive mode""\n"
|
||||
"output streamed partially from server to clients""\n"
|
||||
"added --time-format option to commands displaying times, to allow other formats""\n"
|
||||
"2FA login auth code can be passed as parameter now""\n"
|
||||
"transfer now differentiate backup transfers""\n"
|
||||
"backup command completion for local paths now only looks for folders""\n"
|
||||
"backup transfers are no longer cached (no reason to: backups are considered failed in such case)""\n"
|
||||
"backup fix some halts and output improvements""\n"
|
||||
"added Public Service Announcements (PSA) support""\n"
|
||||
"killsession now allows multiple parameters""\n"
|
||||
"fix \"clear\" in some linuxes""\n"
|
||||
"add support for spaces in password prompts""\n"
|
||||
"many more minor fixes & adjustments"
|
||||
;
|
||||
|
||||
|
||||
|
@ -15,8 +15,7 @@ const char EMERGENCY_UPDATE_CHECK_URL[] = "http://g.static.mega.co.nz/eupd/mcmd
|
||||
const char APP_DIR_BUNDLE[] = "/Applications/MEGAcmd.app/";
|
||||
#endif
|
||||
|
||||
//TODO: update Keys
|
||||
const char UPDATE_PUBLIC_KEY[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
const char UPDATE_PUBLIC_KEY[] = "EACuusrffoqCAsjS824EsQ04pvuDKHUd8PCAfPLsowLBMGWmcxmX-tgk05EXkdyHZPixEda96XadqudlQOEYLBlxMgcAwDkewKoW1XtBQVm3wXeHIvEeBimpWWU6Z6qYP5BiCbW-wCTDS67f4LdkrbA4hcJiVTxQxRUxoJU-I-DCh0ZLCxdrXHpWBrXGv9hFfxMFhr01YGxcW1tgqRx5r6q3YPpFaGo-q9ib3YIBE2HMAc_n_ayz4g5HMAq-C61WT_vhHzPnoCUwpRH68TCoop-3VlYTo8Ps-Xzno1OazCH6VM5MiCLS0X5jhh54RveVZn44MRMLDdj3jzUed4-hFgOXNYLLX1kDRlXiDwGtht-wPJF7BLNVkRolfOUrsONmw3Tbz_ywB-TK7pjhlYoMo7enwABT1iBQoub80OEi-1ltMnzFRWu6o7KCsCqnDtJpALG04B6E1aWvO2HK0-UQNIAPfbErtG4pVVirIaSq4vX5BlmYJ_XCAsaFuLufJvBQBIEwCJRdQ96o4plgzHuJwlaEeYd2dMEjafOi3DBPV7OjN9H7yI0NyHDrqV_hDAmMqHHPu3hdhqkdrSFmcMVGsxXkaOnXDNmJfdwr_mostPY-Uwx_g2vRHKgLpkntlIlvh0GALEzLpukdmnKgXrUNRXrIyyjoRXGNMlBTdV8vAMlGVQAFEQ";
|
||||
const char UPDATE_FILENAME[] = "v.txt";
|
||||
const char UPDATE_FOLDER_NAME[] = "eupdate";
|
||||
const char BACKUP_FOLDER_NAME[] = "ebackup";
|
||||
|
@ -30,9 +30,8 @@
|
||||
#include "Preferences.h"
|
||||
#include "MacUtils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace CryptoPP;
|
||||
|
||||
using std::string;
|
||||
using CryptoPP::Integer;
|
||||
|
||||
enum {
|
||||
LOG_LEVEL_FATAL = 0, // Very severe error event that will presumably lead the application to abort.
|
||||
@ -266,9 +265,9 @@ string UpdateTask::getAppDataDir()
|
||||
|
||||
#define MEGA_TO_NATIVE_SEPARATORS(x) std::replace(x.begin(), x.end(), '\\', '/');
|
||||
#define MEGA_SET_PERMISSIONS chmod("/Applications/MEGAcmd.app/Contents/MacOS/mega-cmd", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); \
|
||||
chmod("/Applications/MEGAcmd.app/Contents/MacOS/MEGAupdater", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
//TODO: figure if this is enough in MAC ^
|
||||
|
||||
chmod("/Applications/MEGAcmd.app/Contents/MacOS/MEGAcmdShell", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); \
|
||||
chmod("/Applications/MEGAcmd.app/Contents/MacOS/MEGAcmd", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); \
|
||||
chmod("/Applications/MEGAcmd.app/Contents/MacOS/MEGAcmdUpdater", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
|
||||
string UpdateTask::getAppDir()
|
||||
{
|
||||
@ -671,20 +670,7 @@ bool UpdateTask::performUpdate()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mega_size(update.c_str()))
|
||||
{
|
||||
if (mega_remove(origFile.c_str()))
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Error installing file %s in %s", update.c_str(), origFile.c_str());
|
||||
rollbackUpdate(i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setPermissions(origFile.c_str());
|
||||
}
|
||||
|
||||
setPermissions(origFile.c_str());
|
||||
LOG(LOG_LEVEL_INFO, "File correctly installed: %s", localPaths[i].c_str());
|
||||
}
|
||||
else
|
||||
@ -726,6 +712,10 @@ void UpdateTask::finalCleanup()
|
||||
bool UpdateTask::setPermissions(const char *path)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
if (path && string(path).find("/mega-") != string::npos)
|
||||
{
|
||||
chmod(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if (!isPublic)
|
||||
|
@ -16,6 +16,12 @@
|
||||
#include <cryptopp/hmac.h>
|
||||
#include <cryptopp/pwdbased.h>
|
||||
|
||||
#if CRYPTOPP_VERSION >= 600 && ((__cplusplus >= 201103L) || (__RPCNDR_H_VERSION__ == 500))
|
||||
using byte = CryptoPP::byte;
|
||||
#elif __RPCNDR_H_VERSION__ != 500
|
||||
typedef unsigned char byte;
|
||||
#endif
|
||||
|
||||
class Base64
|
||||
{
|
||||
static byte to64(byte);
|
||||
|
Loading…
x
Reference in New Issue
Block a user