Пример #1
0
bool Config::loadConfigFile()
{
	std::string dirPath;
#ifndef _DEBUG
	dirPath = getExecutablePath();
#else
	dirPath = getCurrentDirectory();
#endif
	
	// if we have an env variable set for this, use that...
	const char* smPathEnv = getenv("SITEMON_PATH");
	if (smPathEnv && strlen(smPathEnv) > 0)
	{
		dirPath.assign(smPathEnv);
	}
	
	if (dirPath.substr(dirPath.size() - 1, 1) != "/")
	{
		dirPath += "/";
	}
	
	std::string finalPath = dirPath;
	
	// try XML config file first...
	if (loadXMLConfigFile(finalPath + "sm_config.xml"))
	{
		return true;
	}
	
	return false;
}
Пример #2
0
  //----------------------------------------------------------------------------
  void Win32Scanner::getFiles( tStringList & files )
  {
    WIN32_FIND_DATA file;
    HANDLE hSearch;
    DWORD dwAttrs;
    bool done = false;

    hSearch = ::FindFirstFile( string( getCurrentDirectory() + "\\*.mp3" ).c_str(), &file );
    if( hSearch != INVALID_HANDLE_VALUE )
    {
      while( ! done )
      {
        dwAttrs = ::GetFileAttributes( file.cFileName );
        if(    !(dwAttrs & FILE_ATTRIBUTE_SYSTEM)
            && !(dwAttrs & FILE_ATTRIBUTE_DIRECTORY)
        ) {
          files.push_back( file.cFileName );
        }

        if( ! ::FindNextFile( hSearch, &file ) )
        {
          if( ::GetLastError() == ERROR_NO_MORE_FILES )
          {
            done = true;
          }
          else
          {
            error( getEnvironment(), "Couldn't find next file." );
          }
        }
      }
    }

    static_cast<void>( ! ::FindClose( hSearch ) );
  }
Пример #3
0
	bool init(int nCmdShow)
	{
		TCHAR * const cmdlineStr = GetCommandLine();;
		CommandLineParser cmdline;
		cmdline.parse(cmdlineStr);

		if(HWND hwnd = AppWindow::findWindowByWindowName(cmdline.getWindowName())){
			AppWindow::sendCommandLine(hwnd, getCurrentDirectory(), cmdlineStr);//カレントディレクトリも送らないとコマンドラインを正しく解釈できない。
			return false;
		}

		window_.reset(new AppWindow(cmdline.getWindowName()));
		if(!window_->create()){
			return false;
		}

		window_->setAlbum(cmdline.getAlbum());

		if(!window_->restoreWindowPlacement()){
			window_->showWindow(nCmdShow);
		}
		window_->updateWindow();

		return true;
	}
Пример #4
0
std::string CrossPlatform::findFalltergeistDataPath()
{
    if (_falltergeistDataPath.length() > 0)
        return _falltergeistDataPath;
    Logger::info() << "Looking for Falltergeist data files" << std::endl;
    std::vector<std::string> directories;
    directories.push_back(getCurrentDirectory());
    directories.push_back(getDataPath());

    for (auto &directory : directories)
    {
        std::ifstream stream(directory + "/data/dialogs.lst");
        if (stream)
        {
            Logger::info() << "Searching in directory: " << directory << " data/dialogs.lst [FOUND]" << std::endl;
            _falltergeistDataPath = directory;
            return _falltergeistDataPath;
        }
        else
        {
            Logger::info() << "Searching in directory: " << directory << " data/dialogs.lst [NOT FOUND]" << std::endl;
        }
    }

    throw Exception("Falltergeist data files are not found!");
}
Пример #5
0
void CDlgController::OpenPath(const std::wstring& wstrPath, const std::wstring& wstrFileType)
{
	m_wstrPath=wstrPath;
	m_wstrFileType=wstrFileType;
	m_ListBoxFolder.RemoveAllItems();
	//|{"+wstrFileType+L"}";
	CDir dir;
	if(dir.ReadDir(m_wstrPath)==false)
	{
		m_wstrPath=getCurrentDirectory();
		dir.ReadDir(m_wstrPath);
	}
	for (int i=0; i<dir.m_FileInfo.size(); i++)
	{
		if (dir.m_FileInfo[i].IsDirectory())
		{
			m_ListBoxFolder.AddItem((L'\\'+dir.m_FileInfo[i].wstrFilename).c_str());
		}
	}
	for (int i=0; i<dir.m_FileInfo.size(); i++)
	{
		if (!dir.m_FileInfo[i].IsDirectory())
		{
			if (wstrFileType.find(GetExtension(dir.m_FileInfo[i].wstrFilename))!=std::wstring::npos)
			{
				m_ListBoxFolder.AddItem(dir.m_FileInfo[i].wstrFilename.c_str());
			}
		}

	}
}
Пример #6
0
// Given a directory remove the files located within it and then the directory itself
void removeDirectory(std::string directory) {
	std::string CWD = getCurrentDirectory();
	directory = CWD + DIR_SEPARATOR + directory;

	WIN32_FIND_DATA data;
	HANDLE h = FindFirstFile((directory + DIR_SEPARATOR + "*").c_str(), &data);
	if (h != NULL) {
		SetFileAttributes(directory.c_str(), FILE_ATTRIBUTE_NORMAL);
		FindNextFile(h, &data); // ..
		FindNextFile(h, &data); // .
		do {
			std::string filename = directory + DIR_SEPARATOR + data.cFileName;
			if (!SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_NORMAL)) {
				logEvent(ERROR,filename + ": " + ConvertLastErrorToString());
			}
			int result = _unlink(filename.c_str());
			if (result != 0) {
				logEvent(ERROR, filename + ": " + ConvertLastErrorToString());
			}
		} while (FindNextFile(h,&data));
		FindClose(h);
	}
	_rmdir(directory.c_str());

}
Пример #7
0
std::vector<std::string> ResourceManager::getNormalizedClassPathVector() const
{
  std::string basepath = FileUtils::getExecutablePath();
  std::string curdirmodifier = getCurrentDirectory(); //getProperty(string(ResourceManager::KEY_CURRENTDIR));
  if (FileUtils::isAbsolute(curdirmodifier)){
    basepath = curdirmodifier;
  	DEBUG("DEBUG: (absolut) Basepath is : " + basepath);
  } else {
    basepath = FileUtils::concFile(basepath, curdirmodifier);
  	DEBUG("DEBUG: (not absolut) Basepath is : " + basepath);
  }

  std::string cp = getProperty(string(ResourceManager::KEY_CLASSPATH));
  vector<string>cps = StringUtils::split(cp, ";", "", false);
  for (int i=0; i<cps.size(); i++)
    {
      string lib = cps[i];
      DEBUG("ClassPath element is " + basepath + " + " +cps[i]);

      cps[i] = FileUtils::concFile(basepath, cps[i]);
      DEBUG("ClassPath element " + StringUtils::toString(i)+ "=" + cps[i]);
    }

  return cps;
}
Пример #8
0
ExecutableInfo::ExecutableInfo()
	: verbose(false) 
	, miMode(false)
	, silent(false)
	, stopOnEntry(false)
{
	setDir(getCurrentDirectory());
}
Пример #9
0
static int _testBuildAbsolutePathNullFile(void) {
  CharString d = getCurrentDirectory();
  CharString out = newCharString();

  buildAbsolutePath(d, NULL, NULL, out);
  assert(charStringIsEmpty(out));

  freeCharString(d);
  freeCharString(out);
  return 0;
}
Пример #10
0
      void
      TIFF::writeCurrentDirectory()
      {
        Sentry sentry;

        static const std::string software("OME Files (C++) " OME_FILES_VERSION_MAJOR_S "." OME_FILES_VERSION_MINOR_S "." OME_FILES_VERSION_PATCH_S);
        getCurrentDirectory()->getField(SOFTWARE).set(software);

        if (!TIFFWriteDirectory(impl->tiff))
          sentry.error("Failed to write current directory");
      }
