std::string Resources( std::string subdirectory, std::string filename )
		{
			std::string full_directory = "./";
			std::string share_directory = elix::program::RootDirectory();

			AppendDirectory( share_directory, "share" );

			if ( elix::path::Exist( share_directory ) )
			{
				full_directory = share_directory;
			}
			else
			{
				share_directory = elix::program::RootDirectory();

				/* Takes into account the the binaries are stored in bin subdirectory */
				size_t pos = share_directory.find_last_of(ELIX_DIR_SEPARATOR);
				if ( pos > 1 )
					full_directory = share_directory.substr(0, pos);
				else
					full_directory = "..";

				AppendDirectory( full_directory, "share" );
			}

			AppendDirectoryAndCreate( full_directory, elix::program::_user );
			AppendDirectoryAndCreate( full_directory, subdirectory );
			AppendFileName( full_directory, filename );

			return full_directory;
		}
示例#2
0
void ChangeDirectoryCommand(){

    // Make sure we have a path thats not null
    if (args[1] == NULL){
        printf("Error, Expected Path Argument following cd\n");
        return;
    }

    // Store args[1] in a temporary path
    char * path = malloc(sizeof(char) * (strlen(args[1]) + 1));
    strcpy(path, args[1]);

    AppendDirectory(path);

    // Check if Directory Exists
    DIR* dir = opendir(path);
    if (!dir){
        printf ("Error: Invalid Directory for %s\n", path);
        return;
    }

    // If its made it here, its a valid directory
    // Update internal variable for current directory
    cwd = malloc(strlen(path) + 1);
    strcpy(cwd, path);
    printf("Directory changed to %s\n", cwd);
}
示例#3
0
// The 'multiple' parameter determines if this method is called by background command
// or the repeat command. The arguments are in different indexies for each.
void BackgroundRunCommand(int multiple) {

    // Check that we have arguments
    if (args[1] == NULL){
        printf("Error, Expected Argument following command\n");
        return;
    }

    // Depending on if we get the command repeat n program or run program,
    // the argument indexies are different.
    char * arguments[MAX_ARGS];
    int i = 1;
    int j = 1;
    if(multiple == 1){
        i++;
        j++;
    }

    // We want all the arguments but the initial "run" command
    while (args[i]){
        arguments[i-j] = args[i];
        i++;
    }

    // Add a null terminatory so execv knows when to stop
    arguments[i-j] = '\0';

    char * runpath = malloc(sizeof(char) * (strlen(args[j]) + 1));
    strcpy(runpath, args[j]);

    AppendDirectory(runpath);

    // Child to run program
    pid_t child_pid;

    // Print an error if the fork failed
    if((child_pid = fork()) < 0 )
    {
        // We shouldn't get here ever, unless there was an error
        printf("Error, program failed to execute.\n");
        return;
    }

    if(child_pid == 0){
        execv(runpath, arguments);
        // We shouldn't get here unless it failed to execute.
        printf("Error: Program failed to execute.");
        return;
    }
    else{
        // Print the newly created Child Pid
        printf("Newly Created Pid: %d\n", child_pid);
        pids[pidIndex] = child_pid;
        pidIndex++;
    }
}
示例#4
0
void RunCommand() {

    // Check that we have arguments
    if (args[1] == NULL){
        printf("Error, Expected Argument following run\n");
        return;
    }

    char * arguments[MAX_ARGS];
    int i = 1;

    // We want all the arguments but the initial "run" command
    while (args[i]){
        arguments[i-1] = args[i];
        i++;
    }
    // Add a null terminatory so execv knows when to stop
    arguments[i-1] = '\0';

    char * runpath = malloc(sizeof(char) * (strlen(args[1]) + 1));
    strcpy(runpath, args[1]);

    AppendDirectory(runpath);

    // Child to run program
    pid_t child_pid;

    // Print error if fork fails
    if((child_pid = fork()) < 0 )
    {
      printf("Failure with Fork\n");
      return;
    }

    // If we have the child pid
    if(child_pid == 0){
        // Run the program
        execv(runpath, arguments);

        // We shouldn't get here ever, unless there was an error
        printf("Error, program failed to execute.\n");
        return;
    }

    // Parent process
    else
    {
        // Wait for child to finish
        wait(NULL);
    }
}
示例#5
0
//-------------------------------------------------------------
// Post    : Return TRUE if a new match found
// Task    : Find the next file that meets the conditions specified
//           in the last FindFirst call
//-------------------------------------------------------------
bool CPath::FindNext()
{
    if (m_hFindFile == NULL)
        return FALSE;

    WIN32_FIND_DATA	FindData;
    while(FindNextFile(m_hFindFile,&FindData) != FALSE)
    {   // while(FindNext(...))

        if(AttributesMatch(m_dwFindFileAttributes,FindData.dwFileAttributes))
        {   // if(AttributesMatch(...)
            if((_A_SUBDIR & FindData.dwFileAttributes) == _A_SUBDIR)
            {
                if (IsDirectory())
                {
                    // Found a directory
                    UpDirectory();
                }
                else
                {
                    SetNameExtension("");
                }
                AppendDirectory(FindData.cFileName);
            }
            else
            {
                // Found a file
                if (IsDirectory())
                {
                    // Found a directory
                    UpDirectory();
                }
                SetNameExtension(FindData.cFileName);
            }
            if((_A_SUBDIR & FindData.dwFileAttributes) == _A_SUBDIR)
                EnsureTrailingBackslash(m_strPath);
            return TRUE;
        }
    }

    return FALSE;
}
示例#6
0
 void HierTreeCtrl::OnCreateDirectory()
 {
     wxTreeItemId rootItem = GetRootItem();
     wxTreeItemId newItem = AppendDirectory(rootItem, "New Directory");
     EditLabel(newItem);
 }