/* This file is part of Lcrzo.
*/

int lcrzo_windows_getsystemversion(lcrzo_uint32 *psystemversion,
				   lcrzo_uint32 *pspmajor,
				   lcrzo_uint32 *pspminor,
				   lcrzo_uint32 *pbuild)
#if defined LCRZODEF_SYSTEM_Unix
{
  return(LCRZO_ERR_IEUNIMPLEMENTED);
  /* for the compiler warning */
  psystemversion=psystemversion;
  pspmajor=pspmajor;
  pspminor=pspminor;
  pbuild=pbuild;
}
#elif defined LCRZODEF_SYSTEM_Windows
{ OSVERSIONINFO verInfo;
  OSVERSIONINFOEX verInfoEx;
  lcrzo_uint32 systemversion, spmajor, spminor, build;

  /* obtain the version */
  verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  if (!GetVersionEx(&verInfo))
  { if (psystemversion!=NULL)
      *psystemversion=LCRZO_WINDOWS_SYSTEMVERSION_unknown;
    if ( pspmajor!=NULL ) *pspmajor=0;
    if ( pspminor!=NULL ) *pspminor=0;
    if ( pbuild!=NULL ) *pbuild=0;
    return(LCRZO_ERR_OK);
  }

  /*
  lcrzo_uint32_print("dwMajorVersion : ", verInfo.dwMajorVersion, "%d", "\n");
  lcrzo_uint32_print("dwMinorVersion : ", verInfo.dwMinorVersion, "%d", "\n");
  lcrzo_uint32_print("dwBuildNumber : ", verInfo.dwBuildNumber, "%d", "\n");
  lcrzo_uint32_print("dwPlatformId : ", verInfo.dwPlatformId, "%d", "\n");
  printf("szCSDVersion :   %s\n",  verInfo.szCSDVersion);
  */

  /* set version */
  systemversion=LCRZO_WINDOWS_SYSTEMVERSION_unknown;

  /* set service pack */
  spmajor=0;
  spminor=0;

  /* set build number */
  build=verInfo.dwBuildNumber;

  /* update these fields */
  switch (verInfo.dwPlatformId)
  { case VER_PLATFORM_WIN32s:
      systemversion=LCRZO_WINDOWS_SYSTEMVERSION_31;
      break;

    case VER_PLATFORM_WIN32_WINDOWS:
      build = 0xFFFF & build;
      if ( verInfo.dwMajorVersion == 4 && 
           verInfo.dwMinorVersion == 0 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_95;
        if ( verInfo.szCSDVersion[1] == 'A' )
        { spmajor=1; /* no sure this exists */
	}
        else if ( verInfo.szCSDVersion[1] == 'B' )
        { spmajor=2; /* OSR-2 */
	}
        else if ( verInfo.szCSDVersion[1] == 'C' )
	{ spmajor=2;
          spminor=5;
	}
      }
      else if ( verInfo.dwMajorVersion == 4 && 
                verInfo.dwMinorVersion == 10 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_98;
        if ( verInfo.szCSDVersion[1] == 'A' )
	{ spmajor=1;
	}
      }
      else if ( verInfo.dwMajorVersion == 4 && 
                verInfo.dwMinorVersion == 90 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_me;
      }
      break;

    case VER_PLATFORM_WIN32_NT:
      if ( verInfo.dwMajorVersion == 3 && 
           verInfo.dwMinorVersion == 50 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_nt350;
      }
      else if ( verInfo.dwMajorVersion == 3 && 
                verInfo.dwMinorVersion == 51 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_nt351;
      }
      else if (verInfo.dwMajorVersion == 4)
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_nt4;
      }
      else if ( verInfo.dwMajorVersion == 5 && 
                verInfo.dwMinorVersion == 0 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_2k;
      }
      else if ( verInfo.dwMajorVersion == 5 && 
                verInfo.dwMinorVersion == 1 )
      { systemversion=LCRZO_WINDOWS_SYSTEMVERSION_xp;
      }
      /* set service pack */
      verInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
      if (GetVersionEx((LPOSVERSIONINFO)&verInfoEx))
      { spmajor=verInfoEx.wServicePackMajor;
        spminor=verInfoEx.wServicePackMinor;
      }
      break;
  }

  if (psystemversion!=NULL) *psystemversion=systemversion;
  if (pspmajor!=NULL) *pspmajor=spmajor;
  if (pspminor!=NULL) *pspminor=spminor;
  if (pbuild!=NULL) *pbuild=build;

  return(LCRZO_ERR_OK);
}
#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif



