Exemple #1
0
void xmlRep::makeDirectory(std::string Key,xmlRep rape)
{
	Directory dir;
	if(dir.DirectoryExists(TEXT("test")))
	{
		dir.SetCurrentDirectory(TEXT("./test"));
	  ofstream myfile;
  myfile.open (Key+".xml");
  myfile << rape.format();
  myfile.close();
  dir.SetCurrentDirectory(TEXT("../"));
	}
	else
	{
  dir.CreateDirectory(TEXT("test"));
  dir.SetCurrentDirectory(TEXT("./test"));
  ofstream myfile;
  myfile.open (Key+".xml");
  myfile << rape.format();
  myfile.close();
  dir.SetCurrentDirectory(TEXT("../"));
	}

}
Exemple #2
0
int main() {

  stdOut << "\n  Testing WinTools ";
  stdOut << "\n ==================\n";

  SystemError se;
  stdOut << TEXT("\n  Last error code = ") << ::GetLastError();
  stdOut << TEXT("\n  Last error message = ") << se.GetLastMsg();
  stdOut << std::endl;

  std::cout << "\n  testing directory management ";
  std::cout << "\n ------------------------------";

  Directory dir;
  if(dir.DirectoryExists(TEXT("test")))
  {
    std::cout << "\n  Directory test exists";
    if(dir.RemoveDirectory(TEXT("test")))
      std::cout << "\n  successfully removed directory test";
  }
  else
  {
    if(dir.CreateDirectory(TEXT("test")))
      std::cout << "\n  successfully created directory test";
    else
      std::cout << "\n  Directory creation failed";
  }
  stdOut << TEXT("\n  Current directory is: ") << dir.GetCurrentDirectory();
  if(dir.SetCurrentDirectory(TEXT("./test")))
  {
    stdOut << TEXT("\n  changed to: ")  << dir.GetCurrentDirectory();
    dir.SetCurrentDirectory(TEXT(".."));
    stdOut << TEXT("\n  changed back to: ") << dir.GetCurrentDirectory();
  }
  std::cout << std::endl;

  std::vector<stdStr> files = Directory::GetFiles();
  std::cout << "\n  files in this directory are:";
  for(size_t i=0; i<files.size(); ++i)
    stdOut << TEXT("\n    ") << files[i];
  std::cout << std::endl;

  files = Directory::GetFiles(TEXT("*.h*"));
  std::cout << "\n  *.h* files in this directory are:";
  for(size_t i=0; i<files.size(); ++i)
    stdOut << TEXT("\n    ") << files[i];
  std::cout << std::endl;

  std::vector<stdStr> dirs = Directory::GetDirectories();
  std::cout << "\n  directories in this directory are:";
  for(size_t i=0; i<dirs.size(); ++i)
    stdOut << TEXT("\n    ") << dirs[i];
  std::cout << std::endl;

  std::cout << "\n  testing Path management ";
  std::cout << "\n -------------------------";

  stdStr paths[] = { TEXT("aFile"), TEXT("../../aFile"), TEXT("test/aFile"), TEXT("../../") };
  for(int i=0; i<4; ++i)
  {
    stdOut << TEXT("\n  fileSpec: ") << std::setw(12) << paths[i];
    stdOut << TEXT(", name: ") << Path::getName(paths[i]);
    stdOut << TEXT("\n  fileSpec: ") << std::setw(12) << paths[i];
    stdOut << TEXT(", path: ") << Path::getPath(paths[i]);
  }
  std::cout << std::endl;

  std::cout << "\n  testing error messages ";
  std::cout << "\n ------------------------";

  int err = GetLastError();
  std::cout << "\n  Last error code = " << err;

  try {
    se.ThrowString(TEXT("throw message"),Convert::ToStdStr(__FILE__),__LINE__);
  }
  catch(const stdStr &msg)
  { 
    stdOut << TEXT("\n  ") << msg; 
  }
  std::cout << "\n";

  std::cout << "\n  test writing to \"Program Files\" Folder ";
  std::cout << "\n ------------------------------------------";

  stdStr CurrDir = Path::getFullPath(TEXT("."));
  stdStr fileSpec = CurrDir + TEXT("*.*");

  if(Directory::SetCurrentDirectory(TEXT("C:/Program Files")))
  {
    std::cout << "\n  sucessfully set directory to \"C:\\Program Files\"";
    if(Directory::DirectoryExists(TEXT("foobar stuff")))
    {
      std::cout << "\n  \"C:\\Program Files\\foobar stuff\" exists";
      if(!Directory::CopyFiles(fileSpec,TEXT("C:\\Program Files\\foobar stuff")))
        std::cout << "\n  one or more file copy operations failed";
      else
        std::cout << "\n  all file copy operations succeeded";
    }
    else if(Directory::CreateDirectory(TEXT("foobar stuff")))
    {
      std::cout << "\n  successfully created \".\\foobar stuff\"";
      if(!Directory::CopyFiles(fileSpec,TEXT("C:\\Program Files\\foobar stuff")))
        std::cout << "\n  one or more file copy operations failed";
      else
        std::cout << "\n  all file copy operations succeeded";
    }
  }

  std::cout << "\n";
  std::cout << "\n  File file operations: ";
  std::cout << "\n ----------------------";

  stdStr path = TEXT("C:\\temp");
  if(!Directory::SetCurrentDirectory(path))
  {
    stdOut << TEXT("\n\n  invalid path ") << path << TEXT("\n\n");
    return 1;
  }
  std::vector<stdStr> file = Directory::GetFiles();

  // find a fairly large cpp file to read

  stdStr displayFile = TEXT("");
  fileInfo fi;
  size_t fileSize = 0;
  for(size_t i=0; i<file.size(); ++i)
  {
    stdOut << TEXT("\n  ") << file[i];
    if(TEXT("cpp") == Path::getExt(file[i]))
    {
      fi.firstFile(file[i]);
      if(fileSize < fi.size() && fi.size() < 50000)
      {
        fileSize = fi.size();
        displayFile = file[i];
      }
    }
  }

  if(displayFile == TEXT(""))
  {
    stdOut << TEXT("\n  no *.cpp files in ") << path.c_str() << TEXT("\n\n");
    return 1;
  }


  stdOut << "\n\n  Reading Blocks";
  stdOut << "\n ----------------\n";

  if(file.size() > 0)
  {
    FileHandler fh;
    fh.setReadPath(path);
    if(fh.openFileReader(displayFile))
    {
      stdOut << "\n  opening file " << displayFile << "\n\n";
      const size_t size = 1024;
      size_t bytesRead;
      byte_ buffer[size];
      do
      {
        bytesRead = fh.getBlock(buffer,size);
        stdOut << fh.blockToString(buffer,bytesRead);
      } while(bytesRead == size);
    }
    fh.closeFileReader();
  }

  stdOut << "\n\n  Writing Blocks";
  stdOut << "\n ----------------";

  if(file.size() > 0)
  {
    FileHandler fh;
    fh.setReadPath(path);
    fh.setWritePath(path);
    if(!fh.openFileReader(displayFile))
    {
      stdOut << "\n  open " << displayFile << " failed\n\n";
      return 1;
    }
    else
      stdOut << "\n  opening file " << displayFile << " for reading";
    if(fh.openFileWriter(TEXT("test.txt")))
    {
      std::cout << "\n  opening file " << "test.txt" << " for writing";
      const size_t size = 1024;
      size_t bytesRead;
      byte_ buffer[size];
      int count = 0;
      do
      {
        std::cout << "\n    writing block #" << ++count;
        bytesRead = fh.getBlock(buffer,size);
        fh.putBlock(buffer,bytesRead);
      } while(bytesRead == size);
    }
    std::cout << "\n  closing write file";
    fh.closeFileWriter();
    std::cout << "\n  closing read file";
    fh.closeFileReader();
    std::cout << "\n\n";
  }
}