1
0
Fork 0
mirror of https://gitlab.com/Syping/gta5view-cmd synced 2024-06-01 02:37:35 +02:00
gta5view-cmd/main.cpp

138 lines
5.6 KiB
C++
Raw Normal View History

2017-03-04 19:36:47 +01:00
/*****************************************************************************
* gta5view-cmd - gta5view Command Line
* Copyright (C) 2017 Syping
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "SnapmaticPicture.h"
#include <QCoreApplication>
2017-08-29 15:23:14 +02:00
#include <QDateTime>
2017-03-04 19:36:47 +01:00
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QStringList args = a.arguments();
2017-08-29 15:23:14 +02:00
if (args.length() >= 3)
2017-03-04 19:36:47 +01:00
{
2017-08-29 15:23:14 +02:00
bool convertToGTA = true;
bool customFormat = false;
if (args.length() == 4)
2017-03-04 19:36:47 +01:00
{
2017-08-29 15:23:14 +02:00
if (args.at(3) == "-pgta")
2017-03-04 19:36:47 +01:00
{
2017-08-29 15:23:14 +02:00
convertToGTA = true;
customFormat = false;
}
else if (args.at(3) == "-g5e")
{
convertToGTA = true;
customFormat = true;
}
}
if (!convertToGTA)
{
SnapmaticPicture picture(args.at(1));
if (picture.readingPicture(true, false, true))
{
if (!picture.exportPicture(args.at(2), "JPG"))
{
cout << "gta5view-cmd: Exporting of " << args.at(1).toStdString().c_str() << " to " << args.at(2).toStdString().c_str() << " failed!" << endl;
return 1;
}
}
else
{
cout << "gta5view-cmd: Reading of " << args.at(1).toStdString().c_str() << " failed!" << endl;
2017-03-04 19:36:47 +01:00
return 1;
}
}
else
{
2017-08-29 15:23:14 +02:00
SnapmaticPicture picture(":/template.g5e");
if (picture.readingPicture(true, false, true))
{
QImage image(args.at(1));
if (!image.isNull())
{
QSize snapmaticRes(960, 536);
if (image.size() != snapmaticRes) image = image.scaled(snapmaticRes, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
if (picture.setImage(image))
{
picture.setPictureTitle("Converted Picture");
SnapmaticProperties pictureSP = picture.getSnapmaticProperties();
pictureSP.uid = QString(QTime::currentTime().toString("HHmmss") +
QString("0") +
QString::number(QDate::currentDate().dayOfYear())).toInt();
pictureSP.createdDateTime = QDateTime::currentDateTime();
pictureSP.createdTimestamp = pictureSP.createdDateTime.toTime_t();
picture.setSnapmaticProperties(pictureSP);
picture.setPicFileName(QString("PGTA5%1").arg(QString::number(pictureSP.uid)));
QString filePath = args.at(2);
filePath.replace("<autodef>", picture.getPictureFileName());
if (!customFormat)
{
if (!picture.exportPicture(filePath, "PGTA"))
{
cout << "gta5view-cmd: Converting of " << args.at(1).toStdString().c_str() << " to " << args.at(2).toStdString().c_str() << " failed!" << endl;
return 1;
}
}
else
{
if (!picture.exportPicture(filePath, "G5E"))
{
cout << "gta5view-cmd: Converting of " << args.at(1).toStdString().c_str() << " to " << args.at(2).toStdString().c_str() << " failed!" << endl;
return 1;
}
}
}
else
{
cout << "gta5view-cmd: Editing of Snapmatic Image Stream failed!" << endl;
return 1;
}
}
else
{
cout << "gta5view-cmd: Reading of " << args.at(1).toStdString().c_str() << " failed!" << endl;
return 1;
}
}
else
{
cout << "gta5view-cmd: Reading of internal template failed!" << endl;
return 1;
}
2017-03-04 19:36:47 +01:00
}
}
else
{
2017-08-29 15:23:14 +02:00
cout << "gta5view Command Line" << endl << endl;
cout << "Usage: " << args.at(0).toStdString().c_str() << " source target -format" << endl;
if (args.at(1) == "--help")
{
cout << "Convert-only: <autodef> (Auto Filename at Convert)" << endl;
cout << "Formats: jpg pgta g5e" << endl;
}
2017-03-04 19:36:47 +01:00
return 255;
}
2017-03-04 19:41:31 +01:00
return 0;
2017-03-04 19:36:47 +01:00
}