String cleanup.

This commit is contained in:
leo 2015-01-31 21:44:57 +00:00
parent df7afb956a
commit e456b05ebf
10 changed files with 44 additions and 113 deletions

View file

@ -120,11 +120,10 @@ bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* LibraryIn
return mLibrary->Load(EnvPath, LibraryCachePath);
}
char CustomPath[LC_MAXPATH];
strcpy(CustomPath, lcGetProfileString(LC_PROFILE_PARTS_LIBRARY));
QString CustomPath = lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
if (CustomPath[0])
return mLibrary->Load(CustomPath, LibraryCachePath);
if (!CustomPath.isEmpty())
return mLibrary->Load(CustomPath.toLatin1().constData(), LibraryCachePath); // todo: qstring
if (LibraryInstallPath && LibraryInstallPath[0])
{
@ -425,11 +424,11 @@ void lcApplication::ShowPreferencesDialog()
Options.Preferences = mPreferences;
strcpy(Options.DefaultAuthor, lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME));
strcpy(Options.ProjectsPath, lcGetProfileString(LC_PROFILE_PROJECTS_PATH));
strcpy(Options.LibraryPath, lcGetProfileString(LC_PROFILE_PARTS_LIBRARY));
strcpy(Options.POVRayPath, lcGetProfileString(LC_PROFILE_POVRAY_PATH));
strcpy(Options.LGEOPath, lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH));
Options.DefaultAuthor = lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME);
Options.ProjectsPath = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
Options.LibraryPath = lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
Options.POVRayPath = lcGetProfileString(LC_PROFILE_POVRAY_PATH);
Options.LGEOPath = lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH);
Options.CheckForUpdates = lcGetProfileInt(LC_PROFILE_CHECK_UPDATES);
Options.AASamples = CurrentAASamples;
@ -445,7 +444,7 @@ void lcApplication::ShowPreferencesDialog()
if (!gMainWindow->DoDialog(LC_DIALOG_PREFERENCES, &Options))
return;
bool LibraryChanged = strcmp(Options.LibraryPath, lcGetProfileString(LC_PROFILE_PARTS_LIBRARY));
bool LibraryChanged = Options.LibraryPath != lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
bool AAChanged = CurrentAASamples != Options.AASamples;
mPreferences = Options.Preferences;

View file

@ -55,9 +55,9 @@ struct lcHTMLDialogOptions
struct lcPOVRayDialogOptions
{
char FileName[LC_MAXPATH];
char POVRayPath[LC_MAXPATH];
char LGEOPath[LC_MAXPATH];
QString FileName;
QString POVRayPath;
QString LGEOPath;
bool Render;
};
@ -93,11 +93,11 @@ struct lcPreferencesDialogOptions
{
lcPreferences Preferences;
char DefaultAuthor[101];
char ProjectsPath[LC_MAXPATH];
char LibraryPath[LC_MAXPATH];
char POVRayPath[LC_MAXPATH];
char LGEOPath[LC_MAXPATH];
QString DefaultAuthor;
QString ProjectsPath;
QString LibraryPath;
QString POVRayPath;
QString LGEOPath;
int CheckForUpdates;
int AASamples;

View file

@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include "lc_file.h"
#include "str.h"
// =============================================================================
// lcFile
@ -17,21 +16,6 @@ lcFile::~lcFile()
{
}
void lcFile::ReadString(String& Value)
{
lcuint32 Length;
ReadU32(&Length, 1);
ReadBuffer(Value.GetBuffer(Length + 1), Length);
((char*)Value)[Length] = 0;
}
void lcFile::WriteString(const String& Value)
{
lcuint32 Length = Value.GetLength();
WriteU32(Length);
WriteBuffer((const char*)Value, Length);
}
// =============================================================================
// lcMemFile

View file

@ -32,9 +32,6 @@ public:
WriteBuffer(Buffer, strlen(Buffer));
}
void ReadString(String& Value);
void WriteString(const String& Value);
virtual size_t ReadBuffer(void* Buffer, long Bytes) = 0;
virtual size_t WriteBuffer(const void* Buffer, long Bytes) = 0;
virtual void CopyFrom(lcMemFile& Source) = 0;

View file

