home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm4.zip / source / aprofile.cpp < prev    next >
C/C++ Source or Header  |  1998-04-22  |  3KB  |  88 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998  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.     11900 Metric Blvd #J-181
  21.     Austin Tx 78758-3117
  22.     pelliott@io.com
  23. */
  24. #include <io.h>
  25. #include <iapp.hpp>
  26. #include "AProfile.hpp"
  27.  
  28. // get file spec of an application file name.
  29. // We try to get location of the user profile from the OS/2
  30. // user profile using the indicated profile_name_key.
  31. // If the key does not exist we create the profile in
  32. // the directory that the application exists in as indicated
  33. // by argv.
  34. IString AProfile::ApplicationProfileName(const IString& app_name,
  35.                                               const IString& profile_name_key)
  36. {
  37.     // reserve space for answer.
  38.     IString appl_profile;
  39.     {
  40.         // ger user profile.
  41.         IProfile user=IProfile::userProfile();
  42.  
  43.         // set the application name.
  44.         user.setDefaultApplicationName(app_name);
  45.  
  46.         // if the application file name key exists.....
  47.         if ( user.containsKeyName(profile_name_key) &&
  48.             (  access( user.elementWithKey(profile_name_key) , 04) == 00 )
  49.            )
  50.         {
  51.             // then use that data stored in user profile.
  52.             appl_profile = user.elementWithKey(profile_name_key);
  53.         }
  54.         else            // if not in application profile, make up a file name.
  55.         {
  56.             // place to store full name.
  57.             char full[_MAX_PATH];
  58.  
  59.             // full name of application name =argv[0].
  60.             _fullpath(full,IApplication::current().argv(0),sizeof(full) );
  61.  
  62.             // split application name into parts.
  63.             char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT];
  64.             _splitpath(full,drive,dir,fname,ext);
  65.  
  66.             // and put it back together  with extension = ".ini"
  67.             char ini_name[_MAX_PATH];
  68.             _makepath(ini_name,drive,dir,fname,".ini");
  69.  
  70.             // this is the profile name.
  71.             appl_profile = ini_name;
  72.  
  73.  
  74.             // store it in user profile.
  75.             user.addOrReplaceElementWithKey(profile_name_key,appl_profile);
  76.         };
  77.     };
  78.     return appl_profile;          // return application profile file spec.
  79. };
  80.  
  81. // construct the application profile from the filename specified above.
  82. AProfile::AProfile(const IString& app_name,const IString& profile_name_key)  :
  83. IProfile(AProfile::ApplicationProfileName(app_name,profile_name_key) )
  84. {
  85.     // set the application name in the opened profile.
  86.     setDefaultApplicationName(app_name);
  87. };
  88.