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

View file

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

View file

@ -4,7 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "lc_file.h" #include "lc_file.h"
#include "str.h"
// ============================================================================= // =============================================================================
// lcFile // 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 // lcMemFile

View file

@ -32,9 +32,6 @@ public:
WriteBuffer(Buffer, strlen(Buffer)); 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 ReadBuffer(void* Buffer, long Bytes) = 0;
virtual size_t WriteBuffer(const void* Buffer, long Bytes) = 0; virtual size_t WriteBuffer(const void* Buffer, long Bytes) = 0;
virtual void CopyFrom(lcMemFile& Source) = 0; virtual void CopyFrom(lcMemFile& Source) = 0;

View file

@ -3,7 +3,6 @@
#include "lc_file.h" #include "lc_file.h"
#include "lc_math.h" #include "lc_math.h"
#include "str.h"
#include "object.h" #include "object.h"
#define LC_SEL_NO_PIECES 0x01 // No pieces in model #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(); 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]; lcProfileEntry& Entry = gProfileEntries[Key];
QSettings Settings; QSettings Settings;
static QByteArray Value;
LC_ASSERT(Entry.mType == LC_PROFILE_ENTRY_STRING); 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 Settings.value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Entry.mDefault.StringValue).toString();
return Value.data();
} }
void lcGetProfileBuffer(LC_PROFILE_KEY Key, lcMemFile& Buffer) 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); 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) void lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value)
{ {
lcProfileEntry& Entry = gProfileEntries[Key]; lcProfileEntry& Entry = gProfileEntries[Key];

View file

@ -99,12 +99,11 @@ void lcRemoveProfileKey(LC_PROFILE_KEY Key);
int lcGetProfileInt(LC_PROFILE_KEY Key); int lcGetProfileInt(LC_PROFILE_KEY Key);
float lcGetProfileFloat(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 lcGetProfileBuffer(LC_PROFILE_KEY Key, lcMemFile& Buffer);
void lcSetProfileInt(LC_PROFILE_KEY Key, int Value); void lcSetProfileInt(LC_PROFILE_KEY Key, int Value);
void lcSetProfileFloat(LC_PROFILE_KEY Key, float 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 lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value);
void lcSetProfileBuffer(LC_PROFILE_KEY Key, const lcMemFile& Buffer); void lcSetProfileBuffer(LC_PROFILE_KEY Key, const lcMemFile& Buffer);

View file

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

View file

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

View file

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