@ -3,7 +3,6 @@
#include "lc_file.h"
#include "lc_math.h"
#include "str.h"
#include "object.h"
#define LC_SEL_NO_PIECES 0x01 // No pieces in model

View file

@ -132,17 +132,14 @@ float lcGetProfileFloat(LC_PROFILE_KEY Key)
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.FloatValue).toFloat();
}
const char* lcGetProfileString(LC_PROFILE_KEY Key)
QString lcGetProfileString(LC_PROFILE_KEY Key)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
static QByteArray Value;
LC_ASSERT(Entry.mType == LC_PROFILE_ENTRY_STRING);
Value = Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.StringValue).toString().toLocal8Bit();
return Value.data();
return Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.StringValue).toString();
}
void lcGetProfileBuffer(LC_PROFILE_KEY Key, lcMemFile& Buffer)
@ -181,16 +178,6 @@ void lcSetProfileFloat(LC_PROFILE_KEY Key, float Value)
Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Value);
}
void lcSetProfileString(LC_PROFILE_KEY Key, const char* Value)
{
lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings;
LC_ASSERT(Entry.mType == LC_PROFILE_ENTRY_STRING);
Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), QString::fromUtf8(Value));
}
void lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value)
{
lcProfileEntry& Entry = gProfileEntries[Key];

View file

@ -99,12 +99,11 @@ void lcRemoveProfileKey(LC_PROFILE_KEY Key);
int lcGetProfileInt(LC_PROFILE_KEY Key);
float lcGetProfileFloat(LC_PROFILE_KEY Key);
const char* lcGetProfileString(LC_PROFILE_KEY Key);
QString lcGetProfileString(LC_PROFILE_KEY Key);
void lcGetProfileBuffer(LC_PROFILE_KEY Key, lcMemFile& Buffer);
void lcSetProfileInt(LC_PROFILE_KEY Key, int Value);
void lcSetProfileFloat(LC_PROFILE_KEY Key, float Value);
void lcSetProfileString(LC_PROFILE_KEY Key, const char* Value); // todo: qstring
void lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value);
void lcSetProfileBuffer(LC_PROFILE_KEY Key, const lcMemFile& Buffer);

View file

