home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OCreate.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  149 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OCreate.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OCreate.cpp 1.50 1996/08/11 23:49:12 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OCreate.hpp>
  40. #include <OMessage.hpp>
  41.  
  42. // member functions
  43.  
  44. OCreate::OCreate() : Created((HOBJECT)NULL)
  45.   {}
  46.  
  47. OCreate::~OCreate()
  48.   {}
  49.  
  50. PSZ OCreate::isOfType() const
  51.  return("OCreate"); 
  52. }
  53.  
  54.  
  55. void OCreate::Create()
  56. {
  57.  if (!File)
  58.    return;
  59.  
  60.  if (!Location)
  61.    Location << (PSZ) "<WP_DESKTOP>";
  62.  
  63.  
  64.  if (is(".INF"))
  65.    CreateBook();
  66.  else if (is(".EXE") | is(".COM") |
  67.            is(".BAT") | is(".CMD"))
  68.    CreateExe();
  69.  else
  70.    CreateDoc();
  71.  Title << (PSZ)NULL;
  72.  File << (PSZ)NULL;
  73. }
  74.  
  75.  
  76. void OCreate::CreateBook()
  77. {
  78.  PSZ Setup = new CHAR[3*CCHMAXPATH];
  79.  
  80.  if (!Title)
  81.   {
  82. #ifndef __IBMCPP__
  83.    ifstream file((PCSZ)File);
  84. #else
  85.    ifstream file(File);
  86. #endif
  87.    PSZ BTitle = new CHAR[50];
  88.    BTitle[0] = '\0';
  89.    file.seekg(107L);
  90.    file.getline(BTitle, 48);
  91.    if (strlen(BTitle) > 0)
  92.      Title << BTitle;
  93.    else
  94.      Title << File;
  95.    file.close();
  96.    delete[] BTitle;
  97.   }
  98.  
  99.  sprintf(Setup, "EXENAME=VIEW.EXE;PARAMETERS=%s", File.getText());
  100.  Created = WinCreateObject("WPProgram", Title,
  101.                            Setup, Location, CO_REPLACEIFEXISTS);
  102.  delete[] Setup;
  103. }
  104.  
  105.  
  106. void OCreate::CreateExe()
  107. {
  108.  PSZ Setup = new CHAR[2*CCHMAXPATH];
  109.  PSZ Dir   = new CHAR[CCHMAXPATH];
  110.  
  111.  strcpy(Dir, File);
  112.  strcpy(strrchr(Dir, '\\'), "");
  113.  
  114.  if (!Title)
  115.    Title << File;
  116.  
  117.  sprintf(Setup, "EXENAME=%s;STARTUPDIR=%s", File.getText(), Dir);
  118.  Created = WinCreateObject("WPProgram", Title,
  119.                            Setup, Location, CO_REPLACEIFEXISTS);
  120.  delete[] Setup;
  121.  delete[] Dir;
  122. }
  123.  
  124.  
  125. void OCreate::CreateDoc()
  126. {
  127.  PSZ Setup = new CHAR[2*CCHMAXPATH];
  128.  
  129.  if (!Viewer)
  130.    Viewer << (PSZ) "E.EXE";
  131.  
  132.  Title << OCL::error(38);
  133.  Title + File;
  134.  sprintf(Setup, "EXENAME=%s;PARAMETERS=\"%s\"", Viewer.getText(), File.getText());
  135.  Created = WinCreateObject("WPProgram", Title,
  136.                            Setup, Location, CO_REPLACEIFEXISTS);
  137.  delete[] Setup;
  138. }
  139.  
  140.  
  141. BOOL OCreate::is(PCSZ Ext) 
  142. {
  143.  return(strstr(strupr(File), Ext)!=NULL); 
  144. }
  145.  
  146.  
  147. // end of source
  148.