X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Ffs.cc;fp=src%2Ffs.cc;h=c85040a0347c0fb7995e8d326b076aadf25f8219;hp=0000000000000000000000000000000000000000;hb=172da567dcbb634b13069e5c12ae8b6a9b3a29dc;hpb=d0cc9ec2f92f149279ebc8f1c29d2be627074488 diff --git a/src/fs.cc b/src/fs.cc new file mode 100644 index 0000000..c85040a --- /dev/null +++ b/src/fs.cc @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include "fs.h" +#include "icon.h" +#include "gmath/gmath.h" +#include "opengl.h" +#include "app.h" + +static IconRenderer *iconrend; + +bool init_fs() +{ + iconrend = new ShapesIcons; + if(!iconrend->init()) { + return false; + } + + return true; +} + +void cleanup_fs() +{ + delete iconrend; +} + +void draw_fs() +{ + FSNode test; + test.type = FSNODE_DIR; + + Mat4 xform; + xform.rotate(time_sec, 0, 0); + xform.rotate(0, 0, time_sec * 0.5); + xform.translate(0, 2, -5); + + glPushMatrix(); + glMultMatrixf(xform[0]); + + glUseProgram(0); + glDisable(GL_TEXTURE_2D); + iconrend->draw(&test); + + glPopMatrix(); +} + +// ---- FSNode implementation ---- +FSNode::FSNode() +{ + type = FSNODE_UNKNOWN; + abs_path = name = suffix = 0; +} + +FSNode::~FSNode() +{ + if(abs_path) { + delete [] abs_path; + } +} + +void FSNode::set_path(const char *s) +{ + int len = strlen(s); + if(!len) return; + + delete [] abs_path; + + const char *slash = s + len - 1; + while(slash > s && *slash != '/') { + --slash; + } + if(name == s) { // no slashes found + char buf[1024]; + if(!getcwd(buf, sizeof buf)) { + abort(); + } + + int dirlen = strlen(buf); + abs_path = new char[len + dirlen + 2]; + sprintf(abs_path, "%s/%s", buf, s); + + name = abs_path + dirlen + 1; + suffix = abs_path + len + dirlen - 1; + } else { + abs_path = new char[len + 1]; + memcpy(abs_path, s, len + 1); + + name = abs_path + (slash - s); + suffix = abs_path + len - 1; + } + + while(suffix > name && *suffix != '.') { + --suffix; + } + if(suffix == name) { + suffix = 0; + } +}