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

Rewrote lots of the code #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import sys
import os
import webbrowser
from PyQt4 import QtGui, QtCore
from ui_files import main_gui

Path = os.getcwd() + "/Backups/" + "backup.ab"
Path = QtCore.QDir.toNativeSeparators(Path)

class Window(QtGui.QDialog, main_gui.Ui_mainWindow):
def __init__(self):
super(Window, self).__init__()
self.setupUi(self)
self.initUI()

self.bakAllNoSys.clicked.connect(self.backup_all_without_system)
self.bakAll.clicked.connect(self.backup_all_with_system)
self.bakAppDevData.clicked.connect(self.backup_app_data_and_device_data)
self.bakApp.clicked.connect(self.backup_apps)
self.bakStorSd.clicked.connect(self.backup_storage)
self.restoreBtn.clicked.connect(self.getBackupLocation)
self.smsBakRestore.clicked.connect(self.installSmsApp)
self.bakBrowseBtn.clicked.connect(self.openBrowseWindow)
self.wirelessAdb.clicked.connect(self.connectWirelessADB)
self.systemAdb.toggled.connect(self.adbBinaryChange)

def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())

def showDialog(self):
text, ok = QtGui.QInputDialog.getText(self, 'Backup single app', "You should be seeing a list of installed packages in the second window. Enter which one you want to backup.")
if ok:
self.PackageToBackup = str(text)

def showDisclaimer(self):
popup_msg = "ADB Backup is an undocumented, hacky and untested part of the Android SDK. There are various phones and tablets it has trouble with, and on certain devices, it's fairly likely it'll produce an empty backup file for no reason. Some functions might not work properly without root access to your device.\n\nAs a result of this, I strongly recommend that you check if the application actually works for you before relying on it as your only backup solution."
reply = QtGui.QMessageBox.question(self, 'Disclaimer', popup_msg, QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel)

if not reply == QtGui.QMessageBox.Ok:
exit(0)

def password_popup(self):
popup_msg = "This program only works properly if you've set a 'Desktop backup password' in Developer Options. Have you done that?"
reply = QtGui.QMessageBox.question(self, 'Warning!',
popup_msg, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)

if reply is not QtGui.QMessageBox.Yes:
return

def progress_popup(self):
popup_msg = "Ready to start the operation. You'll need to monitor the rest of the process on your device. Be careful not to close the main window until it's done!"
reply = QtGui.QMessageBox.question(self, 'Ready!',
popup_msg, QtGui.QMessageBox.Ok)

def root_popup(self):
popup_msg = "Backups can only be performed when the application is run as superuser/root. Please do that now."
reply = QtGui.QMessageBox.question(self, 'Warning!',
popup_msg, QtGui.QMessageBox.Ok)
exit(0)

def sms_popup(self):
popup_msg = "SMS Backup+, a great open-source application by Jan Berkel, will now be installed and launched on your device.\n\nYou can use this to back up and restore your SMS messages and call log entries using a custom label in your Gmail."
reply = QtGui.QMessageBox.question(self, 'SMS Backup / Restore',
popup_msg, QtGui.QMessageBox.Ok)

def backup_all_without_system(self, event):

if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb backup -apk -shared -all -nosystem -f \"" + Path + "\"\""))
else:
os.system(str("adb backup -apk -shared -all -nosystem -f \"" + Path + "\""))

def backup_all_with_system(self, event):
if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb backup -apk -shared -all -system -f \"" + Path + "\"\""))
else:
os.system(str("adb backup -apk -shared -all -system -f \"" + Path + "\""))

def backup_app_data_and_device_data(self, event):
if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb backup -all -f \"" + Path + "\"\""))
else:
os.system(str("adb backup -all -f \"" + Path + "\""))

def backup_apps(self, event):
if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb backup -apk -noshared -nosystem -f \"" + Path + "\"\""))
else:
os.system(str("adb backup -apk -noshared -nosystem -f \"" + Path + "\""))

def backup_storage(self, event):
if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb backup -noapk -shared -nosystem -f \"" + Path + "\"\""))
else:
os.system(str("adb backup -noapk -shared -nosystem -f \"" + Path + "\""))

def getBackupLocation(self, event):
backup_location = QtGui.QFileDialog.getOpenFileName(self, 'Open backup file', os.getcwd())
if self.password_popup():
self.progress_popup()
else:
return

