コード例 #1
0
// Set the Current variable to the current directory.
void FileSystem::callDirectory(CharString location) {
    if(location.Compare("..",2)) {
        if(Current->Parent != 0x0) {
            Current = Current->Parent;
        }
    } else {
        FileStructureNode* node = getNodeFromString(location);
        if(node != 0x0) {
            if(node->type == Directory) {
                Current = node;
            } else {
                // throw error!
                CharString cs = CharString("cd: ");
                cs.concata(location);
                cs.concata(": not a directory",17);
                this->ErrorString = cs.get();
                throw 10;
            }
        } else {
            // throw error!
            CharString cs = CharString("cd: ");
            cs.concata(location);
            cs.concata(": directory does not exist",26);
            this->ErrorString = cs.get();
            throw 9;
        }
    }
}
コード例 #2
0
// within zip file or folder?
CharString APIMod::getModFileData(CharString modfile){
    // only support folders here, use inheritance to load zip files

    if(isfolder){
        CharString filex = file.clone();
        filex.concata("/");
        filex.concata(modfile);
        cout << "Reading mod folder file: " << filex << endl;
        return fileReadAll(filex);
    }else{
        cout << "could not open Mod File Data " << modfile << endl;
    }
}
コード例 #3
0
// Removes a directory from the current directory based on location.
// Input: String location
void FileSystem::removeDir(CharString location) {
    FileStructureNode* node = getNodeFromString(location);
    if(node != 0x0 && node != Root) {
        // type-dir
        if(node->type == Directory) {
            // determine if CD is inside this dir.
            bool isCD = false;
            if(node->Child != 0x0) {
                FileStructureNode* cc = node->Child;
                while(cc != 0x0 && !isCD) {
                    // search through all of the relatives.
                    if(cc == Current) {
                        isCD = true;
                        break;
                    } else if(cc->Sibling != 0x0) {
                        FileStructureNode* ccd = cc->Sibling;
                        while(ccd != 0x0) {
                            if(ccd == Current) {
                                isCD=true;
                                break;
                            }
                            ccd = ccd->Sibling;
                        }
                    }
                    cc = cc->Child;
                }
            } else if(node == Current) {
                isCD = true;
            }


            if(!isCD) {
                node->del();
            } else {
                // this is restricted by call directory
                CharString cs = CharString("rmdir: ");
                cs.concata(location);
                cs.concata(": directory cannot be deleted",29);
                this->ErrorString = cs.get();
                throw 15;
            }

        } else {
            // cannot find!
            CharString cs = CharString("rmdir: ");
            cs.concata(location);
            cs.concata(": directory does not exist",26);
            this->ErrorString = cs.get();
            throw 8;
        }
    } else {
        // throw error!
        CharString cs = CharString("rmdir: ");
        cs.concata(location);
        cs.concata(": directory does not exist",26);
        this->ErrorString = cs.get();
        throw 7;
    }
}
コード例 #4
0
// Desc: Removes a file from the current directory based on location.
// Input: String location
void FileSystem::removeFile(CharString location) {
    FileStructureNode* node = getNodeFromString(location);
    if(node != 0x0) { // is node available?
        if(node->type == File) { // is node a file?
            // directly delete file.
            node->del();
        } else { // else throw DNE error
            CharString cs = CharString("rm: ");
            cs.concata(location);
            cs.concata(": file does not exist",21);
            this->ErrorString = cs.get();
            throw 6;
        }
    } else { // else throw DNE error
        // throw error!
        CharString cs = CharString("rm: ");
        cs.concata(location);
        cs.concata(": file does not exist",21);
        this->ErrorString = cs.get();
        throw 5;
    }
}