Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search path #178

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
63 changes: 50 additions & 13 deletions src/gui/guimain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,67 @@ class GeometryMutator;
/// Set up search paths to our application directory for Qt's file search
/// mechanism.
///
/// This allows us to use "shaders:las_points.glsl" as a path to a shader
/// in the rest of the code, regardless of the system-specific details of how
/// This allows us to use "shaders:las_points.glsl" or "doc:userguide.html"
/// as a path to a shader/documentation in the rest of the code, regardless
/// of the system-specific details of how
/// the install directories are laid out.
static void setupQFileSearchPaths()
static void addSearchPath(const QString &prefix, const QString& searchPath, const QString& defaultPath)
{
QString installBinDir = QCoreApplication::applicationDirPath();
if (!installBinDir.endsWith("/bin"))
QString localSearchPath(searchPath);
// If path argument is not provided via command line then
// old behaviour - use DISPLAZ_SHADER_DIR or DISPLAZ_DOC_DIR
if (localSearchPath.isEmpty())
{
std::cerr << "WARNING: strange install location detected "
"- shaders will not be found\n";
QString installBinDir = QCoreApplication::applicationDirPath();

// It will fail everytime when the program is started via VC++ Ide
if (!installBinDir.endsWith("/bin"))
{
std::cerr << "WARNING: strange install location detected - "
<< prefix.toStdString()
<< " will not be found\n";
return;
}
QString installBaseDir = installBinDir;
installBaseDir.chop(4);
localSearchPath = QDir(installBaseDir).absoluteFilePath(defaultPath);
}
else // if path is provided via command line then
{
localSearchPath = QDir::fromNativeSeparators(localSearchPath);
// If path is relative, then it will be relative of application exe file,
// not its base path as in the old behaviour
if (QDir(localSearchPath).isRelative())
{
QDir sDir(QCoreApplication::applicationDirPath());
localSearchPath = sDir.absoluteFilePath(localSearchPath);
}
//If path is absolute then it will be used without changes
}
if (!QDir(localSearchPath).exists())
{
std::cerr << "WARNING: Path \""
<< localSearchPath.toStdString()
<< "\" does not exist - "
<< prefix.toStdString()
<< " will not be found\n";
return;
}
QString installBaseDir = installBinDir;
installBaseDir.chop(4);
QDir::addSearchPath("shaders", installBaseDir + "/" + DISPLAZ_SHADER_DIR);
QDir::addSearchPath("doc", installBaseDir + "/" + DISPLAZ_DOC_DIR);
QDir::addSearchPath(prefix, localSearchPath);
}




/// Run the main GUI window
int guimain(int argc, char* argv[])
{
std::string lockName;
std::string lockId;
std::string socketName;
std::string serverName;
std::string shadersDir;
std::string docsDir;

ArgParse::ArgParse ap;
ap.options(
Expand All @@ -54,6 +89,8 @@ int guimain(int argc, char* argv[])
"-instancelock %s %s", &lockName, &lockId, "Single instance lock name and ID to reacquire",
"-socketname %s", &socketName, "Local socket name for IPC",
"-server %s", &serverName, "DEBUG: Compute lock file and socket name; do not inherit lock",
"-shadersDir %s", &shadersDir, "Path to the shaders folder",
"-docsDir %s", &docsDir, "Path to the docs folder",
NULL
);

Expand All @@ -68,8 +105,8 @@ int guimain(int argc, char* argv[])
// Qt5: no longer required
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
#endif

setupQFileSearchPaths();
addSearchPath("shaders", QString::fromStdString(shadersDir), DISPLAZ_SHADER_DIR);
addSearchPath("doc", QString::fromStdString(docsDir), DISPLAZ_DOC_DIR);

Q_INIT_RESOURCE(resource);

Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ int main(int argc, char *argv[])
double viewRadius = -DBL_MAX;

std::string shaderName;
std::string shadersDir;
std::string docsDir;
std::string unloadRegex;
std::string viewLabelName;
bool noServer = false;
Expand Down Expand Up @@ -115,6 +117,8 @@ int main(int argc, char *argv[])
"-noserver", &noServer, "Don't attempt to open files in existing window",
"-server %s", &serverName, "Name of displaz instance to message on startup",
"-shader %s", &shaderName, "Name of shader file to load on startup",
"-shadersDir %s", &shadersDir, "Path to the shaders folder",
"-docsDir %s", &docsDir, "Path to the docs folder",
"-viewposition %F %F %F", &posX, &posY, &posZ, "Set absolute view position [X, Y, Z]",
"-viewradius %F", &viewRadius, "Set distance to view focus point",
"-viewlabel %s", &viewLabelName, "Set view on the first index to geometry that matches the given label",
Expand Down Expand Up @@ -212,6 +216,14 @@ int main(int argc, char *argv[])
<< "-instancelock" << QString::fromStdString(lockName)
<< QString::fromStdString(instanceLock.makeLockId())
<< "-socketname" << QString::fromStdString(socketName);
if(!shadersDir.empty())
{
args << "-shadersDir" << QString::fromStdString(shadersDir);
}
if (!docsDir.empty())
{
args << "-shadersDir" << QString::fromStdString(docsDir);
}
if (!QProcess::startDetached(exeName, args,
QDir::currentPath(), &guiPid))
{
Expand Down