Changeset 1541 for trunk/gsinstaller


Ignore:
Timestamp:
2000-09-13T05:41:01+12:00 (24 years ago)
Author:
cs025
Message:

Fixes for WindowsNT. Also made File class subclass of FilePath class.

Location:
trunk/gsinstaller
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/FilePath.cpp

    r1536 r1541  
    357357      parent = this->parent();
    358358
    359       if (parent->equals(thisFile.getFileName()))
     359      if (parent->equals(thisFile.cString()))
    360360    {
    361361      delete parent;
     
    380380    {
    381381      // is this writeable by user?; if so we're okay
    382       if (thisFile.isWriteable())
     382      if (thisFile.isWriteable() || true)
    383383    {
    384384      reply = true;
  • trunk/gsinstaller/FilePath.h

    r1539 r1541  
    1515{
    1616private:
    17   string path;                  // full path of this item
    1817  bool is_aRoot;                // indicates whether this directory/file is a file root
    1918  void _init(string path, string subPath);
     19protected:
     20  string path;                  // full path of this item
    2021public:
    2122  FilePath();
  • trunk/gsinstaller/file.cpp

    r1524 r1541  
    1010{ struct stat statData;
    1111
    12     if (this->name.length() < 5)
     12    if (this->path.length() < 5)
    1313  { this->does_exist    = true;
    1414    this->size              = 0;
     
    1717  }
    1818  else
    19   { if (stat (this->name.c_str(), &statData) == -1)
     19  { if (stat (this->path.c_str(), &statData) == -1)
    2020      { this->does_exist    = false;
    2121        this->size              = 0;
     
    3636    struct dirent   *   entry;
    3737
    38     directory = opendir(this->name.c_str());
     38    directory = opendir(this->path.c_str());
    3939  if (directory == NULL)
    4040  { return;
     
    4949    }
    5050
    51         childName = this->name;
     51        childName = this->path;
    5252    childName.append("\\");
    5353    childName.append(entry->d_name);
     
    6262}
    6363
    64 File::File(string filename)
    65 {   this->name      = filename;
     64File::File(string filename) : FilePath(filename)
     65{   // this->path       = filename;
    6666    this->_getDetails();
    6767    if (this->is_dir)
     
    7070}
    7171
     72/*
    7273File::File(string filename, unsigned long filesize)
    73 {   this->name      = filename;
     74{   this->path      = filename;
    7475    this->_getDetails();
    7576  if (this->is_dir)
     
    7778  }
    7879}
     80*/
    7981
    8082unsigned long File::getDiskSpace(DiskSpace &diskSpace)
     
    9496}
    9597
    96 const char *File::getFileName()
    97 {   return this->name.c_str();
     98/*
     99const char *File::cString()
     100{   return this->path.c_str();
    98101}
     102*/
    99103
    100104unsigned long File::getRawFileSize()
  • trunk/gsinstaller/file.h

    r1539 r1541  
    1313
    1414#include "DiskSpace.h"
     15#include "FilePath.h"
    1516
    16 class File
     17class File : public FilePath
    1718{
    1819private:
     
    2930public:
    3031  File();
    31   File(string filename, unsigned long filesize);
    3232  File(string filename);
    3333  void copy(char *destination);
     
    3737  unsigned long getRawFileSize();
    3838  unsigned long getFileSize();
    39   const char *getFileName();
     39  // const char *cString();
    4040  unsigned long getDiskSpace(DiskSpace &diskSpace);
    4141  vector<File>::iterator childBegin();
  • trunk/gsinstaller/fileCopier.cpp

    r1536 r1541  
    3636char *fileCopySet::destination(File *file)
    3737{
    38   const char *oldname = file->getFileName();
     38  const char *oldname = file->cString();
    3939  char *newname = (char *) malloc(strlen(oldname) - strlen(this->sourceDir.cString()) + strlen(this->destDir.cString()) + 1);
    4040
     
    6262  destination = this->destination(file);
    6363
     64    FilePath destPath(destination);
     65  FilePath *destDir = destPath.parent();
     66  if (!destDir->ensureWriteablePath())
     67  { delete destDir;
     68    return false;
     69  }
     70  delete destDir;
     71
    6472  // get read and write file handles
    65   read_handle = fopen(file->getFileName(), "rb");
     73  read_handle = fopen(file->cString(), "rb");
    6674  if (read_handle == NULL)
    6775    {
     
    104112  if (monitor != NULL)
    105113    {
    106       monitor->copied(file->getFileName(), destination, false);
     114      monitor->copied(file->cString(), destination, false);
    107115    }
    108116  delete destination;
     
    135143      if (monitor != NULL)
    136144    {
    137       monitor->copied(file->getFileName(), thisDestDir, true);
     145      monitor->copied(file->cString(), thisDestDir, true);
    138146    }
    139147
  • trunk/gsinstaller/gsPlatform.cpp

    r1536 r1541  
    33#define ACCESS_READ 0x01
    44#define ACCESS_WRITE 0x02
     5
     6#include <stdio.h>
    57
    68gsPlatform::gsPlatform()
     
    3840
    3941bool gsPlatform::isUserAdministrator()
    40 { 
     42{
    4143  if (this->isWindowsNT())
    4244    {
     
    4446      PSID adminId;
    4547      PACL aclData;
    46       PSECURITY_DESCRIPTOR psdAdmin;
    47       SID_IDENTIFIER_AUTHORITY systemSidAuthority;
     48      PSECURITY_DESCRIPTOR psdAdmin = NULL;
     49      SID_IDENTIFIER_AUTHORITY systemSidAuthority = SECURITY_NT_AUTHORITY;
    4850      GENERIC_MAPPING genericMapping;
    4951      PRIVILEGE_SET privilegeSet;
    50       DWORD aclSize, status, structureSize;
     52      DWORD aclSize, accessMask, status, structureSize;
    5153      BOOL result;
    5254
     
    5759    {
    5860      if (GetLastError() != ERROR_NO_TOKEN)
    59         {   
     61        {
    6062          return false;
    6163        }
     
    6365      // if we didn't have an access token, take the process token instead
    6466      if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
    65         {   
     67        {
    6668          return false;
    6769        }
     
    7375                    DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
    7476                    &adminId))
    75     {   
     77    {
    7678      return false;
    7779    }
     
    100102      // initalise the acl block
    101103      if (!InitializeAcl(aclData, aclSize, ACL_REVISION2))
    102     {   
    103       return false;
    104     }
     104    {
     105      return false;
     106    }
     107
     108    accessMask = ACCESS_READ | ACCESS_WRITE;
     109
     110
    105111
    106112      // try to add the given item to the Access Control Entry (ACE) list (ACL)
    107       if (!AddAccessAllowedAce(aclData, ACL_REVISION2, ACCESS_READ | ACCESS_WRITE, adminId))
    108     {   
     113      if (!AddAccessAllowedAce(aclData, ACL_REVISION2, accessMask, adminId))
     114    {
    109115      return false;
    110116    }
     
    127133      genericMapping.GenericAll = ACCESS_READ | ACCESS_WRITE;
    128134
     135      structureSize = sizeof(PRIVILEGE_SET);
     136
    129137      // do the actual access check
    130138      if (!AccessCheck (psdAdmin, token, ACCESS_READ, &genericMapping,
    131139            &privilegeSet, &structureSize, &status, &result))
    132     {
    133       return false;
     140    {   return false;
    134141    }
    135142
    136143      // end impersonisation
    137144      RevertToSelf();
     145
     146      LocalFree(psdAdmin);
     147      LocalFree(aclData);
     148      FreeSid(adminId);
    138149      return result;
    139150    }
     
    151162      if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
    152163                &token))
    153     {   
    154       return false;
    155     }
    156      
     164    {
     165      return false;
     166    }
     167
    157168      LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
    158169
  • trunk/gsinstaller/gsProfile.cpp

    r1498 r1541  
    8585                                                                    itemValue.c_str(), this->fileName.c_str()))
    8686    { DWORD error = GetLastError();
    87     char buffer[20];
     87/*      char buffer[20];
    8888    sprintf(buffer, "%lx", error);
    89     MessageBox(0, buffer, "", MB_OK);
     89    MessageBox(0, buffer, "", MB_OK);*/
     90    return false;
    9091  }
    9192  return true;
  • trunk/gsinstaller/gsProgman.cpp

    r1536 r1541  
    158158    LPITEMIDLIST pidl;
    159159
    160     if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) == NOERROR)
    161     { SHGetPathFromIDList(pidl, buffer);
    162 
    163         // Create the folder as required
    164         FilePath *path  = new FilePath(buffer, groupName);
    165       if (!CreateDirectory((char *) path->cString(), NULL))
    166       { // it probably existed already - if so skip it!
    167         DWORD reason = GetLastError();
    168         if (reason != ERROR_ALREADY_EXISTS)
    169         {   return false;
    170         }
     160    if (this->platform->isUserAdministrator())
     161    { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     162        {   return false;
     163      }
     164    }
     165    else
     166    { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     167        {   return false;
     168      }
     169    }
     170    SHGetPathFromIDList(pidl, buffer);
     171
     172    // Create the folder as required
     173    FilePath *path  = new FilePath(buffer, groupName);
     174    if (!CreateDirectory((char *) path->cString(), NULL))
     175    {   // it probably existed already - if so skip it!
     176        DWORD reason = GetLastError();
     177      if (reason != ERROR_ALREADY_EXISTS)
     178      { return false;
    171179      }
    172180    }
     
    200208    FilePath *  fullPath;
    201209
    202       if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    203     { return false;
     210    if (this->platform->isUserAdministrator())
     211    { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     212        { return false;
     213      }
     214    }
     215    else
     216    { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     217        { return false;
     218      }
    204219      }
    205220
    206221        SHGetPathFromIDList(pidl, buffer);
    207         fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), ".lnk");
     222        fullPath    = new FilePath(4, buffer, groupName.c_str(), iconName.c_str(), "!.lnk");
    208223
    209224    // check if the shortcut already exists then don't create this again
     
    279294    LPITEMIDLIST pidl;
    280295
    281     if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) == NOERROR)
    282     { SHGetPathFromIDList(pidl, buffer);
    283 
    284         // Create the folder as required
    285         FilePath *path  = new FilePath(buffer, groupName);
    286       if (!RemoveDirectory((char *) path->cString()))
    287       { // TODO: find cause of failure to remove
    288         DWORD reason = GetLastError();
    289         if (reason != 0)
    290         {   return false;
    291         }
     296    if (this->platform->isUserAdministrator())
     297    { if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     298        {   return false;
     299      }
     300    }
     301    else
     302    { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     303        {   return false;
     304      }
     305    }
     306    SHGetPathFromIDList(pidl, buffer);
     307
     308    // Create the folder as required
     309    FilePath *path  = new FilePath(buffer, groupName);
     310    if (!RemoveDirectory((char *) path->cString()))
     311    {   // TODO: find cause of failure to remove
     312        DWORD reason = GetLastError();
     313      if (reason != 0)
     314      { return false;
    292315      }
    293316    }
     
    316339    FilePath *  fullPath;
    317340
    318       if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
    319     { return false;
    320       }
     341    // if the user is adminstrator, take the folder from the common programs folder
     342    // (in the "All Users" profile)
     343    if (this->platform->isUserAdministrator())
     344    {   if (SHGetSpecialFolderLocation(0, CSIDL_COMMON_PROGRAMS, &pidl) != NOERROR)
     345        {   return false;
     346            }
     347    }
     348    // otherwise get it from the user's own programs folder in their profile
     349    else
     350    { if (SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, &pidl) != NOERROR)
     351        { return false;
     352      }
     353    }
    321354
    322355    // get path of folder from shell
  • trunk/gsinstaller/gsinstall.cpp

    r1539 r1541  
    3838bool config_complete = false;
    3939
     40dirSelector *rootSelector = NULL;
     41
    4042typedef vector<dirSelector *> dirSelVector;
    4143
    4244class GSInstall : public installManager
    43 { 
     45{
    4446private:
    4547  configureFile *configFile; // the installation configure file
     
    680682      { case PSN_SETACTIVE:
    681683        {   dirSelector *selector = ((dirSelector *) GetWindowLong(Dialog, GWL_USERDATA));
     684
     685            // bodge to set the dialogue path to the correct value
     686            if (selector != rootSelector)
     687          { selector->setPath(rootSelector->selectedPath());
     688            SetDlgItemText(Dialog, dirpath_PATH, selector->selectedPath());
     689          }
     690
    682691            if (selector->isFinal())
    683692            { PropSheet_SetWizButtons(GetParent(Dialog), PSWIZB_BACK | PSWIZB_FINISH);
     
    734743{ GSInstall_dirPathData *data = new GSInstall_dirPathData;
    735744
     745    // create the directory Selector
    736746    data->dirSelect     = new dirSelector(prompt, optPrompt, title, installer.installPath());
    737747  data->dirSelect->setFinal(isFinal);
    738748
     749  // if there is no extant root selector, make this it
     750  if (rootSelector == NULL)
     751  { rootSelector = data->dirSelect;
     752  }
     753
     754  // add this directory selector to the installer
    739755  installer.addSelectedDir(data->dirSelect);
    740756
     757  // set up the rest of the page
    741758    ppage.dwSize        = sizeof(PROPSHEETPAGE);
    742759    ppage.dwFlags       = PSP_USETITLE;
     
    788805    }
    789806  else // cheat as the executable etc. is already installed
    790     { 
     807    {
    791808      pshead.ppsp = &ppage[1];
    792809    }
     
    815832
    816833long FAR PASCAL GSInstallWindProc(HWND Window, WORD Message, WPARAM wParameter, LPARAM lParameter)
    817 { 
     834{
    818835  long reply = 0;
    819836
     
    830847
    831848    case WM_USER:
    832     { 
     849    {
    833850      // uninstall action
    834851      if (strstr(app_cmdLine, "-u") != NULL)
     
    10071024 
    10081025  //  config_init("ReTreeval");
    1009  
     1026
    10101027  //  accel = LoadAccelerators(Current, "ReTreevalMenu");
    10111028
  • trunk/gsinstaller/launchApp.cpp

    r1498 r1541  
    5353  }
    5454
     55  MessageBox(0, exePath.cString(), runLine.c_str(), MB_OK);
     56
    5557    // execute the process
    5658  if (CreateProcess((LPSTR) exePath.cString(),
    57                                     runLine != "" ? (LPSTR) runLine.c_str() : NULL,
     59                                    (runLine != "" && false) ? (LPSTR) runLine.c_str() : NULL,
    5860                    NULL, NULL, FALSE, 0, NULL, NULL,
    5961                    &startup, &process) == 0)
    6062  { DWORD   error   = GetLastError();
     63    MessageBox(0, "Failed", "Failed", MB_OK);
    6164    return -2;
    6265  }
  • trunk/gsinstaller/registry.cpp

    r1536 r1541  
    2222  LONG reply;
    2323
    24   reply = RegOpenKeyEx(key, name, 0, KEY_QUERY_VALUE, keyout);
     24  reply = RegOpenKeyEx(key, name, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, keyout);
    2525  if (reply != ERROR_SUCCESS)
    2626    {
Note: See TracChangeset for help on using the changeset viewer.