Пример #11
0
bool MWindow::getOpenMultipleFiles(const char * title, const char * filter, string * repertory, list <string> * filesList)
{
	const char * currentDir = getCurrentDirectory();
	setActive(false);

	static char filename[65536];
	OPENFILENAME fn;

	memset(&fn, 0, sizeof(fn));
	strcpy(filename, "");

	fn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
	fn.lStructSize	= sizeof(fn);
	fn.lpstrFilter	= filter;
	fn.lpstrFile	= filename;
	fn.nMaxFile		= 65536*4;
	fn.lpstrTitle	= title;
	fn.hwndOwner    = m_hWnd;
	filename[0]		= NULL;

	if(GetOpenFileName(&fn))
	{
		setCurrentDirectory(currentDir);

		if(fn.nFileOffset < lstrlen(filename))
		{
			char rep[256];
			getRepertory(rep, filename);
			getLocalFilename(filename, rep, filename);
			(*repertory) = rep;
			filesList->push_back(filename);
		}
		else
		{
			char filePath[256];
			strcpy(filePath, filename);
			filePath[fn.nFileOffset] = 0;
			(*repertory) = filePath;

			while(filename[fn.nFileOffset] != 0)
			{
				char Message[256];
				strcpy(Message, filename+fn.nFileOffset);
				filesList->push_back(Message);
				fn.nFileOffset += (strlen(filename+fn.nFileOffset) + 1);
			}
		}
		setActive(true);
		return true;
	}

	setActive(true);
	return false;
}
Пример #12
0
char *getcwd(char *buf, size_t size)
{
    /* Copy our current working directory. */
    memcpy(buf, **getCurrentDirectory(), size);

    /* Set errno. */
    errno = ESUCCESS;

    /* All done. */
    return buf;
}
Пример #13
0
  //----------------------------------------------------------------------------
  void Win32Scanner::getDirectories( tStringList & directories )
  {
    WIN32_FIND_DATA file;
    HANDLE hSearch;
    DWORD dwAttrs;
    bool done = false;

    hSearch = ::FindFirstFile( string( getCurrentDirectory() + "\\*" ).c_str(), &file );
    if( hSearch != INVALID_HANDLE_VALUE )
    {
      while( ! done )
      {
        dwAttrs = ::GetFileAttributes( file.cFileName );
        if(    !(dwAttrs & FILE_ATTRIBUTE_SYSTEM)
            &&  (dwAttrs & FILE_ATTRIBUTE_DIRECTORY)
            && strcmp( file.cFileName, "." )
            && strcmp( file.cFileName, ".." )
        ) {
          // Not neccessary to check the current directory.
          // We are in!
          const string dir = getCurrentDirectory() + "\\" + file.cFileName;
          directories.push_back( dir );
        }

        if( ! ::FindNextFile( hSearch, &file ) )
        {
          if( ::GetLastError() == ERROR_NO_MORE_FILES )
          {
            done = true;
          }
          else
          {
            error( getEnvironment(), "Couldn't find next file." );
          }
        }
      }
    }

    static_cast<void>( ::FindClose( hSearch ) );
  }
Пример #14
0
void FileLocator::addPath(const char* newPathBegin,const char* newPathEnd)
	{
	/* Check if the path is fully-qualified: */
	if(newPathEnd-newPathBegin>1&&newPathBegin[0]=='/')
		pathList.push_back(cleanPath(newPathBegin,newPathEnd));
	else if(newPathEnd-newPathBegin>0)
		{
		/* Prefix relative paths with the current working directory: */
		std::string absPath=getCurrentDirectory();
		absPath.push_back('/');
		absPath.append(newPathBegin,newPathEnd);
		pathList.push_back(cleanPath(absPath.c_str()));
		}
	}
