Thread: Issues

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    8

    Issues

    I have this C++ program that checks if certain files exist, and then it installs them if they arent. The problem is it only works on NT/2000/XP systems

    on other systems it works to the point that it doesnt find the files, installs them all, and then finishes correctly, but the next time its run, it does the same thing.


    Well i read the post on posting, so ill put it in code tags instead:

    Code:
    #include <sys/stat.h>
    #include <stdio.h>
    #include <conio.h>
    #include <process.h>
    
    bool fileExists (char * fileName)
    {
       struct stat buf;
       int i = stat ( fileName, &buf );
         if ( i == 0 )
         {
           return true;
         }
         return false;
           
    }
    
    void Launch(char * FileName)
    {
       system(FileName);
    }
    
    int askDir(void)
    {
       char answer;
       
       answer='0';
    
       while ((answer != '1') && (answer != '2'))
       {
         printf("Both WinNT and Windows directory exist!\n");
         printf("Please choose which directory Windows is installed in.\n");
         printf("\n");
         printf("1) Windows\n");
         printf("2) WinNt\n");
         printf("\n");
    
         answer=(char)getch();
    
         if (answer=='1')
         {
         	return(1);
         }
         else if (answer=='2')
         {
         	return(2);
         }
         else
         {
             Launch("cls");
             printf("Invalid Response\n\n");
         }
    
       }
    
       return(0);
    }
    
    int determineDir(void){
       if (fileExists("C:/Windows") & fileExists("C:/Winnt"))
       {
          //printf("Both WINNT and WINDOWS directory exist");
          return(3);
       }
       else if(fileExists("C:/Windows"))
       {
          //printf("Windows Directory Only");
          return(1);
       }
       else if(fileExists("C:/Winnt"))
       {
          //printf("Winnt Directory Only");
          return(2);
       }
    
       return(0);
    }
    
    
    bool LookFiles(void)
    {
       int i=determineDir();
       bool install;
    
       install=false;
    
       if (i==3)
       {
       	i=askDir();
       }
    
       if (i==1)
       {
          if (fileExists("C:/Windows/msvbvm60.dll") || fileExists("C:/Windows/system32/msvbvm60.dll"))
          {
             printf("Visual Basic Runtimes Found, Skipping Installation\n");
          }
          else
          {
             Launch("vbrun60sp5.exe");
             printf("Visual Basic Runtimes Installed\n");
             install=true;
          }
    
          if (fileExists("C:/Windows/mscomctl.ocx") || fileExists("C:/Windows/system32/mscomctl.ocx"))
          {
             printf("Microsoft Common Controls Found, Skipping Installation\n");
          }
          else
          {
              Launch("missingfilesetup.exe");
              printf("Common Controls Installed\n");
              install=true;
          }
    
          if (fileExists("C:/Windows/talctl32.ocx") || fileExists("C:/Windows/system32/tabctl32.ocx"))
          {
             printf("Microsoft Tab Control Found, Skipping Installation\n");
          }
          else
          {
              Launch("tabinstall.exe /silent");
              printf("Tab Control Installed\n");
              install=true;
          }
       }
    
       if (i==2)
       {
          if (fileExists("C:/WinNT/msvbvm60.dll") || fileExists("C:/WinNT/system32/msvbvm60.dll"))
          {
             printf("Visual Basic Runtimes Found, Skipping Installation\n");
          }
          else
          {
             Launch("vbrun60sp5.exe");
             printf("Visual Basic Runtimes Installed\n");
             install=true;
          }
    
          if (fileExists("C:/WinNT/mscomctl.ocx") || fileExists("C:/WinNT/system32/mscomctl.ocx"))
          {
             printf("Microsoft Common Controls Found, Skipping Installation\n");
          }
          else
          {
             Launch("missingfilesetup.exe");
             printf("Common Controls Installed\n");
             install=true;
          }
    
          if (fileExists("C:/WinNT/talctl32.ocx") || fileExists("C:/WinNT/system32/tabctl32.ocx"))
          {
             printf("Microsoft Tab Control Found, Skipping Installation\n");
          }
          else
          {
             Launch("tabinstall.exe /silent");
             printf("Tab Control Installed\n");
             install=true;
          }
       }
       
       return(install);
    
    }
    
    int main(void)   {
    
       bool Install;
    
       Launch("cls");
       Install=LookFiles();
       printf("\n\n");
    
       if (Install)
       {
        printf("Files Have Finished Installing. Press Any Key To Continue");
        getch();
       }
       else
       {
        printf("No Files Were Installed, Ending Application");
       }
    
       execl("utilities","utilities",(char *)0);
    
       return (0);
    
    
    
    }
    Last edited by Tamandt; 09-09-2004 at 10:36 AM.

  2. #2
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    ok I saw your program,Why you don't use the header #include <iostream>?, but why you use printf instead of cout??? and a recommendation that I saw in several books that I have read says that the function main (preferent) has to be at first, just for comfort, and the other functions below, well I didnt know much , but hopefuly in the further I would help you better than today
    Bye
    Have I crossed the line?

  3. #3
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Try changing this:

    Code:
    int determineDir(void){
       if (fileExists("C:/Windows") & fileExists("C:/Winnt"))
    to this:

    Code:
    int determineDir(void){
       if (fileExists("C:/Windows") && fileExists("C:/Winnt"))
    That might help.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    Quote Originally Posted by abyssphobia
    ok I saw your program,Why you don't use the header #include <iostream>?, but why you use printf instead of cout??? and a recommendation that I saw in several books that I have read says that the function main (preferent) has to be at first, just for comfort, and the other functions below, well I didnt know much , but hopefuly in the further I would help you better than today
    Bye
    Its been three years since ive seen any C at all, but in borland, unless im doing something wrong, if the function is written after main, then it crashes saying the function doesnt exist

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    The reason it says that is you have to put a prototype before main. Example:

    Code:
    #include <iostream>
    using namespace std;
    
    void HelloWorld(void);
    
    int main(void) {
      HelloWorld();
      return 0;
    }
    
    void HelloWorld(void) {
      cout << "Hello world" << endl;
    }

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    8

    Shucks

    Ya know what, i totally forgot about doing that, do you know how many times i had to move functions cause they didnt exist yet, thanks for reminding me.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    8

    One more side note

    I will rewrite it with th && (my mistake) and using cout, and with main at the top with prototypes.

    One other note though, when compiled on NT/2000/XP my program works on NT based os and gives an illegal operation in 9X oses.

    if compiled in 9x, it works on all

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Could it be an issue with using '/' vs. '\\' in all of your paths?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    Quote Originally Posted by hk_mp5kpdw
    Could it be an issue with using '/' vs. '\\' in all of your paths?

    Good point, i will try that tonight too, but also when i try to run a file with /silent option, do i use a single slash for that?

  10. #10
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    If it's a forward slash, i.e. '/', you only need one.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    Ok Thanks all, here is the newly updated code, which one again has the following problems.

    Compiling OS
    ----------------
    XP-Runs only under NT based systems, illegal ops in 9x
    -Detects files properly on NT based OS's

    9X-Runs under all OS's but always says the files dont exist.
    -Detects files properly on NT based OS's

    Heres the updated code:

    Code:
    #include <sys/stat>
    #include <conio>
    #include <process>
    #include <iostream>
    
    using namespace std;
    
    bool fileExists (char * fileName);
    void Launch(char * FileName);
    int askDir(void);
    int determineDir(void);
    bool LookFiles(void);
    
    int main(void)   {
    
       bool Install;
    
       Launch("cls");
       Install=LookFiles();
       cout << endl << endl;
    
       if (Install)
       {
        cout << "Files Have Finished Installing. Press Any Key To Continue" << endl;
        getch();
       }
       else
       {
        cout << "No Files Were Installed, Ending Application" << endl;
       }
    
       execl("utilities","utilities",(char *)0);
    
       return (0);
    
    
    
    }
    
    bool fileExists (char * fileName)
    {
       struct stat buf;
       int i = stat ( fileName, &buf );
         if ( i == 0 )
         {
           return true;
         }
         return false;
           
    }
    
    void Launch(char * FileName)
    {
       system(FileName);
    }
    
    int askDir(void)
    {
       char answer;
       
       answer='0';
    
       while ((answer != '1') && (answer != '2'))
       {
         cout << "Both WinNT and Windows directory exist!" << endl;
         cout << "Please choose which directory Windows is installed in." << endl;
         cout << endl;
         cout << "1) Windows" << endl;
         cout << "2) WinNt" << endl << endl;
    
         answer=(char)getch();
    
         if (answer=='1')
         {
         	return(1);
         }
         else if (answer=='2')
         {
         	return(2);
         }
         else
         {
             Launch("cls");
             cout << "Invalid Response" << endl << endl;
         }
    
       }
    
       return(0);
    }
    
    int determineDir(void){
       if (fileExists("C:\\Windows") && fileExists("C:\\Winnt"))
       {
          //printf("Both WINNT and WINDOWS directory exist");
          return(3);
       }
       else if(fileExists("C:\\Windows"))
       {
          //printf("Windows Directory Only");
          return(1);
       }
       else if(fileExists("C:\\Winnt"))
       {
          //printf("Winnt Directory Only");
          return(2);
       }
    
       return(0);
    }
    
    
    bool LookFiles(void)
    {
       int i=determineDir();
       bool install;
    
       install=false;
    
       if (i==3)
       {
       	i=askDir();
       }
    
       if (i==1)
       {
          if (fileExists("C:\\Windows\\msvbvm60.dll") || fileExists("C:\\Windows\\system32\\msvbvm60.dll"))
          {
             cout << "Visual Basic Runtimes Found, Skipping Installation" << endl;
          }
          else
          {
             Launch("vbrun60sp5.exe");
             cout << "Visual Basic Runtimes Installed" << endl;
             install=true;
          }
    
          if (fileExists("C:\\Windows\\mscomctl.ocx") || fileExists("C:\\Windows\\system32\\mscomctl.ocx"))
          {
             cout << "Microsoft Common Controls Found, Skipping Installation";
             cout << endl;
          }
          else
          {
              Launch("missingfilesetup.exe");
              cout << "Common Controls Installed" << endl;
              install=true;
          }
    
          if (fileExists("C:\\Windows\\talctl32.ocx") || fileExists("C:\\Windows\\system32\\tabctl32.ocx"))
          {
             cout << "Microsoft Tab Control Found, Skipping Installation" << endl;
          }
          else
          {
              Launch("tabinstall.exe /silent");
              cout << "Tab Control Installed" << endl;
              install=true;
          }
       }
    
       if (i==2)
       {
          if (fileExists("C:\\WinNT\\msvbvm60.dll") || fileExists("C:\\WinNT\\system32\\msvbvm60.dll"))
          {
             cout << "Visual Basic Runtimes Found, Skipping Installation" << endl;
          }
          else
          {
             Launch("vbrun60sp5.exe");
             cout << "Visual Basic Runtimes Installed" << endl;
             install=true;
          }
    
          if (fileExists("C:\\WinNT\\mscomctl.ocx") || fileExists("C:\\WinNT\\system32\\mscomctl.ocx"))
          {
             cout << "Microsoft Common Controls Found, Skipping Installation" << endl;
          }
          else
          {
             Launch("missingfilesetup.exe");
             cout << "Common Controls Installed" << endl;
             install=true;
          }
    
          if (fileExists("C:\\WinNT\\talctl32.ocx") || fileExists("C:\\WinNT\\system32\\tabctl32.ocx"))
          {
             cout << "Microsoft Tab Control Found, Skipping Installation" << endl;
          }
          else
          {
             Launch("tabinstall.exe /silent");
             cout << "Tab Control Installed" << endl;
             install=true;
          }
       }
       
       return(install);
    
    }

  12. #12
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Here is my two centavos...


    Code:
    bool fileExists (char * fileName)
    {
       struct stat buf;
       int i = stat ( fileName, &buf );
         if ( i == 0 )
         {
           return true;
         }
         return false;
           
    }


    could be written this way...
    Code:
    bool fileExists (char * fileName)
    {
       struct stat buf;
       int i = stat ( fileName, &buf );
         
              return  ( i == 0 );
    }

    Where the implied boolean function will return true when the condition is met... otherwise will return false.

    tip o' the day.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  13. #13
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    btw... after reviewing the above algorithm... i noticed that you lack of an associated else makes your code not cool..


    because if the first if condition is met... it will return true.... but then will continue to process your next line of code.. which is to return false.... which will make the function invalid.. by definition.. a function is not a function if it resolves to more than one return value

    Using else will ensure that either 'one or the other' (but not both) will occur.
    Last edited by The Brain; 09-10-2004 at 01:10 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Quote Originally Posted by The Brain
    btw... after reviewing the above algorithm... i noticed that you lack of an associated else makes your code not cool..


    because if the first if condition is met... it will return true.... but then will continue to process your next line of code.. which is to return false.... which will make the function invalid.. by definition.. a function is not a function if it resolves to more than one return value

    Using else will ensure that either 'one or the other' (but not both) will occur.
    No, that part of the code is perfecly fine as is. When he calls return he returns from that function and no more line in the function will run.

  15. #15
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    oh.. my bad
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iterator issues
    By Elkvis in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2009, 09:52 PM
  2. issues in float division a/b
    By George2 in forum C# Programming
    Replies: 17
    Last Post: 04-24-2008, 06:15 AM
  3. Speed issues
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-22-2005, 03:06 AM
  4. Visual Age C++ to MS VC++ conversion issues?
    By Ruchikar in forum Windows Programming
    Replies: 3
    Last Post: 08-10-2003, 09:54 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM