Example #1
0
OovString const Project::getDocDirectory()
    {
    FilePath path(getBinDirectory(), FP_Dir);
#ifdef __linux__
    if(isDevelopment())
        {
        path.appendDir("../../web");
        }
    else
        {
        size_t pos = path.find("bin");
        if(pos != std::string::npos)
            {
            path.replace(pos, 3, "share/oovaide/doc");
            }
        OovStatus status(true, SC_File);
        if(!FileIsDirOnDisk(path, status))
            {
            path.setPath("/usr/share/oovaide/doc", FP_Dir);
            }
        }
#else
    // During development, the path is ../../web, but let it find the web below.
    path.appendDir("../web");
#endif
    OovStatus status(true, SC_File);
    if(!FileIsDirOnDisk(path, status))
        {
        path.setPath("http://oovaide.sourceforge.net", FP_Dir);
        }
    return path;
    }
Example #2
0
void FileWaitForDirDeleted(OovStringRef const path, int waitMs)
{
#ifndef __linux__
    int minWait = 100;
    int count = waitMs / minWait;
    bool deleted = false;
    bool success = true;
    for(int tries=0; tries<count && success; tries++)
    {
        if(!FileIsDirOnDisk(path, success))
        {
            deleted = true;
            break;
        }
        else
        {
            sleepMs(minWait);
        }
    }
    if(!success || !deleted)
    {
        OovString str = "Unable to delete directory: ";
        str += path;
        OovError::report(ET_Error, str);
    }
#endif
}
Example #3
0
OovString const Project::getDataDirectory()
    {
    FilePath path(getBinDirectory(), FP_Dir);
#ifdef __linux__
    if(isDevelopment())
        {
        path.appendDir("data");
        }
    else
        {
        size_t pos = path.find("bin");
        if(pos != std::string::npos)
            {
            path.replace(pos, 3, "share/oovaide/data");
            }
        OovStatus status(true, SC_File);
        if(!FileIsDirOnDisk(path, status))
            {
            path.setPath("/usr/share/oovaide/data", FP_Dir);
            }
        }
#else
    path.appendDir("data");
#endif
    return path;
    }
Example #4
0
static bool isDevelopment()
    {
    static enum eDevel { Uninit, Devel, Deploy } devel;
    if(devel == Uninit)
        {
        OovString path = Project::getBinDirectory();
        size_t pos = path.find("bin");
        if(pos != std::string::npos)
            {
            path.replace(pos, 3, "lib");
            }
        OovStatus status(true, SC_File);
        if(FileIsDirOnDisk(path, status))
            {
            devel = Deploy;
            }
        else
            {
            devel = Devel;
            }
        if(status.needReport())
            {
            status.reported();
            }
        }
    return(devel == Devel);
    }
Example #5
0
OovStatusReturn FileWaitForDirDeleted(OovStringRef const path, int waitMs)
    {
    OovStatus status(true, SC_File);
#ifndef __linux__
    int minWait = 100;
    int count = waitMs / minWait;
    bool deleted = false;
    for(int tries=0; tries<count && status.ok(); tries++)
        {
        if(!FileIsDirOnDisk(path, status))
            {
            deleted = true;
            break;
            }
        else
            {
            sleepMs(minWait);
            }
        }
    if(status.ok() && !deleted)
        {
        status.set(false, SC_Time);
        }
    if(status.needReport())
        {
        OovString str = "Unable to delete directory: ";
        str += path;
        OovError::report(ET_Error, str);
        }
#endif
    return status;
    }
Example #6
0
void ProjectPackagesDialog::winSetEnableScanning()
    {
    bool success = true;
    bool missing = !FileIsDirOnDisk(getEntry("PackageRootDirEntry"), success);
    Gui::setEnabled(GTK_LABEL(Builder::getBuilder()->getWidget(
            "MissingDirectoryLabel")), missing);
    Gui::setEnabled(GTK_BUTTON(Builder::getBuilder()->getWidget(
            "ScanDirectoriesButton")), missing);
    }
Example #7
0
bool ProjectPackagesDialog::winCheckDirectoryOk()
    {
    bool success = true;
    bool missing = !FileIsDirOnDisk(getEntry("PackageRootDirEntry"), success);
    if(missing)
        {
        Gui::messageBox("The root directory is not correct");
        }
    return(!missing);
    }
