Skip to content

Commit

Permalink
New command line options and small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Ebner authored and Christoph Ebner committed Jun 15, 2015
1 parent 440f142 commit 798f819
Show file tree
Hide file tree
Showing 45 changed files with 6,798 additions and 440 deletions.
51 changes: 51 additions & 0 deletions DestinationFolderSetting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* DestinationFolderSetting.cpp
*
* Created on: 02.06.2015
* Author: Christoph
*/

#include "DestinationFolderSetting.h"
#include "UserInterface.h"

DestinationFolderSetting::DestinationFolderSetting(UserInterface const& ui)
: FolderSetting(ui, "destination", "Where to save processed movies",
"Please enter the path where poisonconvert should save processed movies "
"(if you leave the optoin empty, processed movies stay in their source directory).",
"Destination equals source")
{
}

DestinationFolderSetting::~DestinationFolderSetting()
{
}

DestinationFolderSetting::PARAM_CHANGE_RETURN DestinationFolderSetting::checkParam(string const& new_param,
bool ui_output)
{
if (new_param.empty() || "Destination equals source")
{
if (ui_output)
{
ui_.writeString("The video will not be moved after processing has finished.", true);
}
return PARAM_CHANGE_SUCCESS;
}
else
{
return FolderSetting::checkParam(new_param, ui_output);
}
}

void DestinationFolderSetting::changeParam(string const& new_param)
//We can assume that new_param is either y or n since checkParam was called before ...
{
if (new_param.empty())
{
settings_param_ = "Destination equals source";
}
else
{
settings_param_ = new_param;
}
}
23 changes: 23 additions & 0 deletions DestinationFolderSetting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* DestinationFolderSetting.h
*
* Created on: 02.06.2015
* Author: Christoph
*/

#ifndef DESTINATIONFOLDERSETTING_H_
#define DESTINATIONFOLDERSETTING_H_

#include "FolderSetting.h"

class DestinationFolderSetting: public FolderSetting {
public:
DestinationFolderSetting(UserInterface const& ui);
virtual ~DestinationFolderSetting();

private:
virtual PARAM_CHANGE_RETURN checkParam(string const& new_param, bool ui_output);
void changeParam(string const& new_param);
};

