]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMFile.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMFile.cpp
index 6fcfab6560982f1d1d2b75dd8a49e9c9f8091115..dcafc8e1c8e0995babff83ef93376d0e6d294f69 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "modelCDMFile.h"
 
+#include <fstream>
 #include <creaWx.h>
 #include <wx/dir.h>
 
@@ -43,34 +44,62 @@ modelCDMFile::modelCDMFile()
 {
 }
 
-modelCDMFile::modelCDMFile(const std::string& path, const int& level)
+modelCDMFile::modelCDMFile(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating file: " + path + "\n";
+  this->parent = parent;
   this->children.clear();
   this->level = level;
-
-  std::vector<std::string> words;
-  std::string delimiters;
-  //TODO::fix for windows
-  delimiters = "/";
-  CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
-  this->name = words[words.size()-1];
-
+  this->name = name;
   this->path = path;
   this->type = wxDIR_FILES;
+
+  std::ifstream in(path.c_str(), std::ifstream::in | std::ifstream::binary);
+  in.seekg(0, std::ifstream::end);
+  this->length = in.tellg();
+  in.close();
+
 }
 
 modelCDMFile::~modelCDMFile()
 {
 }
 
-bool modelCDMFile::OpenFile(std::string*& result)
+bool modelCDMFile::OpenFile(std::string*& result, const std::string& command)
 {
-  //TODO: implement method
+  if (!CDMUtilities::openFileWithCommand(path, command))
     return true;
+  else
+    {
+      result = new std::string("Couldn't open file with command " + command + ".");
+      return false;
+    }
 }
 
 const bool modelCDMFile::Refresh(std::string*& result)
 {
-  //TODO: implement method
+  //std::cout << "refreshing file " << this->name << std::endl;
+  std::ifstream in((this->path).c_str());
+  if(!in.is_open())
+    {
+      in.close();
+      return false;
+    }
+  std::ifstream in2(path.c_str(), std::ifstream::in | std::ifstream::binary);
+  in2.seekg(0, std::ifstream::end);
+  this->length = in2.tellg();
+  in2.close();
+  return true;
+}
+
+const bool modelCDMFile::OpenInFileExplorer(std::string*& result) const
+{
+  std::string pth = this->path.substr(0, path.size() - name.size() - 1);
+  if (!CDMUtilities::openFileExplorer(pth))
     return true;
+  else
+    {
+      result = new std::string("Couldn't open file.");
+      return false;
+    }
 }