Example #1
0
/*
        This routine is platform-independent.

        MMEX is a portable application which means ability to to run
        without installation, for example, from USB flash drive.

        If mmex finds mmexini.db3 in its folder, it assumes portable
        mode and GetUserDir() in such case points to that folder.

        FIXME: security issue - temp files will be created on host filesystem.
*/
const wxFileName mmex::GetUserDir(bool create)
{
    static wxFileName fname;

    if (!fname.IsOk())
    {
        fname = getSettingsPathPortable();

        bool portable_file_ok = fname.IsFileWritable() && fname.IsFileReadable();

        if (!portable_file_ok)
        {
            fname.AssignDir(wxStandardPaths::Get().GetUserDataDir());

            if (create && !fname.DirExists())
            {
                portable_file_ok = fname.Mkdir(0700, wxPATH_MKDIR_FULL); // 0700 - octal, "111 000 000"
                wxASSERT(portable_file_ok);
            }
        }

        fname.SetFullName(wxGetEmptyString());
    }

    return fname;
}
Example #2
0
bool AmeJobMan::makeDirs(wxFileName f){
	wxFileName p = f.GetPath();
	if(f.DirExists())
		return true;
	if(!p.DirExists() && !makeDirs(p))
		return false;
	return f.Mkdir();
}
Example #3
0
bool Converter::MakeSureDirExists(wxFileName& path) {
  wxFileName parent(path);
  parent.RemoveLastDir();
  if (parent.GetDirCount() > 0 && !parent.DirExists()) {
    if (!MakeSureDirExists(parent)) {
      return false;
    }
  }
  if (!path.DirExists()) {
    return path.Mkdir();
  }
  return true;
}
Example #4
0
    // static helpers
    static const wxFileName& GetWatchDir()
    {
        static wxFileName dir;

        if (dir.DirExists())
            return dir;

        wxString tmp = wxStandardPaths::Get().GetTempDir();
        dir.AssignDir(tmp);

        // XXX look for more unique name? there is no function to generate
        // unique filename, the file always get created...
        dir.AppendDir("fswatcher_test");
        CPPUNIT_ASSERT(!dir.DirExists());
        CPPUNIT_ASSERT(dir.Mkdir());

        return dir;
    }
Example #5
0
void PHPWorkspaceView::DoAddFileWithContent(const wxTreeItemId& folderId,
                                            const wxFileName& filename,
                                            const wxString& content)
{
    // file can only be added to a folder
    ItemData* data = DoGetItemData(folderId);
    if(!data || !data->IsFolder()) {
        return;
    }

    if(filename.FileExists()) {
        // a file with this name already exists
        wxMessageBox(_("A file with same name already exists!"), wxT("CodeLite"), wxOK | wxCENTER | wxICON_WARNING);
        return;
    }

    FileExtManager::FileType type = FileExtManager::GetType(filename.GetFullName());

    // Create the file
    const wxString __EOL__ = EditorConfigST::Get()->GetOptions()->GetEOLAsString();

    // Make sure that the path exists
    filename.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);

    wxFFile fp;
    if(fp.Open(filename.GetFullPath(), wxT("w+"))) {

        // if its is a PHP file, write the php tag at to the top of the file
        if(type == FileExtManager::TypePhp) {
            fp.Write(wxString() << "<?php " << __EOL__ << __EOL__ << content);
        }
        fp.Close();
    }

    // add the new file
    wxString project_name = DoGetSelectedProject();
    wxString folder_name = data->GetFolderPath();

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project_name);
    CHECK_PTR_RET(pProject);

    PHPFolder::Ptr_t pFolder = pProject->Folder(folder_name);
    CHECK_PTR_RET(pFolder);

    if(PHPWorkspace::Get()->AddFile(project_name, folder_name, filename.GetFullPath())) {
        wxArrayString filesToAdd;
        filesToAdd.Add(filename.GetFullPath());
        DoAddFilesToTreeView(folderId, pProject, pFolder, filesToAdd);
    }

    // Open the newly added file
    m_mgr->OpenFile(filename.GetFullPath());

    IEditor* editor = m_mgr->GetActiveEditor();
    if(editor) {
        editor->SetCaretAt(editor->GetLength());
    }

    // Notify plugins about new files was added to workspace
    wxArrayString files;
    files.Add(filename.GetFullPath());

    // Notify the plugins
    clCommandEvent evtFilesAdded(wxEVT_PROJ_FILE_ADDED);
    evtFilesAdded.SetStrings(files);
    EventNotifier::Get()->AddPendingEvent(evtFilesAdded);
}