#endif /* DESTINATIONFOLDERSETTING_H_ */
23 changes: 14 additions & 9 deletions FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "FileWriteException.h"
#include "VectorSourceManager.h"
#include "AnalyzeMedia.h"
#include "SettingsMode.h"
#include "Settings.h"
#include <sstream>
#include <vector>
Expand Down Expand Up @@ -54,9 +55,11 @@ int FileManager::readSettings() throw(FileReadException,

num_settings = setting_.getVectorLen();
//Head
readfile.open("/opt/etc/PoisonConvert_Settings"); // /opt/etc/Settings
readfile.open("/etc/PoisonConvert_Settings");
if (readfile.is_open() == false)
{
throw OpenFileException();
}
getline(readfile, tmp_string, '\n');
ReadFileError(readfile);
if (tmp_string != "-----Settings-----")
Expand All @@ -68,15 +71,17 @@ int FileManager::readSettings() throw(FileReadException,
for(unsigned int i=0; i<num_settings; i++)
{
getline(readfile, tmp_string, ' ');

ReadFileError(readfile);
if (tmp_string != setting_.getSettingsName(i))
{
readfile.close();
throw FileReadException();
}
getline(readfile, tmp_setting, '\n');

ReadFileError(readfile);
if (setting_.writeParam(tmp_setting, i) == -1)
if (setting_.writeParam(tmp_setting, SettingsMode::SETTING_SPECIFIER(i), false) == Settings::PARAM_CHANGE_ERROR)
{
throw FileReadException();
}
Expand Down Expand Up @@ -107,7 +112,7 @@ void FileManager::saveSettingsToFile() throw(FileWriteException)

num_settings = setting_.getVectorLen();

writefile.open("/opt/etc/PoisonConvert_Settings", ostream::out);
writefile.open("/etc/PoisonConvert_Settings", ostream::out);
if (writefile.is_open() == false)
{
writefile.close();
Expand Down Expand Up @@ -142,7 +147,7 @@ void FileManager::ReadFileError(ifstream& readfile) throw(FileReadException)
int FileManager::savePreferencesToFile() throw(FileWriteException)
{
ofstream writefile;
string filename = setting_.getSettingsParam(CONFIGNAME);
string filename = setting_.getSettingsParam(SettingsMode::CONFIGNAME);
string config_file;
unsigned int identifier = 0;

Expand Down Expand Up @@ -193,7 +198,7 @@ int FileManager::savePreferencesToFile() throw(FileWriteException)

string FileManager::checkPathToConfig()
{
string config_file = setting_.getSettingsParam(CONFIGLOC);
string config_file = setting_.getSettingsParam(SettingsMode::CONFIGLOC);

return config_file;
}
Expand Down Expand Up @@ -224,8 +229,8 @@ void FileManager::readPreferences() throw (FileReadException, OpenFileException)
{
ifstream readfile;
string tmp_string;
string filename = setting_.getSettingsParam(CONFIGNAME);
string config_file = setting_.getSettingsParam(CONFIGLOC);
string filename = setting_.getSettingsParam(SettingsMode::CONFIGNAME);
string config_file = setting_.getSettingsParam(SettingsMode::CONFIGLOC);

config_file.append(filename);

Expand Down Expand Up @@ -410,7 +415,7 @@ void FileManager::readImportantFiles(vector<string>& filenames) throw (FileReadE
ifstream readfile;
string tmp_filename = "start";

readfile.open("/opt/tmp/poisonXfileslist");
readfile.open("/tmp/poisonXfileslist");
if (readfile.is_open() == false)
{
readfile.close();
Expand All @@ -432,7 +437,7 @@ void FileManager::readProperties(string filename, string& duration) throw (FileR
string outter_bitrate;
string params[5] = {"poison"};

readfile.open("/opt/tmp/poisonXprobelist");
readfile.open("/tmp/poisonXprobelist");
if (readfile.is_open() == false)
{
readfile.close();
Expand Down
7 changes: 4 additions & 3 deletions FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ class FileManager {
virtual ~FileManager();

int readSettings() throw (FileReadException, OpenFileException);

void saveSettingsToFile() throw(FileWriteException);

void readPreferences() throw (FileReadException, OpenFileException);
int savePreferencesToFile() throw(FileWriteException);
string checkPathToConfig();
int savePreferencesToFile() throw(FileWriteException);

string checkPathToConfig();
void readImportantFiles(vector<string>& filenames) throw (FileReadException,
OpenFileException);
void readProperties(string filename, string& duration) throw (FileReadException, OpenFileException);
Expand Down
55 changes: 55 additions & 0 deletions FileSetting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright 2014 CutePoisonX ([email protected])
//
// This file is part of PoisonConvert.
//
// PoisonConvert is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PoisonConvert 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. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PoisonConvert. If not, see <http://www.gnu.org/licenses/>.
//

#include "FileSetting.h"

#include "UserInterface.h"

FileSetting::FileSetting(UserInterface ui, string name, string description,
string settings_change_prompt, string default_param,
string error_promp_str)
: Settings(ui, name, description, settings_change_prompt, default_param),
error_promp_str_(error_promp_str)
{
}

FileSetting::FileSetting(const Settings& orig)
: Settings(orig)
{
}

FileSetting::~FileSetting()
{
}

FileSetting::PARAM_CHANGE_RETURN FileSetting::checkParam(string const& new_param, bool ui_output)
//note: this method does not check whether a file actually exists, but
//only if the string provided by "new_param" is non-empty!
{
if(new_param.empty())
{
if (ui_output)
{
ui_.writeString(error_promp_str_, true);
}
return PARAM_CHANGE_ERROR;
}

return PARAM_CHANGE_SUCCESS;
}
44 changes: 44 additions & 0 deletions FileSetting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2014 CutePoisonX ([email protected])
//
// This file is part of PoisonConvert.
//
// PoisonConvert is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PoisonConvert 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. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PoisonConvert. If not, see <http://www.gnu.org/licenses/>.
//

#ifndef FILESETTING_H
#define FILESETTING_H

#include "Settings.h"
#include <string>

class UserInterface;
using namespace std;

class FileSetting : public Settings {
public:
FileSetting(UserInterface ui, string name, string description,
string settings_change_prompt, string default_param,
string error_promp_str);
FileSetting(const Settings& orig);
virtual ~FileSetting();

protected:
virtual PARAM_CHANGE_RETURN checkParam(string const& new_param, bool ui_output);

string error_promp_str_;

};

#endif /* FILESETTING_H */
62 changes: 15 additions & 47 deletions FolderSetting.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include "FolderSetting.h"
#include "UserInterface.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <cstdlib>
#include <dirent.h>

FolderSetting::FolderSetting(UserInterface ui, string name, string description,
string settings_change_prompt, string default_param)
Expand All @@ -38,64 +40,30 @@ FolderSetting::~FolderSetting()
{
}

const int FolderSetting::checkParam(string new_param)
FolderSetting::PARAM_CHANGE_RETURN FolderSetting::checkParam(string const& new_param, bool ui_output)
{
size_t position = new_param.find_last_of("/");
struct stat folder_check;

if (stat(new_param.c_str(), &folder_check) == 0 && S_ISDIR(folder_check.st_mode))
if (stat(new_param.c_str(), &folder_check) != 0 || S_ISDIR(folder_check.st_mode) == false)
{
if( position != new_param.length() -1)
if (ui_output)
{
new_param.append("/");
ui_.writeString("Please enter a valid path or 'exit' to abort!", true);
}
settings_param_ = new_param;
} else if (new_param == "exit")
{
return -2;
} else
{
ui_.writeString("Please enter a valid path or 'exit' to abort!", true);
return -1;
return PARAM_CHANGE_ERROR;
}

return 0;
return PARAM_CHANGE_SUCCESS;
}

const string FolderSetting::setParam()
void FolderSetting::changeParam(string const& new_param)
{
string new_param;
int errorcase = 0;
ui_.writeString(settings_change_prompt_, true, "green");
do
{
new_param = ui_.readString();
errorcase = checkParam(new_param);
} while (errorcase != 0 && errorcase != -2);
if(errorcase == 0)
{
ui_.writeString("Saved.", true, "green");
ui_.readString(false);
}

return settings_param_;
}
string new_writable_param = new_param;
size_t position = new_writable_param.find_last_of("/");

const int FolderSetting::writeParam(string new_param)
{
string check_param_first = "[ -d \"/";
string check_param_sec = "\" ]";

check_param_first.append(new_param);
check_param_first.append(check_param_sec);

if (system(check_param_first.c_str()) == -1)
if (position != new_writable_param.length() - 1)
{
return -1;
} else
{
settings_param_ = new_param;
new_writable_param.append("/");
}
return 0;

settings_param_ = new_writable_param;
}
Loading

0 comments on commit 798f819

Please sign in to comment.