Example #1
0
bool wxExFile::FileSave(const wxExFileName& filename)
{
  bool save_as = false;

  if (filename.IsOk())
  {
    Assign(filename);
    MakeAbsolute();
    save_as = true;
  }

  if (!save_as && !m_IsLoaded)
  {
    wxLogStatus("File has not been loaded");
    return false;
  }

  if (m_OpenFile && !Open(m_FileName.GetFullPath(), wxFile::write))
  {
    return false;
  }

  DoFileSave(save_as);

  Close();

  ResetContentsChanged();
  
  m_FileName.m_Stat.Sync();
  m_Stat.Sync();

  return true;
}
Example #2
0
//--------------------------------------------------------------------------------
void CIwASDFileDataAttr::Group::BrowseForFile(wxString& fileName)
{
    wxFileName temp(MakeAbsolute(fileName));

    wxString root=L"";
    if (m_Parent->m_File->m_Paths[0]->GetRoot()!=NULL)
        root=m_Parent->m_File->m_Paths[0]->GetRoot()->c_str().Lower();

    root.Replace(L"\\",L"/");

    wxString prompt=L"Please choose a file to load...";
    while (true)
    {
        wxFileDialog dlg(NULL,prompt,temp.GetPath(),temp.GetFullName(),L"All files (*.*)|*.*",wxOPEN);

        if (dlg.ShowModal()!=wxID_OK)
            return;

        wxString name=dlg.GetPath().Lower();
        if (name.StartsWith(root))
        {
            fileName=name.Mid(root.size());
            return;
        }

        prompt=L"Please choose a file under the current project directory...";
    }
}
Example #3
0
//--------------------------------------------------------------------------------
CIwAttrMember* CIwASDFileDataAttr::Group::TryGetMember(const wxString& name,CIwAttrInstance* inst)
{
    int i;
    for (i=0; i<(int)inst->m_Class->m_Members.size(); i++)
    {
        if ((inst->m_Class->m_Members[i]->m_Type&ATTRMEMBER_MASK)==ATTRMEMBER_RESOURCE)
            break;
    }
    if (i==(int)inst->m_Class->m_Members.size())
        return NULL;

    wxString name2=MakeAbsolute(name);
    if (!wxFileExists(name2))
        return NULL;

    return inst->m_Class->m_Members[i];
}
// In case dir does not exist, it will search for the first valid top directory
std::string GetFirstValidDir(const std::string &dir)
{
    if ((dir[0] == '/') && (dir.length() == 1))
        return dir; // Root dir given

    std::string subdir = dir;
    
    if (!subdir.compare(0, 2, "~/"))
    {
        const char *env = getenv("HOME");
        if (env)
            subdir.replace(0, 1, env);
    }
    
    MakeAbsolute(subdir);
    
    if (ReadAccess(subdir))
        return subdir;
    
    // Remove trailing /
    if (subdir[subdir.length()-1] == '/')
        subdir.erase(subdir.length()-1, 1);
    
    TSTLStrSize pos;
    do
    {
        pos = subdir.rfind('/');
        assert(pos != std::string::npos);
        
        if (pos == std::string::npos)
        {
            // Shouldn't happen
            return subdir;
        }
        else if (pos == 0) // Reached the root dir('/')
            return "/";
        
        subdir.erase(pos);
    }
    while (!ReadAccess(subdir));
    
    return subdir;
}
void MKDirRec(std::string dir)
{
    MakeAbsolute(dir);

    TSTLStrSize start = 1; // Skip first root path
    TSTLStrSize end = 0;
    
    do
    {
        end = dir.find("/", start);
        std::string subdir = dir.substr(0, end);

        if (subdir.empty())
            break;       
        
        if (!FileExists(subdir))
            MKDir(subdir, (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH));
        
        start = end + 1;
    }
    while (end != std::string::npos);
}
Example #6
0
void t4p::ApacheClass::ParseApacheConfigFile(const wxString& includedFile) {
    if (wxFileExists(includedFile)) {
        wxTextFile file;
        if (file.Open(includedFile)) {
            bool inVirtualHost = false;

            // this flag will be used to skip directives inside a conditional
            // directive. we want to skip this to avoid getting confused when
            // a config has an SSL binding hidden behind a conditional
            bool skipParsing = false;
            wxString currentServerName,
                     currentDocumentRoot,
                     currentPort;
            for (wxString line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
                // apache directives are case insensitive, but file names are not
                // so we need 2 variables for this ...
                line = line.Trim(false).Trim(true);
                wxString lineLower = line.Lower();

                if (0 == lineLower.Find(wxT("<ifmodule"))) {
                    skipParsing = true;
                }
                if (0 == lineLower.Find(wxT("</ifmodule>"))) {
                    skipParsing = false;
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("<virtualhost"))) {
                    currentServerName = wxT("");
                    currentDocumentRoot = wxT("");
                    currentPort = wxT("");
                    inVirtualHost = true;

                    // handle the virtual host port
                    size_t colonPos = lineLower.find_last_of(wxT(":"));
                    if (colonPos != std::string::npos) {
                        size_t endPos = lineLower.find_first_of(wxT(">"), colonPos);
                        if (endPos != std::string::npos) {
                            wxString portString = lineLower.Mid(colonPos + 1, endPos - colonPos - 1);
                            portString.Trim();
                            long portLong = 0;
                            bool parsed = portString.ToLong(&portLong);

                            // dont use port on default HTTP port; makes URLs 'prettier'
                            if (parsed && portLong <= 65535 && portLong != 80) {
                                currentPort = portString;
                            }
                        }
                    }
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("</virtualhost>"))) {
                    currentServerName = wxT("");
                    currentDocumentRoot = wxT("");
                    inVirtualHost = false;
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("serverroot"))) {
                    ServerRoot = line.Mid(10).Trim(false).Trim(true);  // 10= length of 'ServerRoot'

                    // trim any quotes that the path may have
                    ServerRoot.Replace(wxT("\""), wxT(""));
                    ServerRoot.Replace(wxT("'"), wxT(""));
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("include "))) {
                    wxString nextFile = line.Mid(8).Trim(false).Trim(true);  // 8= length of 'Include'
                    nextFile = MakeAbsolute(nextFile);
                    ParseApacheConfigFile(nextFile);
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("servername"))) {
                    // must get the line that has not been modified to lowercase
                    currentServerName = line.Mid(10).Trim(false).Trim(true);  // 10=length of "ServerName"
                    if (inVirtualHost && !currentPort.IsEmpty()) {
                        // append the port information; sometimes virtual hosts have their own port
                        currentServerName.Append(wxT(":")).Append(currentPort);
                    }
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("documentroot"))) {
                    currentDocumentRoot = line.Mid(12).Trim(false).Trim(true);  // 12=length of "DocumentRoot"
                    currentDocumentRoot.Replace(wxT("\""), wxT(""));
                    currentDocumentRoot.Replace(wxT("'"), wxT(""));
                }
                if (!skipParsing && 0 == lineLower.Find(wxT("listen"))) {
                    currentPort = line.Mid(6).Trim(false).Trim(true);  // 6=length of "listen"

                    // handle listen 127.0.0.1:8080
                    // hadle listen 8080
                    if (currentPort.Contains(wxT(":"))) {
                        currentPort = currentPort.AfterLast(wxT(':'));
                    }
                    Port = 0;
                    long portLong;
                    bool parsed = currentPort.ToLong(&portLong);
                    if (parsed && portLong <= 65535) {
                        Port = portLong;
                    }
                }
                if (!currentDocumentRoot.IsEmpty() && !inVirtualHost) {
                    // this is the case for the server document root (outside a virtual host tag)
                    currentServerName = wxT("localhost");
                    SetVirtualHostMapping(currentDocumentRoot, currentServerName);
                    currentServerName = wxT("");
                    currentDocumentRoot = wxT("");
                    currentPort = wxT("");
                } else if (inVirtualHost && !currentDocumentRoot.IsEmpty() && !currentServerName.IsEmpty()) {
                    SetVirtualHostMapping(currentDocumentRoot, currentServerName);
                    currentServerName = wxT("");
                    currentDocumentRoot = wxT("");
                    currentPort = wxT("");
                }
            }
        }
    } else if (includedFile.Contains(wxT("*"))) {
        // wxIsWild(wxT("C:\\*.conf")) returns false, maybe it doesn't do wilcards in windows??
        wxFileName fileName(includedFile);
        if (fileName.IsOk()) {
            // ATTN: careful, in windows we need the volume in case the executable
            // is in a different drive than the config file
            wxString dirString = fileName.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME);
            wxString wildCard = fileName.GetFullName();
            wxDir dir;
            if (wxFileName::IsDirReadable(dirString) && dir.Open(dirString)) {
                wxString file;
                if (dir.GetFirst(&file, wildCard)) {
                    ParseApacheConfigFile(dirString + file);
                    while (dir.GetNext(&file)) {
                        ParseApacheConfigFile(dirString + file);
                    }
                }
            }
        }
    } else if (wxDirExists(includedFile)) {
        wxDir dir;
        if (wxFileName::IsDirReadable(includedFile) && dir.Open(includedFile)) {
            wxString file;
            wxString newConfigDir = includedFile + wxFileName::GetPathSeparator();
            if (dir.GetFirst(&file)) {
                ParseApacheConfigFile(newConfigDir + file);
                while (dir.GetNext(&file)) {
                    ParseApacheConfigFile(newConfigDir + file);
                }
            }
        }
    }
}
Example #7
0
bool wxExFile::FileLoad(const wxExFileName& filename)
{
  Assign(filename);
  return m_FileName.FileExists() && MakeAbsolute() && Get(false);
}