@ -1252,9 +1252,8 @@ void Project::ExportPOVRay()
lcPOVRayDialogOptions Options;
memset(Options.FileName, 0, sizeof(Options.FileName));
strcpy(Options.POVRayPath, lcGetProfileString(LC_PROFILE_POVRAY_PATH));
strcpy(Options.LGEOPath, lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH));
Options.POVRayPath = lcGetProfileString(LC_PROFILE_POVRAY_PATH);
Options.LGEOPath = lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH);
Options.Render = lcGetProfileInt(LC_PROFILE_POVRAY_RENDER);
if (!gMainWindow->DoDialog(LC_DIALOG_EXPORT_POVRAY, &Options))
@ -1266,7 +1265,7 @@ void Project::ExportPOVRay()
lcDiskFile POVFile;
if (!POVFile.Open(Options.FileName, "wt"))
if (!POVFile.Open(Options.FileName.toLatin1().constData(), "wt")) // todo: qstring
{
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(Options.FileName));
return;
@ -1302,27 +1301,15 @@ void Project::ExportPOVRay()
LGEO_COLOR_GLITTER = 0x40
};
char LGEOPath[LC_MAXPATH];
strcpy(LGEOPath, lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH));
if (LGEOPath[0])
if (!Options.LGEOPath.isEmpty())
{
lcDiskFile TableFile, ColorFile;
char Filename[LC_MAXPATH];
int Length = strlen(LGEOPath);
if ((LGEOPath[Length - 1] != '\\') && (LGEOPath[Length - 1] != '/'))
strcat(LGEOPath, "/");
strcpy(Filename, LGEOPath);
strcat(Filename, "lg_elements.lst");
if (!TableFile.Open(Filename, "rt"))
if (!TableFile.Open(QFileInfo(QDir(Options.LGEOPath), QLatin1String("lg_elements.lst")).absoluteFilePath().toLatin1().constData(), "rt"))
{
delete[] PieceTable;
delete[] PieceFlags;
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(LGEOPath));
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(Options.LGEOPath));
return;
}
@ -1360,14 +1347,11 @@ void Project::ExportPOVRay()
PieceFlags[Index] |= LGEO_PIECE_SLOPE;
}
strcpy(Filename, LGEOPath);
strcat(Filename, "lg_colors.lst");
if (!ColorFile.Open(Filename, "rt"))
if (!ColorFile.Open(QFileInfo(QDir(Options.LGEOPath), QLatin1String("lg_colors.lst")).absoluteFilePath().toLatin1().constData(), "rt"))
{
delete[] PieceTable;
delete[] PieceFlags;
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(LGEOPath));
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Could not find LGEO files in folder '%1'.").arg(Options.LGEOPath));
return;
}
@ -1392,7 +1376,7 @@ void Project::ExportPOVRay()
const char* OldLocale = setlocale(LC_NUMERIC, "C");
if (LGEOPath[0])
if (!Options.LGEOPath.isEmpty())
{
POVFile.WriteLine("#include \"lg_defs.inc\"\n#include \"lg_color.inc\"\n\n");
@ -1522,31 +1506,18 @@ void Project::ExportPOVRay()
if (Options.Render)
{
QStringList Arguments;
char Argument[LC_MAXPATH + 32];
sprintf(Argument, "+I%s", Options.FileName);
Arguments.append(Argument);
Arguments.append(QString::fromLatin1("+I%1").arg(Options.FileName));
if (Options.LGEOPath[0])
if (!Options.LGEOPath.isEmpty())
{
sprintf(Argument, "+L%slg/", Options.LGEOPath);
Arguments.append(Argument);
sprintf(Argument, "+L%sar/", Options.LGEOPath);
Arguments.append(Argument);
Arguments.append(QString::fromLatin1("+L%1lg/").arg(Options.LGEOPath));
Arguments.append(QString::fromLatin1("+L%1ar/").arg(Options.LGEOPath));
}
sprintf(Argument, "+o%s", Options.FileName);
char* Slash1 = strrchr(Argument, '\\');
char* Slash2 = strrchr(Argument, '/');
if (Slash1 || Slash2)
{
if (Slash1 > Slash2)
*(Slash1 + 1) = 0;
else
*(Slash2 + 1) = 0;
Arguments.append(Argument);
}
QString AbsolutePath = QFileInfo(Options.FileName).absolutePath();
if (!AbsolutePath.isEmpty())
Arguments.append(QString::fromLatin1("+o%1").arg(AbsolutePath));
QProcess::execute(Options.POVRayPath, Arguments);
}

View file

@ -32,14 +32,9 @@ void lcQPOVRayDialog::accept()
return;
}
strcpy(options->FileName, fileName.toLocal8Bit().data());
QString povrayPath = ui->povrayEdit->text();
strcpy(options->POVRayPath, povrayPath.toLocal8Bit().data());
QString lgeoPath = ui->lgeoEdit->text();
strcpy(options->LGEOPath, lgeoPath.toLocal8Bit().data());
options->FileName = fileName;
options->POVRayPath = ui->povrayEdit->text();
options->LGEOPath = ui->lgeoEdit->text();
options->Render = ui->render->isChecked();
QDialog::accept();

View file

@ -83,11 +83,11 @@ void lcQPreferencesDialog::accept()
return;
}
strcpy(options->DefaultAuthor, ui->authorName->text().toLocal8Bit().data());
strcpy(options->ProjectsPath, ui->projectsFolder->text().toLocal8Bit().data());
strcpy(options->LibraryPath, ui->partsLibrary->text().toLocal8Bit().data());
strcpy(options->POVRayPath, ui->povrayExecutable->text().toLocal8Bit().data());
strcpy(options->LGEOPath, ui->lgeoPath->text().toLocal8Bit().data());
options->DefaultAuthor = ui->authorName->text();
options->ProjectsPath = ui->projectsFolder->text();
options->LibraryPath = ui->partsLibrary->text();
options->POVRayPath = ui->povrayExecutable->text();
options->LGEOPath = ui->lgeoPath->text();
options->Preferences.mMouseSensitivity = ui->mouseSensitivity->value();
options->CheckForUpdates = ui->checkForUpdates->currentIndex();
options->Preferences.mFixedAxes = ui->fixedDirectionKeys->isChecked();