Пример #15
0
CString Utils::SelectDirectory(const CString& strCaption)
{
    CFolderDialog dlg(strCaption, getCurrentDirectory());

	CString strFolderPath;

    if( dlg.DoModal() == IDOK  )
    {	
        strFolderPath = dlg.GetFolderPath();
		strFolderPath += "\\";
    }	

	return strFolderPath;
}
Пример #16
0
void FileLocator::addPathFromFile(const char* fileName)
	{
	/* Find the final '/': */
	const char* slashPtr=findLastOf(fileName,'/');
	if(slashPtr!=0)
		{
		/* Add the file's directory to the search path list: */
		addPath(fileName,slashPtr);
		}
	else
		{
		/* Add the current directory to the search path list: */
		pathList.push_back(getCurrentDirectory());
		}
	}
Пример #17
0
bool Utils::OpenBmpDialog(CString& strFile, const CString& strDirectory)
{
	std::vector<CString> filter;

	filter.push_back(Utils::GetString(IDS_FILTER_BMP_FILE));
	filter.push_back("*.bmp");

	if (exists(strDirectory))
	{
		return OpenSaveDialog(strFile, filter, strDirectory);
	}
	else
	{
		return OpenSaveDialog(strFile, filter, getCurrentDirectory());
	}
}
Пример #18
0
FILE* openFile(const char* path, const char* mode)
{
	// we need to get a full path to the file for relative paths (normalizePath will always work, isFullPath is an optimization)
	std::wstring wpath = fromUtf8(isFullPath(path) ? path : normalizePath(getCurrentDirectory().c_str(), path).c_str());

	// this makes sure we can use long paths and, more importantly, allows us to open files with special names such as 'aux.c'
	wpath.insert(0, L"\\\\?\\");
	std::replace(wpath.begin(), wpath.end(), '/', '\\');

	// convert file mode, assume short ASCII literal string
	wchar_t wmode[8] = {};
	assert(strlen(mode) < ARRAYSIZE(wmode));
	std::copy(mode, mode + strlen(mode), wmode);

	return _wfopen(wpath.c_str(), wmode);
}
Пример #19
0
// This method is trying to find out where are the DAT files located
std::string CrossPlatform::findFalloutDataPath()
{
    if (_falloutDataPath.length() > 0)
        return _falloutDataPath;
    Logger::info() << "Looking for Fallout data files" << std::endl;
    std::vector<std::string> directories;
    directories.push_back(getCurrentDirectory());
    directories.push_back(getDataPath());

    try
    {
        std::vector<std::string> cdDrives = getCdDrivePaths();
        directories.insert(directories.end(), cdDrives.begin(), cdDrives.end());
    }
    catch (Exception e)
    {
        Logger::error() << e.message() << std::endl;
    }

    for (auto &directory : directories)
    {
        if (std::all_of(
                necessaryDatFiles.begin(),
                necessaryDatFiles.end(),
                [directory](std::string file) {
                    std::ifstream stream(directory + "/" + file);
                    if (stream)
                    {
                        Logger::info() << "Searching in directory: " << directory << " " << file << " [FOUND]" << std::endl;
                        return true;
                    }
                    else
                    {
                        Logger::info() << "Searching in directory: " << directory << " " << file << " [NOT FOUND]" << std::endl;
                        return false;
                    }
                })
                )
        {
            _falloutDataPath = directory;
            return _falloutDataPath;
        }
    }

    throw Exception("Fallout data files are not found!");
}
Пример #20
0
MWindow::MWindow(void):
m_focus(true),
m_active(true),
m_fullscreen(false),
m_width(0),
m_height(0),
m_colorBits(0),
m_pointerEvent(NULL),
m_hDC(NULL),
m_hRC(NULL),
m_hWnd(NULL)
{
	m_position[0] = 0;
	m_position[1] = 0;
	strcpy(m_workingDirectory, getCurrentDirectory());
	strcpy(m_title, "");
}
Пример #21
0
const char * MWindow::getSaveFilename(const char * title, const char * filter, const char * startPath)
{
	char winStartPath[256] = "";
	if(startPath)
	{
		strcpy(winStartPath, startPath);
		strrep(winStartPath, '/', '\\');
	}

	const char * currentDir = getCurrentDirectory();
	setActive(false);

	static char filename[256];
	OPENFILENAME fn;

	memset(&fn, 0, sizeof(fn));
	strcpy(filename, "");

	fn.lpstrInitialDir = winStartPath;
	fn.lStructSize	= sizeof(fn);
	fn.lpstrFilter	= filter;
	fn.lpstrFile	= filename;
	fn.nMaxFile		= 256*4;
	fn.Flags		= OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	fn.lpstrTitle	= title;
	filename[0]		= NULL;
	fn.hwndOwner    = m_hWnd;

	if(GetSaveFileName(&fn))
	{
		setCurrentDirectory(currentDir);
		setActive(true);
		return filename;
	}

	setActive(true);
	return NULL;
}
Пример #22
0
std::string FileSystem::normalize(const std::string& path)
{
    auto fullPath = path;
    if (fullPath.front() != '/') { // TODO: Windows's drive (ex. 'C:' drive) and '\\[server name]'
        // NOTE: 'path' is not full path.
        fullPath = FileSystem::join(getCurrentDirectory(), fullPath);
    }

    std::vector<std::string> paths;
    auto iter = PathIterator::begin(fullPath);
    while (iter != PathIterator::end(fullPath)) {
        auto current = *iter;
        iter = PathIterator::next(iter);

        if (current == ".") {
            continue;
        }
        if (current == "..") {
            assert(!paths.empty());
            if (paths.empty()) {
                return fullPath;
            }
            paths.pop_back();
            continue;
        }
        paths.push_back(current);
    }

    fullPath.clear();
    for (auto & current : paths) {
        if (fullPath.empty() && current == "/") {
            fullPath = current;
            continue;
        }
        fullPath = FileSystem::join(fullPath, current);
    }
    return std::move(fullPath);
}
Пример #23
0
bool Utils::SaveDialog(CString& strFile, FileType& fileType, std::vector<CString>& filter, std::vector<FileType>& fileTypes)
{
	CFileDialog dlg(FALSE);

	CString strFilter(makeFilter(filter));
	dlg.m_ofn.lpstrFilter = strFilter;

	dlg.m_ofn.lpstrDefExt = NULL;

	CString initalDirectory(getCurrentDirectory());
	dlg.m_ofn.lpstrInitialDir = initalDirectory;

	dlg.m_ofn.Flags |= OFN_CREATEPROMPT;

	if (dlg.DoModal() == IDOK)
	{
		int typeIndex = dlg.m_ofn.nFilterIndex;
		strFile = getFileName(filter, typeIndex, dlg.GetPathName());
		fileType = fileTypes[typeIndex - 1];
		return true;
	}

	return false;
}
Пример #24
0
int main(int argc, char *argv[]){
	char *currDir  = NULL;
	char relPath[] = "../doc";
	char testPart[] = "/foo/bar/test.txt";
	char *filePart = NULL;
	char *newDir   = NULL;
	
	Logging_setup(argv[0], LOG_TOSTDERR | LOG_LEVELTRACE, NULL);
	currDir = getCurrentDirectory();
	Logging_infof("Current directory is: \"%s\"", currDir);
	newDir = getCombinedPath(currDir, relPath);
	Logging_infof("Doc directory is: \"%s\"", newDir);
	filePart = getPathPart(testPart, PATH_FILE);
	Logging_infof("The file part of \"%s\" with extension is: \"%s\"", 
		testPart, filePart);
	mu_free(filePart);
	filePart = getPathPart(testPart, PATH_FILEONLY);
	Logging_infof("The file part of \"%s\" without extension is: \"%s\"", 
		testPart, filePart);
	mu_free(filePart);
	mu_free(newDir);
	mu_free(currDir);
	exit(EXIT_SUCCESS);
}
Пример #25
0
int chdir(const char *filepath)
{
    String *last = ZERO;
    List<String *> lst;
    char cwd[PATH_MAX], buf[PATH_MAX], *path = ZERO;
    FileSystemPath fspath;
    struct stat st;

    /* First stat the file. */
    if (stat(filepath, &st) != 0)
    {
        return -1;
    }
    /* Must be a directory. */
    if (!S_ISDIR(st.st_mode))
    {
        errno = ENOTDIR;
        return -1;
    }
    /* What's the current working dir? */
    getcwd(cwd, PATH_MAX);
    
    /* Relative or absolute? */
    if (filepath[0] != '/')
    {
        snprintf(buf, sizeof(buf), "%s/%s", cwd, filepath);
        fspath.parse(buf);
        memset(buf, 0, sizeof(buf));
    
        /* Process '..' */
        for (ListIterator<String *> i(fspath.split()); i.hasCurrent(); i++)
        {
            if ((**i.current())[0] != '.')
            {
                lst.append(i.current());
                last = i.current();
            }
            else if ((**i.current())[1] == '.' && last)
            {
                lst.remove(last);
            }
        }
        /* Construct final path. */
        for (ListIterator<String *> i(&lst); i.hasCurrent(); i++)
        {
            strcat(buf, "/");
            strcat(buf, **i.current());
        }
        path = buf;
    }
    else
        path = (char *) filepath;
    
    /* Fall back to slash? */
    if (!path[0])
    {
        strcpy(buf, "/");
        path = buf;
    }
    // Set current directory
    (*getCurrentDirectory()) = path;

    /* Done. */
    errno = ZERO;
    return 0;
}
Пример #26
0
int main()
{
	char c[200],a[200],temp[50],home[50],*args[50];
stk S;
pid_t p;
int j,i,fd,n,flag=0,pid,num_arg,status,block;
  sigset(SIGCHLD, sig_handler);
ini(&S);
getCurrentDirectory(home);
while(1) {
if(!flag){
getCurrentDirectory(temp);
printf("myshell[%s]:- ", temp);
gets(a);
num_arg = parse_cmd(a,args);}
flag=0;

	if(a[0]== '\0');
else if(feof(stdin))
{printf("\n");
exit(0);}
else if(num_arg>1&&strstr(args[1],"&")){
        pid = fork();
if(pid==0)
{signal(SIGALRM,times_up);  alarm (10);
execvp(args[0], args);
//execlp(arg[0], "/usr", (char *) 0);
while(1);
            exit(0); }

           else{
    printf("Waiting for child, pid = %d\n",pid);
    waitpid(pid, &status, 0);
    printf("child process finished of pid = %d\n",pid);
  }
} 
else if(!strcmp(a,"ls")){
j=strlen(a);
push(a,&S,j);
system("ls");
}
else if(!strcmp(args[0],"history"))
{
i=0;n=0;
if(num_arg==1)
pop(&S);
else{
strcpy(c,args[1]);
while(c[i]!='\0')
{  n=n*10+c[i++]-48;}
pop1(&S,n);}
j=strlen(a);push(a,&S,j);
}
else if(!strcmp(args[0],"issue"))
{
n=0;push(a,&S,j);strcpy(c,args[1]);
while(c[i]!='\0')
{  n=n*10+c[i++]-48;}
j=strlen(a);
strcpy(a,S.a[n-1]);
flag=1;
}
else if(!strcmp(args[0],"cd"))
{j=strlen(a);push(a,&S,j);
if(num_arg==1)
changeDirectory1(home);
else{
changeDirectory(args[1]);
}}
else if (!strcmp(args[0],"rm")){
	 push(a,&S,j);
	fd=unlink(args[1]);
	printf("File deleted\n");
	if(fd==-1)
	printf("Can't delete file\n");
}
else if(!strcmp(a,"quit"))
exit(0);
else 
printf("not a recognized command\n");
	}
	printf("\n");
	return 0;
}
Пример #27
0
Path Path::getAbsolutePath() const {
    if (isEmpty() || isAbsolute()) {
        return *this;
    }
    return getCurrentDirectory().concat(*this);
}
Пример #28
0
void FileLocator::addPathFromApplication(const char* executablePath)
	{
	/* Separate the executable name from the executable path: */
	const char* slashPtr=findLastOf(executablePath,'/');
	std::string appName=slashPtr!=0?std::string(slashPtr+1):std::string(executablePath);
	
	/* Add the standard resource search path for private installed applications: */
	if(getenv("HOME")!=0)
		{
		std::string path=getenv("HOME");
		path.append("/.");
		path.append(appName);
		addPath(path);
		}
	
	/* Add the standard resource search paths for system-wide installed applications: */
	addPath("/usr/share/"+appName);
	addPath("/usr/local/share/"+appName);
	
	/* Construct the fully-qualified executable name: */
	std::string fullExePath;
	if(executablePath[0]=='/')
		fullExePath=executablePath;
	else
		{
		/* Try to find the full path to the executable: */
		#if 0
		/* Get the full executable path through the /proc interface: */
		char pse[PATH_MAX];
		int pseLength=readlink("/proc/self/exe",pse,PATH_MAX);
		if(pseLength>=0)
			fullExePath=std::string(pse,pse+pseLength);
		else
			{
		#else
		/* Search for the executable just as the shell did: */
		if(slashPtr==0&&getenv("PATH")!=0)
			{
			/* Search for the executable in the PATH list: */
			const char* pathBegin=getenv("PATH");
			while(*pathBegin!='\0')
				{
				/* Find the end of the next path: */
				const char* pathEnd;
				for(pathEnd=pathBegin;*pathEnd!='\0'&&*pathEnd!=':';++pathEnd)
					;
				
				/* Test the path if it is non-empty: */
				if(pathEnd!=pathBegin)
					{
					/* Construct the full path name: */
					std::string testName;
					if(*pathBegin!='/')
						{
						/* Start the path name with the current directory: */
						testName=getCurrentDirectory();
						testName.push_back('/');
						}
					testName.append(pathBegin,pathEnd);
					testName.push_back('/');
					testName.append(appName);
					
					/* Test if the file exists and is an executable: */
					if(Misc::isPathFile(testName.c_str()))
						{
						/* Save the matching full path and stop searching: */
						fullExePath=testName;
						break;
						}
					}
				
				/* Go to the next path: */
				if(*pathEnd!='\0')
					++pathEnd;
				pathBegin=pathEnd;
				}
			}
		else
			{
			/* Use the provided path starting at the current directory: */
			fullExePath=getCurrentDirectory();
			fullExePath.push_back('/');
			fullExePath.append(executablePath);
			}
		#endif
		#if 0
			}
		#endif
		}
	
	/* Find the last slash in the cleaned fully-qualified executable path name: */
	std::string cleanFullExePath=cleanPath(fullExePath.c_str());
	executablePath=cleanFullExePath.c_str();
	slashPtr=findLastOf(executablePath,'/');
	
	#ifdef __linux__
	/* Check if the executable is part of a Linux application bundle: */
	if(slashPtr!=0)
		{
		if(slashPtr-executablePath>=4&&strncasecmp(slashPtr-4,"/exe",4)==0)
			{
			/* Add the bundle's base directory to the search path list: */
			addPath(executablePath,slashPtr-4);
			}
		else if(slashPtr-executablePath>=7&&strncasecmp(slashPtr-7,"/exe/64",7)==0)
			{
			/* Add the bundle's base directory to the search path list: */
			addPath(executablePath,slashPtr-7);
			}
		}
	#endif
	
	#ifdef __APPLE__
	/* Check if the executable is part of a Mac OS X application bundle: */
	if(slashPtr!=0&&slashPtr-executablePath>=19&&strncasecmp(slashPtr-19,".app/Contents/MacOS",19)==0)
		{
		/* Add the bundle's resource directory to the search path list: */
		addPath(std::string(executablePath,slashPtr-5)+"Resources");
		}
	#endif
	}