Example #8
0
OovStatusReturn FileEnsurePathExists(OovStringRef const path)
    {
    OovStatus status(true, SC_File);
    FilePath fullPath(path, FP_Dir);
    FilePath existingPath = fullPath;

    if(fullPath.find('~') == std::string::npos)
        {
        // Walk up the tree to find a base that exists.
        size_t pos = existingPath.getPosEndDir();
        while(pos != 0 && pos != std::string::npos)
            {
            existingPath.discardTail(pos);
            OovStatus ignoredStatus(true, SC_File);
            if(existingPath.isDirOnDisk(ignoredStatus))
                break;
            else
                pos = existingPath.getPosLeftPathSep(pos, RP_RetPosFailure);
            }
        if(pos == std::string::npos)
            {
            pos = 0;
            }
        while(pos != std::string::npos && status.ok())
            {
            pos = findPathSep(fullPath, pos);
            if(pos != std::string::npos)
                {
                OovString partPathStr = fullPath;
                partPathStr.resize(pos);
                if(!FileIsDirOnDisk(partPathStr, status))
                    {
                    status = FileMakeSubDir(partPathStr);
                    }
                pos++;
                }
            }
        }
    else
        {
        status.set(false, SC_Logic);
        }
    return status;
    }
Example #9
0
bool FileEnsurePathExists(OovStringRef const path)
{
    bool success = true;

    // Walk up the tree to find a base that exists.
    FilePath fp(path, FP_File);
    size_t pos = fp.getPosEndDir();
    while(pos != 0)
    {
        fp.discardTail(pos);
        bool ignoredSuccess = true;
        if(fp.isDirOnDisk(ignoredSuccess))
            break;
        else
            pos = fp.getPosLeftPathSep(pos, RP_RetPosFailure);
    }
    while(pos != std::string::npos && pos != 0 && success)
    {
        pos = findPathSep(path, pos);
        if(pos != std::string::npos)
        {
            OovString partPath = path;
            partPath.resize(pos);
            if(!FileIsDirOnDisk(partPath, success))
            {
#ifdef __linux__
                success = (mkdir(partPath.getStr(), 0x1FF) == 0);       // 0777
#else
                success = (_mkdir(partPath.getStr()) == 0);
#endif
            }
            pos++;
        }
    }
    return success;
}
bool ProjectSettingsDialog::runDialog()
    {
    GtkEntry *projDirEntry = GTK_ENTRY(Builder::getBuilder()->getWidget(
            "OovaideProjectDirEntry"));
    GtkTextView *excDirsTextView = GTK_TEXT_VIEW(Builder::getBuilder()->getWidget(
            "ExcludeDirsTextview"));
    GtkEntry *srcDirEntry = GTK_ENTRY(Builder::getBuilder()->getWidget(
            "RootSourceDirEntry"));

    OovString origSourceDir = Project::getSourceRootDirectory();
    if(mEditStyle == PS_NewProject)
        {
        Gui::clear(projDirEntry);
        Gui::clear(srcDirEntry);
        Gui::clear(excDirsTextView);
        }
    else
        {
        Gui::setText(projDirEntry, Project::getProjectDirectory());
        Gui::setText(srcDirEntry, Project::getSourceRootDirectory());
        CompoundValue excDirs(mProjectOptions.getValue(OptProjectExcludeDirs), ';');
        Gui::setText(excDirsTextView, excDirs.getAsString('\n'));
        }

    bool editSrc = (mEditStyle == PS_NewProject ||
        mEditStyle == PS_OpenProjectEditSource);
    Gui::setEnabled(srcDirEntry, editSrc);
    Gui::setEnabled(GTK_BUTTON(Builder::getBuilder()->getWidget(
            "RootSourceDirButton")), editSrc);
    Gui::setEnabled(GTK_BUTTON(Builder::getBuilder()->getWidget(
            "OovaideProjectDirButton")), mEditStyle == PS_NewProject);
    Gui::setEnabled(projDirEntry, mEditStyle == PS_NewProject);

    bool ok = run(true);
    if(ok)
        {
        OovStatus status(true, SC_File);
        if(!FileIsDirOnDisk(getRootSrcDir(), status))
            {
            ok = Gui::messageBox("The source directory does not exist. "
                "Do you want to create it?", GTK_MESSAGE_QUESTION,
                GTK_BUTTONS_YES_NO);
            if(ok)
                {
                FilePath dir(getRootSrcDir(), FP_Dir);
                status = FileEnsurePathExists(dir);
                }
            }
        if(status.needReport())
            {
            ok = false;
            status.report(ET_Error, "Unable to access directory");
            }
        }
    if(ok)
        {
        mExcludeDirs.parseString(Gui::getText(excDirsTextView), '\n');
        mExcludeDirs.deleteEmptyStrings();
        Project::setSourceRootDirectory(getRootSrcDir());

        // Update the project options.
        if(mEditStyle == PS_NewProject)
            {
            // The project dir is used by setDefaultOptions.
            OovString projectDir = getProjectDir();
            Project::setProjectDirectory(projectDir);
            FilePathEnsureLastPathSep(projectDir);
            OovStatus status = FileEnsurePathExists(projectDir);
            OptionsDefaults optionDefaults(getProjectOptions());
            optionDefaults.setDefaultOptions();
            sProjectSettingsDialog->getGuiOptions().setDefaultOptions();
            }
        FilePath rootSrcText(getRootSrcDir(), FP_Dir);
        getProjectOptions().setNameValue(OptSourceRootDir, rootSrcText);
        }
    return ok;
    }