if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb restore " + str(backup_location) + "\""))
else:
os.system(str("adb restore " + str(backup_location)))


def installSmsApp(self, event):
self.sms_popup()
if not self.useSystemAdbBinary:
os.system(str("gksudo \"./adb install smsBackupPlus/sms_backup_plus.apk\""))
os.system(str("gksudo \"./adb shell am start -n com.zegoggles.smssync/com.zegoggles.smssync.SmsSync\""))
else:
os.system(str("adb install smsBackupPlus/sms_backup_plus.apk"))
os.system(str("adb shell am start -n com.zegoggles.smssync/com.zegoggles.smssync.SmsSync"))

def openBrowseWindow(self, event):
# print "Browse window placeholder"
#dialog = QtGui.QFileDialog(self, 'Select: Shared Music Directory', os.getcwd())
#dialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)

directory = QtGui.QFileDialog.getExistingDirectory(self, 'Select backup directory')

Path = QtCore.QDir.toNativeSeparators(directory + "/backup.ab")
self.pathLabel.setText(directory)

def adbBinaryChange(self, event):
pass

def donateBtc(self, event):
webbrowser.open('donate.html')

def connectWirelessADB(self, event):
text, ok = QtGui.QInputDialog.getText(self, 'Connect to Wireless ADB', "If your device is set up for wireless ADB, connect to it here. Just type the location of the device in 'host:port' format.")
if ok:
os.system(str("./adb connect " + str(text)))

def initUI(self):
self.showDisclaimer()

# backup_location = QtGui.QFileDialog.getOpenFileName(self, 'Open backup file', os.getcwd())

self.useSystemAdbBinary = False

self.resize(300, 520)
self.center()
self.setFixedSize(300, 520)
self.setWindowTitle("Holo Backup")
self.bakLocation.setText(Path)


def main():
app = QtGui.QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()
Empty file added src/ui_files/__init__.py
Empty file.
Binary file added src/ui_files/__init__.pyc
Binary file not shown.
120 changes: 120 additions & 0 deletions src/ui_files/main_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'main_gui.ui'
#
# Created: Sun Feb 3 07:52:52 2013
# by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_mainWindow(object):
def setupUi(self, mainWindow):
mainWindow.setObjectName(_fromUtf8("mainWindow"))
mainWindow.resize(300, 520)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(mainWindow.sizePolicy().hasHeightForWidth())
mainWindow.setSizePolicy(sizePolicy)
mainWindow.setMinimumSize(QtCore.QSize(300, 520))
mainWindow.setMaximumSize(QtCore.QSize(300, 520))
self.label = QtGui.QLabel(mainWindow)
self.label.setGeometry(QtCore.QRect(10, 0, 151, 41))
self.label.setFrameShadow(QtGui.QFrame.Plain)
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(mainWindow)
self.label_2.setGeometry(QtCore.QRect(10, 35, 291, 21))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(mainWindow)
self.label_3.setGeometry(QtCore.QRect(50, 80, 201, 41))
self.label_3.setWordWrap(True)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_4 = QtGui.QLabel(mainWindow)
self.label_4.setGeometry(QtCore.QRect(20, 60, 261, 17))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.bakAllNoSys = QtGui.QPushButton(mainWindow)
self.bakAllNoSys.setGeometry(QtCore.QRect(25, 130, 251, 27))
self.bakAllNoSys.setObjectName(_fromUtf8("bakAllNoSys"))
self.bakAll = QtGui.QPushButton(mainWindow)
self.bakAll.setGeometry(QtCore.QRect(25, 165, 251, 27))
self.bakAll.setObjectName(_fromUtf8("bakAll"))
self.bakAppDevData = QtGui.QPushButton(mainWindow)
self.bakAppDevData.setGeometry(QtCore.QRect(25, 200, 251, 27))
self.bakAppDevData.setObjectName(_fromUtf8("bakAppDevData"))
self.bakStorSd = QtGui.QPushButton(mainWindow)
self.bakStorSd.setGeometry(QtCore.QRect(25, 270, 251, 27))
self.bakStorSd.setObjectName(_fromUtf8("bakStorSd"))
self.bakApp = QtGui.QPushButton(mainWindow)
self.bakApp.setGeometry(QtCore.QRect(25, 235, 251, 27))
self.bakApp.setObjectName(_fromUtf8("bakApp"))
self.line = QtGui.QFrame(mainWindow)
self.line.setGeometry(QtCore.QRect(25, 305, 251, 5))
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName(_fromUtf8("line"))
self.restoreBtn = QtGui.QPushButton(mainWindow)
self.restoreBtn.setGeometry(QtCore.QRect(25, 315, 251, 27))
self.restoreBtn.setObjectName(_fromUtf8("restoreBtn"))
self.smsBakRestore = QtGui.QPushButton(mainWindow)
self.smsBakRestore.setGeometry(QtCore.QRect(25, 360, 251, 27))
self.smsBakRestore.setObjectName(_fromUtf8("smsBakRestore"))
self.line_2 = QtGui.QFrame(mainWindow)
self.line_2.setGeometry(QtCore.QRect(25, 350, 251, 5))
self.line_2.setFrameShape(QtGui.QFrame.HLine)
self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
self.line_2.setObjectName(_fromUtf8("line_2"))
self.bakLocation = QtGui.QLineEdit(mainWindow)
self.bakLocation.setGeometry(QtCore.QRect(25, 395, 151, 27))
self.bakLocation.setObjectName(_fromUtf8("bakLocation"))
self.bakBrowseBtn = QtGui.QPushButton(mainWindow)
self.bakBrowseBtn.setGeometry(QtCore.QRect(180, 395, 98, 27))
self.bakBrowseBtn.setObjectName(_fromUtf8("bakBrowseBtn"))
self.donateLbl = QtGui.QLabel(mainWindow)
self.donateLbl.setGeometry(QtCore.QRect(30, 492, 241, 17))
self.donateLbl.setOpenExternalLinks(True)
self.donateLbl.setObjectName(_fromUtf8("donateLbl"))
self.wirelessAdb = QtGui.QPushButton(mainWindow)
self.wirelessAdb.setGeometry(QtCore.QRect(25, 430, 251, 27))
self.wirelessAdb.setObjectName(_fromUtf8("wirelessAdb"))
self.systemAdb = QtGui.QCheckBox(mainWindow)
self.systemAdb.setGeometry(QtCore.QRect(25, 465, 251, 22))
self.systemAdb.setObjectName(_fromUtf8("systemAdb"))