Пример #29
0
void FileLocator::addCurrentDirectory(void)
	{
	pathList.push_back(getCurrentDirectory());
	}
Пример #30
0
int main(int argc, _TCHAR* argv[])
{
	mkdir("Dec");mkdir("Enc");
	std::wstring wstrFindPath = getCurrentDirectory();
	CDir dir;
	dir.ReadDir(wstrFindPath);
	for (size_t i=0; i<dir.m_FileInfo.size(); i++)
	{
		if (!dir.m_FileInfo[i].IsDirectory())
		{
			std::wstring wstrExt = GetExtension(dir.m_FileInfo[i].wstrFilename);
			std::string strFilename = ws2s(dir.m_FileInfo[i].wstrFilename);
			if (wstrExt==L".ozj")
			{
				std::string strDestFilename = "Dec\\"+ChangeExtension(strFilename,".jpg");
				fileOffset(strFilename,strDestFilename,24);
			}
			else if (wstrExt==L".ozt")
			{
				std::string strDestFilename = "Dec\\"+ChangeExtension(strFilename,".tga");
				fileOffset(strFilename,strDestFilename,4);
			}
			else if (wstrExt==L".ozb")
			{
				std::string strDestFilename = "Dec\\"+ChangeExtension(strFilename,".bmp");
				fileOffset(strFilename,strDestFilename,4);
			}
			else if (wstrExt==L".jpg")
			{
				std::string strDestFilename = "Enc\\"+ChangeExtension(strFilename,".ozj");
				fileOffset(strFilename,strDestFilename,-24);
			}
			else if (wstrExt==L".tga")
			{
				std::string strDestFilename = "Enc\\"+ChangeExtension(strFilename,".ozt");
				fileOffset(strFilename,strDestFilename,-4);
			}
			else if (wstrExt==L".bmp")
			{
				std::string strDestFilename = "Enc\\"+ChangeExtension(strFilename,".ozb");
				fileOffset(strFilename,strDestFilename,-4);
			}
			else if (wstrExt==L".map"||wstrExt==L".obj")
			{
				decryptMuFile(strFilename,"Dec\\"+strFilename+"d");
			}
			else if (wstrExt==L".att")
			{
				decryptMuATTFile(strFilename,"Dec\\"+strFilename+"d");
			}
			else if (wstrExt==L".bmd")
			{
				if ("item.bmd"==strFilename)
				{
					decryptItemBMD(strFilename,"Dec\\"+ChangeExtension(strFilename,".csv"));
				}
				else if ("BuffEffect.bmd"==strFilename)
				{
					decryptBuffEffectFile(strFilename,"Dec\\"+strFilename+"d");
				}
				//else if (isEncBmd(strFilename))
				//{
				//	decryptMuFile(strFilename,"Dec\\"+strFilename);
				//}
				else
				{
					Bmd2Smd(strFilename,"Dec\\"+ChangeExtension(strFilename,".smd"));
				//	decryptMuFileXOR3(strFilename,"Dec\\"+strFilename);
				}
			}
			else if (wstrExt==L".csv")
			{
				if ("item.csv"==strFilename)
				{
					encryptItemBMD(strFilename,"Enc\\"+ChangeExtension(strFilename,".bmd"));
				}
			}
			else if (wstrExt==L".smd")
			{
				Smd2Bmd(strFilename,"Enc\\"+ChangeExtension(strFilename,".bmd"));
			}
		}
	}

	return 0;
}