home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / aprofile.cpp < prev    next >
C/C++ Source or Header  |  1999-06-12  |  3KB  |  89 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998, 1999  Paul Elliott
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     Paul Elliott
  20.     PMB #181
  21.     11900 Metric Blvd Ste. J
  22.     Austin Tx 78758-3117
  23.     pelliott@io.com
  24. */
  25. #include <io.h>
  26. #include <iapp.hpp>
  27. #include "AProfile.hpp"
  28.  
  29. // get file spec of an application file name.
  30. // We try to get location of the user profile from the OS/2
  31. // user profile using the indicated profile_name_key.
  32. // If the key does not exist we create the profile in
  33. // the directory that the application exists in as indicated
  34. // by argv.
  35. IString AProfile::ApplicationProfileName(const IString& app_name,
  36.                                               const IString& profile_name_key)
  37. {
  38.     // reserve space for answer.
  39.     IString appl_profile;
  40.     {
  41.         // ger user profile.
  42.         IProfile user=IProfile::userProfile();
  43.  
  44.         // set the application name.
  45.         user.setDefaultApplicationName(app_name);
  46.  
  47.         // if the application file name key exists.....
  48.         if ( user.containsKeyName(profile_name_key) &&
  49.             (  access( user.elementWithKey(profile_name_key) , 04) == 00 )
  50.            )
  51.         {
  52.             // then use that data stored in user profile.
  53.             appl_profile = user.elementWithKey(profile_name_key);
  54.         }
  55.         else            // if not in application profile, make up a file name.
  56.         {
  57.             // place to store full name.
  58.             char full[_MAX_PATH];
  59.  
  60.             // full name of application name =argv[0].
  61.             _fullpath(full,IApplication::current().argv(0),sizeof(full) );
  62.  
  63.             // split application name into parts.
  64.             char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
  65.             _splitpath(full,drive,dir,fname,ext);
  66.  
  67.             // and put it back together  with extension = ".ini"
  68.             char ini_name[_MAX_PATH];
  69.             _makepath(ini_name,drive,dir,fname,".ini");
  70.  
  71.             // this is the profile name.
  72.             appl_profile = ini_name;
  73.  
  74.  
  75.             // store it in user profile.
  76.             user.addOrReplaceElementWithKey(profile_name_key,appl_profile);
  77.         };
  78.     };
  79.     return appl_profile;          // return application profile file spec.
  80. };
  81.  
  82. // construct the application profile from the filename specified above.
  83. AProfile::AProfile(const IString& app_name,const IString& profile_name_key)  :
  84. IProfile(AProfile::ApplicationProfileName(app_name,profile_name_key) )
  85. {
  86.     // set the application name in the opened profile.
  87.     setDefaultApplicationName(app_name);
  88. };
  89.