home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 November / PCWorld_2004-11_cd.bin / software / temacd / poweroff / pwroff30.exe / src / sanity.c < prev    next >
C/C++ Source or Header  |  2003-03-31  |  3KB  |  112 lines

  1. #include "poweroff.h"
  2.  
  3. int SanityCheck(HWND hWnd,PowerSettings *ps,char *str)
  4. {
  5.   Log("SanityCheck start");
  6.   if (ps->who==REMOTE_COMPUTER)
  7.   {
  8.     if (ps->action!=WAKE_ON_LAN)
  9.     {
  10.       if (ps->remote.use_nt)
  11.       {
  12.         if (ps->action!=SHUTDOWN && ps->action!=REBOOT)
  13.         {
  14.           strcpy(str,"Unsupported action for specified remote protocol");
  15.           return 1;
  16.         }
  17.       }
  18.       if (ps->remote.computer_name[0]=='\0')
  19.       {
  20.         strcpy(str,"No remote computer specified");
  21.         return 1;
  22.       }
  23.     }
  24.     else
  25.     {
  26.       if (ps->remote.ip_address[0]=='\0')
  27.       {
  28.         strcpy(str,"No ip address specified");
  29.         return 1;
  30.       }
  31.       if (ps->remote.mac_address[0]=='\0')
  32.       {
  33.         strcpy(str,"No MAC address specified");
  34.         return 1;
  35.       }
  36.       if (ps->remote.subnet_mask[0]=='\0')
  37.       {
  38.         strcpy(str,"No subnet mask specified");
  39.         return 1;
  40.       }
  41.     }
  42.   }
  43.   else if (ps->action==WAKE_ON_LAN)
  44.   {
  45.     strcpy(str,"WAKE-On-LAN requires remote computer");
  46.     return 1;
  47.   }
  48.   if (ps->options.warning && ps->warning.play_sound && ps->warning.sound_file[0]=='\0')
  49.   {
  50.     strcpy(str,"No sound file specified");
  51.     return 1;
  52.   }
  53.   if (ps->options.run_program && ps->program.program[0]=='\0')
  54.   {
  55.     strcpy(str,"No program specified");
  56.     return 1;
  57.   }
  58.   if (ps->when==SCHEDULED && ps->schedule.time.wHour==25 && ps->schedule.schedule!=AFTER_X_SECONDS)
  59.   {
  60.     strcpy(str,"No time specified");
  61.     return 1;
  62.   }
  63.   if (ps->when==SCHEDULED && ps->schedule.schedule==FIXED_DAY && ps->schedule.time.wYear==0)
  64.   {
  65.     strcpy(str,"No date specified");
  66.     return 1;
  67.   }
  68.   if (ps->when==SCHEDULED && ps->schedule.schedule==DAILY && ps->schedule.monday==0 && ps->schedule.tuesday==0 && ps->schedule.wednesday==0 && ps->schedule.thursday==0 && ps->schedule.friday==0 && ps->schedule.saturday==0 && ps->schedule.sunday==0)
  69.   {
  70.     strcpy(str,"No day of the week specified");
  71.     return 1;
  72.   }
  73.   if (ps->when==SCHEDULED && ps->schedule.schedule==DAILY && ps->schedule.week1==0 &&ps->schedule.week2==0 &&ps->schedule.week3==0 &&ps->schedule.week4==0 &&ps->schedule.week5==0)
  74.   {
  75.     strcpy(str,"No week specified");
  76.     return 1;
  77.   }
  78.   if (ps->when==SCHEDULED && ps->schedule.schedule==DAY_OF_MONTH && (ps->schedule.day<=0 || ps->schedule.day>31))
  79.   {
  80.     strcpy(str,"Invalid day specified");
  81.     return 1;
  82.   }
  83.   if (ps->when==SCHEDULED && ps->schedule.schedule==AFTER_X_SECONDS && ps->schedule.seconds<0)
  84.   {
  85.     strcpy(str,"Number of seconds < 0");
  86.     return 1;
  87.   }
  88.   if (ps->when==PROCESS && ps->process.process[0]=='\0')
  89.   {
  90.     strcpy(str,"No process specified");
  91.     return 1;
  92.   }
  93.   if (ps->windowsversion.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
  94.   {
  95.     if (ps->action==LOCK)
  96.     {
  97.       strcpy(str,"Action not supported by this windows version");
  98.       return 1;
  99.     }
  100.   }
  101.   else if (ps->windowsversion.dwPlatformId==VER_PLATFORM_WIN32_NT
  102.         && ps->windowsversion.dwMajorVersion<5)
  103.   {
  104.     if (ps->action==LOCK)
  105.     {
  106.       strcpy(str,"Action not supported by this windows version");
  107.       return 1;
  108.     }
  109.   }
  110.   Log("SanityCheck end");
  111.   return 0;
  112. }