cmWindowsConfigure.cxx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmWindowsConfigure.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmSystemTools.h"
  14. #include <windows.h>
  15. bool cmWindowsConfigure::Configure(const char* file)
  16. {
  17. std::ifstream fin(file);
  18. if(!fin)
  19. {
  20. return false;
  21. }
  22. char inbuf[5001];
  23. while(fin.getline(inbuf, 5000) )
  24. {
  25. std::string inputLine = inbuf;
  26. if(inputLine[0] != '#')
  27. {
  28. std::string destDir;
  29. std::string fromFile;
  30. std::string toFile;
  31. std::string::size_type pos = inputLine.find(':');
  32. if(pos != std::string::npos)
  33. {
  34. destDir = inputLine.substr(0, pos);
  35. std::string::size_type nextPos = inputLine.find(':', pos+1);
  36. if(nextPos != std::string::npos)
  37. {
  38. std::string toFileName = inputLine.substr(pos+1, nextPos-pos-1);
  39. fromFile = inputLine.substr(nextPos+1);
  40. toFile = destDir;
  41. toFile += "/";
  42. toFile += toFileName;
  43. cmSystemTools::ReplaceString(toFile, "${CMAKE_BINARY_DIR}",
  44. m_WhereBuild.c_str() );
  45. cmSystemTools::ReplaceString(toFile, "${CMAKE_SOURCE_DIR}",
  46. m_WhereSource.c_str() );
  47. cmSystemTools::ReplaceString(fromFile, "${CMAKE_BINARY_DIR}",
  48. m_WhereBuild.c_str() );
  49. cmSystemTools::ReplaceString(fromFile, "${CMAKE_SOURCE_DIR}",
  50. m_WhereSource.c_str() );
  51. cmSystemTools::ReplaceString(destDir, "${CMAKE_BINARY_DIR}",
  52. m_WhereBuild.c_str() );
  53. cmSystemTools::ReplaceString(destDir, "${CMAKE_SOURCE_DIR}",
  54. m_WhereSource.c_str() );
  55. }
  56. }
  57. if(destDir != "" && fromFile != "" && toFile != "")
  58. {
  59. if(!cmSystemTools::MakeDirectory(destDir.c_str()) )
  60. {
  61. std::string error = "Error: can not create directory: ";
  62. error += destDir;
  63. MessageBox(0, error.c_str(), "config ERROR", MB_OK);
  64. return false;
  65. }
  66. if(!CopyFile(fromFile.c_str(), toFile.c_str(), FALSE))
  67. {
  68. std::string error = "Error: can not copy : ";
  69. error += fromFile;
  70. error += " to ";
  71. error += toFile;
  72. MessageBox(0, error.c_str(), "config ERROR", MB_OK);
  73. return false;
  74. }
  75. }
  76. else if (inputLine != "")
  77. {
  78. std::string error = "Error in parsing : ";
  79. error += file;
  80. error += " in line:\n ";
  81. error += inputLine;
  82. MessageBox(0, error.c_str(), "config ERROR", MB_OK);
  83. return false;
  84. }
  85. }
  86. }
  87. return true;
  88. }