Skip to content

Commit

Permalink
Clean up command line options for backup and include example backup s…
Browse files Browse the repository at this point in the history
…cript.
  • Loading branch information
Brian Hill committed Nov 5, 2016
1 parent 70d1cdb commit a00e8b0
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 88 deletions.
Binary file modified SimpleBackup
Binary file not shown.
9 changes: 9 additions & 0 deletions backup_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
#Modify these values to your folder paths
appDir="/boot/system/apps/SimpleBackup"
backupDir="/boot/backups"

#Run the backup and quit
$appDir/SimpleBackup home_backup_settings $backupDir/home$(date +%Y-%m-%d).zip&
sleep 5s
$appDir/SimpleBackup -q
97 changes: 46 additions & 51 deletions src/SBApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,42 @@
#include "SBApp.h"

int main()
{ SBApp myApp;
{
SBApp myApp;
myApp.Run();
return(0);
}
void SBApp::printhelp()
{ printf( "SimpleBackup v%s by Brian Hill\n"
"Usage: SimpleBackup [settings_file] [backup_file]\n"
"If settings_file is specified, settings will be restored from\n"
"that previously configured and saved settings file.\n"
"If backup_file is specified (must follow a settings_file\n"
"arguement) saving of the backup into backup_file is started\n"
"automatically\n",SB_version);
return;
}
SBApp::SBApp() :BApplication(APPLICATION_SIGNATURE), ready_to_run(false)


SBApp::SBApp()
:BApplication(APPLICATION_SIGNATURE)
{
aWindow = new SBWindow(BRect(200,50,850,570));
}
SBApp::~SBApp()
{ }
void SBApp::ReadyToRun()
{ //aWindow->Show();
ready_to_run = true;
fWindow = new SBWindow(BRect(200,50,850,570));
}
void SBApp::ArgvReceived(int32 argc, char** argv)
{ if(strcmp(argv[1],"-q")==0 || strcmp(argv[1],"--quit")==0)


void
SBApp::ArgvReceived(int32 argc, char** argv)
{
if(strcmp(argv[1],"-q")==0 || strcmp(argv[1],"--quit")==0)
{ be_app->PostMessage(B_QUIT_REQUESTED); return; }
if(strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0)
{ printhelp(); return; }
if(argc!=2 && argc!=3) { printhelp(); return; }
BPath settingsPath;
find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath);
settingsPath.Append(DEFAULT_SETTINGS_DIR);
BString backupString;
BEntry settingsEntry(argv[1]);
if(!settingsEntry.Exists())
{ settingsPath.Append(argv[1]);
settingsEntry.SetTo(settingsPath.Path());
if(!settingsEntry.Exists())
{ printf("Error: Could not find settings file %s\n"
"Using settings from last session.\n",argv[1]);
return;
}
}
//aWindow->UpdateIfNeeded();//?????
entry_ref settingsRef; //Send message to restore settings
settingsEntry.GetRef(&settingsRef);
if(argc == 2){//only restore settings
BMessage *setmsg = new BMessage(RESTORES_REF);
setmsg->AddRef("refs",&settingsRef);
aWindow->PostMessage(setmsg);
delete setmsg;

//only restore settings
if(argc == 2)
{
BString fileString(argv[1]);
BMessage setmsg(RESTORES_FILENAME);
setmsg.AddString("filename", fileString);
fWindow->PostMessage(&setmsg);
}
else if(argc==3)//send message to start backup
{ BEntry backupEntry(argv[2]);
//send message to start backup
else if(argc==3)
{
BString fileString(argv[1]);
BEntry backupEntry(argv[2]);
bool newBackup = !(backupEntry.Exists());
char backupName[B_FILE_NAME_LENGTH];
backupEntry.GetName(backupName);
Expand All @@ -70,11 +51,25 @@ void SBApp::ArgvReceived(int32 argc, char** argv)
}
entry_ref backupRef;
backupEntry.GetRef(&backupRef);
BMessage *savemsg = new BMessage(NEW_BACKUP);
savemsg->AddRef("settings_ref",&settingsRef);
savemsg->AddRef("directory",&backupRef);
savemsg->AddString("name",backupName);
savemsg->AddBool("newBackup",newBackup);
aWindow->PostMessage(savemsg);
BMessage savemsg(NEW_BACKUP);
savemsg.AddString("filename", fileString);
savemsg.AddRef("directory",&backupRef);
savemsg.AddString("name",backupName);
savemsg.AddBool("newBackup",newBackup);
fWindow->PostMessage(&savemsg);
}
}


void SBApp::printhelp()
{
printf( "SimpleBackup v%s by Brian Hill\n"
"Usage: SimpleBackup [settings_file] [backup_file]\n"
"If settings_file is specified, settings will be restored from "
"that previously configured and saved settings file. "
"If backup_file is specified (must follow a settings_file "
"arguement) saving of the backup into backup_file is started "
"automatically\n",SB_version);
return;
}

10 changes: 4 additions & 6 deletions src/SBApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
#include "SBWindow.h"

class SBApp : public BApplication
{public:
{
public:
SBApp();
~SBApp();
virtual void ReadyToRun();
virtual void ArgvReceived(int32,char**);
void printhelp();
private:
SBWindow *aWindow;
bool ready_to_run;
SBWindow *fWindow;
void printhelp();
};

#endif
4 changes: 2 additions & 2 deletions src/SBControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SBControls : public BView
SBControls(BRect&,/* BPicture* = NULL, BPicture* = NULL,*/ SBSettings* = NULL);
~SBControls();
// virtual void FrameResized(float,float);
char* getSrc() { return (char*)backupSrc->Text(); }
void setSrc(char* src) { backupSrc->SetText(src); return; }
const char* getSrc() { return backupSrc->Text(); }
void setSrc(const char* src) { backupSrc->SetText(src); return; }
// void setToggleB(bool a) { togglePB->SetValue(a); }
// float getBottom() { return aboutB->Frame().bottom; }
private:
Expand Down
5 changes: 2 additions & 3 deletions src/SBSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,9 @@ void SBSettings::storeSettings(BMessage &archive)
}
return;
}
bool SBSettings::restoreSettingsRef(BMessage *msg){
bool SBSettings::restoreSettingsRef(entry_ref srcRef)
{
bool success = false;
entry_ref srcRef;
msg->FindRef("refs", &srcRef);
BEntry srcEntry(&srcRef, true);
BFile srcFile(&srcEntry, B_READ_ONLY);
off_t datasize;
Expand Down
2 changes: 1 addition & 1 deletion src/SBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SBSettings : public BView
bool getIncludeEntrys(BPath&);
int getZipSplitBytes();
void storeSettings(BMessage&);
bool restoreSettingsRef(BMessage*);
bool restoreSettingsRef(entry_ref srcRef);
void restoreSettings(BMessage&);
SBControls *parent;
private:
Expand Down
Loading

0 comments on commit a00e8b0

Please sign in to comment.