Okay so, i know this will never be truly portable but im just trying to get rid of as many system calls as possible. This program works as is, but the real guts of it could be done with a simple bash script. In particular i was wondering if anyone could give me a few pointers on any system("") call you see here that may have a better/faster/more secure C/C++ (). This small console program will be moved to a child wxwidgets interface on a larger p2p filesharing application myself and a few other linux nerds are working on called FileFly. This is very very pre-alpha.
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h> // not all of these headers are necessary but will be used
#include <sys/ioctl.h> // as system("") calls are replaced with the appropriate C ()'s
#include <fcntl.h>
#include <linux/cdrom.h>
using namespace std;
const double CLK_TCK = 1000.0;
/* For some odd reason CLK_TCK (included in time.h)
* needed to be assigned a value in ms(econds) here??
*/
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
int OpenTray()
{
int cdrom;
if ((cdrom = open("/dev/scd0",O_RDONLY | O_NONBLOCK)) < 0)
{
perror("open");
exit(1);
}
if (ioctl(cdrom,CDROMEJECT,0)<0)
{
perror("ioctl");
exit(1);
}
close(cdrom);
}
int CloseTray()
// Closes the tray, There is no comparable system("") call for this
{
int cdrom;
if ((cdrom = open("/dev/scd0",O_RDONLY | O_NONBLOCK)) < 0)
{
perror("open");
exit(1);
}
if (ioctl(cdrom,CDROMCLOSETRAY,0)<0)
{
perror("ioctl");
exit(1);
}
close(cdrom);
}
void pressEnter()
{
std::cin.clear();
std::cout << "\n\n\nPress Return to continue...\n";
std::cin.ignore(1,0);
}
class demon
{
public:
void haha();
void wtf();
};
class angel
{
public:
void deps();
void mmm();
};
void angel::mmm()
{
wait(1000);
// you will need to change /dev/sr0 to your appropriate dev alias. You can find it with dmesg | grep DVD
system ("echo 'Please enter the directory path containing the avi you wish to work on' && read dir && cd $dir && echo 'Enter the filename of the .avi (SomeName.avi)' && read target && cat $target > 1.avi && mencoder -o 2.avi -noidx -oac copy -ovc copy 1.avi && ffmpeg -i 2.avi -y -target ntsc-dvd -sameq -aspect 16:9 3.mpg && dvdauthor --title -o dvd -f 3.mpg && dvdauthor -o dvd -T && mkisofs -dvd-video -o dvd.iso dvd/");
wait(1000);
std::cout << "\nConversion complete.\n";
}
void demon::wtf()
//not necessary but useful for testing the CloseTray() and OpenTray() functions
{
int n;
for (n=8; n>0; n--)
{
wait (1000);
system("clear");
std::cout << " <-- Please Insert A Blank ~4gb Dvd-R/+/-\n" << n;
}
}
void demon::haha()
{
wait(1000);
system("clear");
//system("eject /dev/scd0");
std::cout << " <-- Please Insert A Blank ~4gb Dvd-R/+/-\n.";
wait(1000);
CloseTray();
std::cout << string(50, '\n');
std::cout << "\nPlease enter the directory path where you previously converted your avi\n";
system("read dir && cd $dir && growisofs -dvd-compat -Z /dev/scd0=dvd.iso");
wait(2000);
std::cout << "\nBurn Completed."; //successfully? need this in a string.
OpenTray();
}
int f,y;
int main()
{
y = 1;
do
{
f = 0;
std::cout << "=======================================================\n";
std::cout << "::: ::: ::: ::: ::::::::: :::::::: ::::::::::\n";
std::cout << ":+: :+: :+: :+: :+: :+: :+: :+: :+:\n";
std::cout << "+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+\n";
std::cout << "+#++:++ +#+ +:+ +#++:++#: +#++:++#++ +#++:++#\n";
std::cout << "+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+\n";
std::cout << "#+# #+# #+# #+# #+# #+# #+# #+# #+#\n";
std::cout << "### ### ######## ### ### ######## ##########\n";
std::cout << "=======================================================\n";
std::cout << " AVI TO DVD BOOTLEGGER\n";
std::cout << "\n";
std::cout << "Press (1) to author a DVD from an avi file\n";
std::cout << "Press (2) to burn authored DVD .iso\n";
std::cout << "Press (0) to exit\n" << "-->";
std::cin >> f;
switch(f)
{
case 1:
{
angel Convert;
std::cout << string(50, '\n');
Convert.mmm();
pressEnter();
std::cout << string(50, '\n');
}
break;
case 2:
{
int l = 10;
demon Burn;
std::cout << string(50, '\n');
OpenTray();
wait(500);
std::cout << l << " <-- Please Insert A Blank ~4gb Dvd-R/+/-\n";
wait(500);
std::cout << "9";
wait(1000);
system("clear");
Burn.wtf();
Burn.haha();
pressEnter();
std::cout << string(50, '\n');
}
case 0:
{
return 0;
}
break;
default:
break;
}
}
while (y = 1);
return 0;
}