home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / winpref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.2 KB  |  155 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "windows.h"
  20. #include "jsapi.h"
  21. #include "xp_core.h"
  22. #include "xp_mcom.h"
  23. #include "prefapi.h"
  24.  
  25. extern HINSTANCE hAppInst;
  26.  
  27. int pref_InitInitialObjects(JSContext *js_context,JSObject *js_object) {
  28.     int ok;
  29.     jsval result;
  30.     HRSRC hFound;
  31.     HGLOBAL hRes;
  32.     char * lpBuff = NULL;
  33.     XP_File fp;
  34.     XP_StatStruct stats;
  35.     long fileLength;
  36.  
  37.     if (!(js_context&&js_object)) return FALSE;
  38.  
  39.     hFound = FindResource(hAppInst, "init_prefs", RT_RCDATA);
  40.     hRes = LoadResource(hAppInst, hFound);
  41.     lpBuff = (char *)LockResource(hRes);
  42.     if (lpBuff) {
  43.         ok = JS_EvaluateScript(js_context,js_object,
  44.                   lpBuff, strlen(lpBuff), NULL, 0,
  45.                   &result);
  46.     } 
  47.     else ok = JS_FALSE;
  48.  
  49. #ifndef XP_WIN32    
  50.     UnlockResource(hRes);
  51.     FreeResource(hRes);
  52. #endif
  53.  
  54. #ifdef DEBUG
  55.     if (!ok) {
  56.         MessageBox(NULL,"Initial preference resource failed!  Is there a bug in initpref.js? -- Aborting","Debug Error!", MB_OK);
  57.         return ok;
  58.     }
  59. #endif
  60.  
  61.  
  62.     hFound = FindResource(hAppInst, "all_prefs", RT_RCDATA);
  63.     hRes = LoadResource(hAppInst, hFound);
  64.     lpBuff = (char *)LockResource(hRes);
  65.     if (lpBuff) {
  66.         ok = JS_EvaluateScript(js_context,js_object,
  67.                   lpBuff, strlen(lpBuff), NULL, 0,
  68.                   &result);
  69.     } 
  70.     else ok = JS_FALSE;
  71. #ifndef XP_WIN32    
  72.     UnlockResource(hRes);
  73.     FreeResource(hRes);
  74. #endif
  75.  
  76.     hFound = FindResource(hAppInst, "mailnews_prefs", RT_RCDATA);
  77.     hRes = LoadResource(hAppInst, hFound);
  78.     lpBuff = (char *)LockResource(hRes);
  79.     if (lpBuff) {
  80.         ok = JS_EvaluateScript(js_context,js_object,
  81.                   lpBuff, strlen(lpBuff), NULL, 0,
  82.                   &result);
  83.     } 
  84.     else ok = JS_FALSE;
  85. #ifndef XP_WIN32    
  86.     UnlockResource(hRes);
  87.     FreeResource(hRes);
  88. #endif
  89.  
  90.     hFound = FindResource(hAppInst, "editor_prefs", RT_RCDATA);
  91.     hRes = LoadResource(hAppInst, hFound);
  92.     lpBuff = (char *)LockResource(hRes);
  93.     if (lpBuff) {
  94.         ok = JS_EvaluateScript(js_context,js_object,
  95.                   lpBuff, strlen(lpBuff), NULL, 0,
  96.                   &result);
  97.     } 
  98.     else ok = JS_FALSE;
  99. #ifndef XP_WIN32    
  100.     UnlockResource(hRes);
  101.     FreeResource(hRes);
  102. #endif
  103.  
  104.     hFound = FindResource(hAppInst, "security_prefs", RT_RCDATA);
  105.     hRes = LoadResource(hAppInst, hFound);
  106.     lpBuff = (char *)LockResource(hRes);
  107.     if (lpBuff) {
  108.         ok = JS_EvaluateScript(js_context,js_object,
  109.                   lpBuff, strlen(lpBuff), NULL, 0,
  110.                   &result);
  111.     } 
  112.     else ok = JS_FALSE;
  113. #ifndef XP_WIN32    
  114.     UnlockResource(hRes);
  115.     FreeResource(hRes);
  116. #endif
  117.  
  118.     hFound = FindResource(hAppInst, "win_prefs", RT_RCDATA);
  119.     hRes = LoadResource(hAppInst, hFound);
  120.     lpBuff = (char *)LockResource(hRes);
  121.     if (lpBuff) {
  122.         ok = JS_EvaluateScript(js_context,js_object,
  123.                   lpBuff, strlen(lpBuff), NULL, 0,
  124.                   &result);
  125.     } 
  126.     else ok = JS_FALSE;
  127. #ifndef XP_WIN32    
  128.     UnlockResource(hRes);
  129.     FreeResource(hRes);
  130. #endif
  131.  
  132. #ifdef DEBUG
  133.     if (!ok) MessageBox(NULL,"Initial preference resource failed!  Is there a bug in all.js or winpref.js? -- Aborting","Debug Error!", MB_OK);
  134. #endif
  135.  
  136.     hFound = FindResource(hAppInst, "config_prefs", RT_RCDATA);
  137.     hRes = LoadResource(hAppInst, hFound);
  138.     lpBuff = (char *)LockResource(hRes);
  139.     if (lpBuff) {
  140.         ok = JS_EvaluateScript(js_context,js_object,
  141.                   lpBuff, strlen(lpBuff), NULL, 0,
  142.                   &result);
  143.     } else ok = JS_FALSE;
  144. #ifndef XP_WIN32    
  145.     UnlockResource(hRes);
  146.     FreeResource(hRes);
  147. #endif
  148.  
  149. #ifdef DEBUG
  150.     //if (!ok) MessageBox(NULL,"Initial preference resource failed!  Is there a bug in all.js? -- Aborting","Debug Error!", MB_OK);
  151. #endif
  152.  
  153.     return ok;
  154. }
  155.