self.retranslateUi(mainWindow)
QtCore.QMetaObject.connectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):
mainWindow.setWindowTitle(_translate("mainWindow", "Holo Backup v2.0", None))
self.label.setText(_translate("mainWindow", "<html><head/><body><p><span style=\" font-size:18pt; color:#006a9f;\">Holo Backup</span></p></body></html>", None))
self.label_2.setText(_translate("mainWindow", "Backups only work on devices running 4.0+", None))
self.label_3.setText(_translate("mainWindow", "<html><head/><body><p align=\"center\">Backups can only be restored to the same device</p></body></html>", None))
self.label_4.setText(_translate("mainWindow", "Make sure USB Debugging is enabled!", None))
self.bakAllNoSys.setText(_translate("mainWindow", "Backup all without system apps", None))
self.bakAll.setText(_translate("mainWindow", "Backup all with system apps (unsafe)", None))
self.bakAppDevData.setText(_translate("mainWindow", "Backup app data and device data", None))
self.bakStorSd.setText(_translate("mainWindow", "Backup storage / SD card", None))
self.bakApp.setText(_translate("mainWindow", "Backup apps", None))
self.restoreBtn.setText(_translate("mainWindow", "Restore...", None))
self.smsBakRestore.setText(_translate("mainWindow", "SMS Backup / Restore", None))
self.bakLocation.setPlaceholderText(_translate("mainWindow", "Backup location", None))
self.bakBrowseBtn.setText(_translate("mainWindow", "Browse", None))
self.donateLbl.setText(_translate("mainWindow", "<html><head/><body><p><a href=\"donate.html\"><span style=\" text-decoration: underline; color:#0000ff;\">Feeling generous? Send me bitcoins!</span></a></p></body></html>", None))
self.wirelessAdb.setText(_translate("mainWindow", "Connect to wireless ADB", None))
self.systemAdb.setText(_translate("mainWindow", "Use system ADB binary? (No root)", None))

Binary file added src/ui_files/main_gui.pyc
Binary file not shown.
Loading