home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / ownedlst.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  21.7 KB  |  703 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 "stdafx.h"
  20.  
  21. #include "helper.h"
  22. #include "ownedlst.h"
  23. #include "ngdwtrst.h"
  24. #include "mozilla.h"
  25. #include "shcut.h"
  26.  
  27. // Registry key constants
  28. static const CString strMARKUP_KEY = "NetscapeMarkup";
  29. static const CString strOPEN_CMD_FMT = "%s\\shell\\open\\command";
  30. static const CString strDDE_EXEC_FMT = "%s\\shell\\open\\ddeexec";
  31. static const CString strDDE_APP_FMT = "%s\\shell\\open\\ddeexec\\Application";
  32. static const CString strDDE_APP_NAME = "NSShell";
  33. static const CString strDDE_OLDAPP_NAME = "Netscape";
  34. static const CString strDEF_ICON_FMT = "%s\\DefaultIcon";
  35. static const CString strDDE_EXEC_VALUE = "%1";
  36. static const CString strDDE_TOPIC_FMT = "%s\\shell\\open\\ddeexec\\Topic";
  37. static const CString strEDIT_CMD_FMT = "%s\\shell\\edit\\command";
  38.  
  39. COwnedLostItem::COwnedLostItem(CString mimeType)
  40. :m_csMimeType(mimeType), m_bIgnored(FALSE), m_bBroken(FALSE)
  41. {
  42.     SetHandledViaNetscape();    
  43. }
  44.  
  45. COwnedLostItem::COwnedLostItem(CString mimeType, CString ignored)
  46. :m_csMimeType(mimeType), m_bBroken(FALSE)
  47. {
  48.     m_bIgnored = (ignored == "Ignored");
  49.     SetHandledViaNetscape();
  50. }
  51.  
  52. void COwnedLostItem::GiveControlToNetscape()
  53. {    
  54.     char buffer[_MAX_PATH];
  55.     ::GetModuleFileName(theApp.m_hInstance, buffer, _MAX_PATH);
  56.     
  57.     // Get the app's directory into a short file name
  58.     char shortBuffer[_MAX_PATH];
  59.     GetShortPathName(buffer, shortBuffer, _MAX_PATH);
  60.  
  61.     CString directoryName(shortBuffer);
  62.     directoryName.MakeUpper();  // This is what we'll write to the registry
  63.  
  64.     CString strValueName, strCmdPath;
  65.  
  66.     // Special Internet Shortcut check
  67.     if (IsInternetShortcut())
  68.     {
  69.         CInternetShortcut internetShortcut;
  70.         if (internetShortcut.ShellSupport())
  71.         {
  72.             // Need to take over lots of stuff
  73.             CString strType = GetInternetShortcutFileClass();
  74.             
  75.             // Set the open command path
  76.             strValueName.Format(strOPEN_CMD_FMT, (const char *)strType);
  77.             strCmdPath = directoryName + " -h \"%1\"";
  78.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strCmdPath);
  79.         
  80.             // Set the DDE exec value
  81.             strValueName.Format(strDDE_EXEC_FMT, (const char *)strType);
  82.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_EXEC_VALUE);
  83.  
  84.             // Set the DDE app name
  85.             strValueName.Format(strDDE_APP_FMT, (const char *)strType);
  86.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_APP_NAME);
  87.                             
  88.             // Set the DDE topic
  89.             strValueName.Format(strDDE_TOPIC_FMT, (const char *)strType);
  90.             CString strDDETopic;
  91.             strDDETopic.LoadString(IDS_DDE_OPENURL);
  92.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDETopic);
  93.  
  94.             // Set the Default Icon
  95.             CString strIconPath;
  96.             if ((strType == "news") || (strType == "snews"))
  97.             {
  98.                 // Use the news icon from URL.DLL
  99.                 ::GetSystemDirectory(buffer, _MAX_PATH);
  100.                 strIconPath = CString(buffer) + "\\URL.DLL,1";
  101.             }  
  102.             else
  103.             {
  104.                 // Use the document icon
  105.                 strIconPath = CString(buffer) + ",1";
  106.             }  
  107.             strValueName.Format(strDEF_ICON_FMT, (const char *)strType);
  108.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strIconPath);
  109.             
  110.             // Take over printing (applies to ALL Internet Shortcuts.  If we own one, we'll take
  111.             // over printing for ALL of them).
  112.             CString csMunge = directoryName + " /print(\"%1\")";
  113.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\command", csMunge);
  114.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\ddeexec", "[print(\"%1\")]");
  115.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\print\\ddeexec\\Application", strDDE_APP_NAME);
  116.  
  117.             //  The PrintTo Command.
  118.             csMunge = directoryName + " /printto(\"%1\",\"%2\",\"%3\",\"%4\")";
  119.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\command", csMunge);
  120.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\ddeexec", "[printto(\"%1\",\"%2\",\"%3\",\"%4\")]");
  121.             FEU_RegistryWizard(HKEY_CLASSES_ROOT, "InternetShortcut\\shell\\PrintTo\\ddeexec\\Application", strDDE_APP_NAME);
  122.         }
  123.  
  124.         return;
  125.     }
  126.  
  127.     CPtrList* allHelpers = &(CHelperApp::m_cplHelpers);
  128.  
  129.     for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;)
  130.     {
  131.         CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos);
  132.         CString helperMime(app->cd_item->ci.type);
  133.  
  134.         if (helperMime == m_csMimeType)
  135.         {
  136.             // Found the helper app.  Get the file class.
  137.             CString fileClass(app->strFileClass);
  138.             if (fileClass != "")
  139.             {
  140.                 // We have some registry work to do.
  141.                 // In the case where this is text/html, we point .htm and .html to
  142.                 // NetscapeMarkup.
  143.                 HKEY hKey;
  144.                 DWORD dwDisp;
  145.  
  146.                 if (m_csMimeType == "text/html")
  147.                 {
  148.                     ::RegCreateKeyEx(HKEY_CLASSES_ROOT,
  149.                         ".htm", 0L, NULL,
  150.                         REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  151.                         &hKey, &dwDisp);
  152.                     ::RegSetValueEx(hKey, NULL, 0L, REG_SZ,
  153.                         (const BYTE *)((const char *)strMARKUP_KEY),
  154.                         strMARKUP_KEY.GetLength() + 1);
  155.                     ::RegCloseKey(hKey);
  156.                     
  157.                     ::RegCreateKeyEx(HKEY_CLASSES_ROOT,
  158.                         ".html", 0L, NULL,
  159.                         REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  160.                         &hKey, &dwDisp);
  161.                     ::RegSetValueEx(hKey, NULL, 0L, REG_SZ,
  162.                         (const BYTE *)((const char *)strMARKUP_KEY),
  163.                         strMARKUP_KEY.GetLength() + 1);
  164.                     ::RegCloseKey(hKey);    
  165.                 }
  166.  
  167.                 // In the case where this is application/x-unknown-content-type-NetscapeMarkup, 
  168.                 // we point .shtml to NetscapeMarkup.
  169.                 else if (m_csMimeType == "application/x-unknown-content-type-NetscapeMarkup")
  170.                 {
  171.                     ::RegCreateKeyEx(HKEY_CLASSES_ROOT,
  172.                         ".shtml", 0L, NULL,
  173.                         REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  174.                         &hKey, &dwDisp);
  175.                     ::RegSetValueEx(hKey, NULL, 0L, REG_SZ,
  176.                         (const BYTE *)((const char *)strMARKUP_KEY),
  177.                         strMARKUP_KEY.GetLength() + 1);
  178.                     ::RegCloseKey(hKey);
  179.                     
  180.                 }
  181.  
  182.                 // In all other cases, we should use the existing file class
  183.                 else
  184.                 {
  185.                     // Need to take over lots of stuff
  186.                     CString strType = fileClass;
  187.                     if (strType == "NetscapeMarkup")
  188.                       return; // Don't let ANYTHING mess with NetscapeMarkup.
  189.                               // Someone might point something to it later, and
  190.                               // we don't want this code changing the stuff that's already there.
  191.  
  192.                     // Set the open command path
  193.                     strValueName.Format(strOPEN_CMD_FMT, (const char *)strType);
  194.                     strCmdPath = directoryName + " \"%1\"";
  195.                     FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strCmdPath);
  196.         
  197.                     // Set the DDE exec value
  198.                     strValueName.Format(strDDE_EXEC_FMT, (const char *)strType);
  199.                     FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_EXEC_VALUE);
  200.  
  201.                     // Set the DDE app name
  202.                     strValueName.Format(strDDE_APP_FMT, (const char *)strType);
  203.                     FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDE_APP_NAME);
  204.                             
  205.                     // Set the DDE topic
  206.                     strValueName.Format(strDDE_TOPIC_FMT, (const char *)strType);
  207.                     CString strDDETopic;
  208.                     strDDETopic.LoadString(IDS_DDE_OPENURL);
  209.                     FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strDDETopic);
  210.  
  211.                     // Set the Default Icon
  212.                     CString strIconPath;
  213.                     CString iconString = ",1";
  214.                     if (m_csMimeType == "text/x-javascript" || m_csMimeType == "application/x-javascript")
  215.                         iconString = ",7";
  216.                     else if (m_csMimeType.Left(5) == "image")
  217.                         iconString = ",6";
  218.  
  219.                     strIconPath = CString(buffer) + iconString;
  220.                       
  221.                     strValueName.Format(strDEF_ICON_FMT, (const char *)strType);
  222.                     FEU_RegistryWizard(HKEY_CLASSES_ROOT, strValueName, strIconPath);
  223.                 }
  224.             }
  225.  
  226.             return;
  227.         }
  228.     }
  229.  
  230. }
  231.  
  232. void COwnedLostItem::SetHandledViaNetscape()
  233. {
  234.     m_nHandleMethod = OL_OTHER_APP;
  235.  
  236.     // Get the app's name.
  237.     CString netscapeName;
  238.     char buffer[_MAX_PATH+1];
  239.     ::GetModuleFileName(theApp.m_hInstance, buffer, _MAX_PATH);
  240.     char *pSlash = ::strrchr(buffer, '\\');
  241.     netscapeName = (char*)(pSlash+1);
  242.     netscapeName.MakeUpper();
  243.  
  244.     // Get the app's directory. Adequate heuristic for version-checking Netscape
  245.     CString directoryName(buffer);
  246.     directoryName.MakeUpper();
  247.  
  248.     // Special Internet Shortcut check
  249.     if (IsInternetShortcut())
  250.     {
  251.         CInternetShortcut internetShortcut;
  252.         if (!internetShortcut.ShellSupport())
  253.         {
  254.             m_nHandleMethod = OL_CURRENT_NETSCAPE;
  255.             return;
  256.         }
  257.         
  258.         CString fileClass = GetInternetShortcutFileClass();
  259.         SetHandleMethodViaFileClass(fileClass, netscapeName, directoryName);
  260.         return;
  261.     }
  262.  
  263.     CPtrList* allHelpers = &(CHelperApp::m_cplHelpers);
  264.  
  265.     for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;)
  266.     {
  267.         CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos);
  268.         CString helperMime(app->cd_item->ci.type);
  269.  
  270.         if (helperMime == m_csMimeType)
  271.         {
  272.             // Found the helper app.  See if Netscape is truly handling this mime type.
  273.             CString fileClass(app->strFileClass);
  274.  
  275.             if (fileClass != "")
  276.             {
  277.                 SetHandleMethodViaFileClass(fileClass, netscapeName, directoryName);
  278.                 return;
  279.             }
  280.             else m_bBroken = TRUE; // Treat as if ignored. Don't want to pop up a dialog over this.
  281.  
  282.             if (app->how_handle == HANDLE_VIA_NETSCAPE)
  283.                 m_nHandleMethod = OL_CURRENT_NETSCAPE;
  284.             else m_nHandleMethod = OL_OTHER_APP;
  285.  
  286.             return;
  287.         }
  288.     }
  289.  
  290.     m_bBroken = TRUE; // Didn't even find this mime type. Don't want to fool with it.
  291. }
  292.  
  293. void COwnedLostItem::SetHandleMethodViaFileClass(const CString& fileClass, 
  294.                                                  const CString& netscapeName,
  295.                                                  const CString& directoryName)
  296. {
  297.     // We have a place to look in the registry
  298.     char lpszOpenCommand[_MAX_PATH+1];
  299.  
  300.     CString theString = fileClass + "\\shell\\open\\command";
  301.                 
  302.     LONG size = _MAX_PATH;
  303.     if (::RegQueryValue(HKEY_CLASSES_ROOT, theString, lpszOpenCommand, &size) !=
  304.                         ERROR_SUCCESS)
  305.     {
  306.         m_nHandleMethod = OL_OTHER_APP;
  307.         return;
  308.     }
  309.  
  310.     CString openCommand(lpszOpenCommand);
  311.     openCommand.MakeUpper();
  312.  
  313.     if (openCommand.Find(netscapeName) != -1)
  314.     {
  315.         // Handled by a version of Netscape.
  316.         char shortBuffer[_MAX_PATH];
  317.         GetShortPathName(directoryName, shortBuffer, _MAX_PATH);
  318.         CString shortName(shortBuffer);
  319.         shortName.MakeUpper();
  320.  
  321.         if (openCommand.Find(directoryName) != -1 ||
  322.             openCommand.Find(shortName) != -1)    
  323.         {
  324.             // Handled by current version.
  325.             m_nHandleMethod = OL_CURRENT_NETSCAPE;
  326.         }
  327.         else m_nHandleMethod = OL_OLD_NETSCAPE;
  328.     }
  329.     else m_nHandleMethod = OL_OTHER_APP;
  330. }
  331.  
  332. CString COwnedLostItem::GetInternetShortcutFileClass()
  333. {
  334.     int startIndex = m_csMimeType.Find('-');
  335.     int endIndex = m_csMimeType.ReverseFind('-');
  336.     
  337.     return m_csMimeType.Mid(startIndex+1, endIndex-startIndex-1);
  338. }
  339.  
  340. void COwnedLostItem::FetchPrettyName()
  341. {
  342.     if (IsInternetShortcut())
  343.         m_csPrettyName = MakeInternetShortcutName();
  344.  
  345.     CPtrList* allHelpers = &(CHelperApp::m_cplHelpers);
  346.  
  347.     for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;)
  348.     {
  349.         CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos);
  350.         CString helperMime(app->cd_item->ci.type);
  351.  
  352.         if (helperMime == m_csMimeType)
  353.         {
  354.             CString returnString = app->cd_item->ci.desc;
  355.             if (returnString == "")
  356.                 returnString = "File Type";
  357.  
  358.             if (app->cd_item->num_exts > 0)
  359.             {
  360.                 returnString += " (";
  361.                 for (int i = 0; i < app->cd_item->num_exts; i++)    
  362.                 {
  363.                     returnString += "*.";
  364.                     returnString += app->cd_item->exts[i];
  365.  
  366.                     if (i < app->cd_item->num_exts-1)
  367.                       returnString += "; ";
  368.                 }
  369.                 returnString += ")";
  370.             }
  371.  
  372.             m_csPrettyName = returnString;
  373.         }
  374.     }
  375. }
  376.  
  377. BOOL COwnedLostItem::IsInternetShortcut()
  378. {
  379.     return (m_csMimeType == "application/x-http-protocol" ||
  380.             m_csMimeType == "application/x-https-protocol" ||
  381.             m_csMimeType == "application/x-ftp-protocol" ||
  382.             m_csMimeType == "application/x-news-protocol" ||
  383.             m_csMimeType == "application/x-snews-protocol" ||
  384.             m_csMimeType == "application/x-gopher-protocol");
  385. }
  386.  
  387. CString COwnedLostItem::MakeInternetShortcutName()
  388. {
  389.     CString protocolName = GetInternetShortcutFileClass();
  390.     protocolName.MakeUpper();
  391.  
  392.     return protocolName + CString(" Internet Shortcuts");
  393. }
  394.  
  395. // =====================================================================================
  396. // COWNEDANDLOSTLIST 
  397. // =====================================================================================
  398.  
  399. COwnedAndLostList::~COwnedAndLostList()
  400. {
  401.     int count = m_OwnedList.GetSize();
  402.     for (int i = 0; i < count; i++)
  403.     {
  404.         COwnedLostItem* theItem = (COwnedLostItem*)(m_OwnedList[0]);
  405.         m_OwnedList.RemoveAt(0);
  406.         delete theItem;
  407.     }
  408.  
  409.     count = m_LostList.GetSize();
  410.     for (i = 0; i < count; i++)
  411.     {
  412.         COwnedLostItem* theItem = (COwnedLostItem*)(m_LostList[0]);
  413.         m_LostList.RemoveAt(0);
  414.         delete theItem;
  415.     }
  416. }
  417.  
  418.  
  419. void COwnedAndLostList::ConstructLists()
  420. {
  421.     CString pathString;
  422.     pathString.LoadString(IDS_NETHELP_REGISTRY); // Software\Netscape\Netscape Navigator
  423.  
  424.     // Read in the owned list
  425.     // Look for owned subkey
  426.     // If subkey exists, iterate over its subkeys and build the owned list
  427.     // If subkey does not exist, the owned list should contain a certain
  428.     // list of built-in types.  These are the types that Netscape defends initially.
  429.     HKEY ownedKey, lostKey;
  430.     CString ownerPath = pathString + "Owned";
  431.     LONG result = ::RegOpenKey(HKEY_CURRENT_USER, ownerPath, &ownedKey);
  432.     
  433.     // Prepopulate our list with some types we want to defend.
  434.  
  435.     int dwIndex;
  436.     char nameBuffer[_MAX_PATH];
  437.     unsigned long nameBufferSize, valueBufferSize;
  438.     unsigned char valueBuffer[_MAX_PATH];
  439.     unsigned long typeCodeBuffer = 0;
  440.  
  441.     if (result != ERROR_SUCCESS)
  442.     {
  443.         m_OwnedList.Add(new COwnedLostItem("text/html"));
  444.         m_OwnedList.Add(new COwnedLostItem("image/jpeg"));
  445.         m_OwnedList.Add(new COwnedLostItem("image/pjpeg"));
  446.         m_OwnedList.Add(new COwnedLostItem("image/gif"));
  447.         m_OwnedList.Add(new COwnedLostItem("application/x-javascript"));
  448.         m_OwnedList.Add(new COwnedLostItem("image/x-xbitmap"));
  449.         
  450.         // Be prepared to defend Internet Shortcuts if they are ever installed
  451.         // later! 
  452.         m_OwnedList.Add(new COwnedLostItem("application/x-http-protocol"));
  453.         m_OwnedList.Add(new COwnedLostItem("application/x-https-protocol"));
  454.         m_OwnedList.Add(new COwnedLostItem("application/x-news-protocol"));
  455.         m_OwnedList.Add(new COwnedLostItem("application/x-snews-protocol"));
  456.         m_OwnedList.Add(new COwnedLostItem("application/x-ftp-protocol"));
  457.         m_OwnedList.Add(new COwnedLostItem("application/x-gopher-protocol"));
  458.     }
  459.     else
  460.     {
  461.         // Read in the owned list
  462.         dwIndex = 0;
  463.         valueBufferSize = sizeof(valueBuffer);
  464.         nameBufferSize = sizeof(nameBuffer);
  465.         while (RegEnumValue(ownedKey, dwIndex, nameBuffer, 
  466.                 &nameBufferSize, NULL, &typeCodeBuffer, valueBuffer,
  467.                 &valueBufferSize) != ERROR_NO_MORE_ITEMS)
  468.         {
  469.             m_OwnedList.Add(new COwnedLostItem(nameBuffer, valueBuffer));
  470.             dwIndex++;
  471.             valueBufferSize = sizeof(valueBuffer);
  472.             nameBufferSize = sizeof(nameBuffer);
  473.         }
  474.  
  475.     }
  476.  
  477.     // Read in the lost list
  478.     // Look for lost subkey
  479.     // If subkey exists, iterate over its subkeys and build the lost list
  480.     // If subkey does not exist, the lost list is initially empty.  Do nothing.
  481.     CString lostPath = pathString + "Lost";
  482.     result = ::RegOpenKey(HKEY_CURRENT_USER, lostPath, &lostKey);
  483.     
  484.     if (result == ERROR_SUCCESS)
  485.     {
  486.         // Read in the lost list
  487.         dwIndex = 0;
  488.         valueBufferSize = sizeof(valueBuffer);
  489.         nameBufferSize = sizeof(nameBuffer);
  490.         while (RegEnumValue(lostKey, dwIndex, nameBuffer, 
  491.                 &nameBufferSize, NULL, &typeCodeBuffer, valueBuffer,
  492.                 &valueBufferSize) != ERROR_NO_MORE_ITEMS)
  493.         {
  494.             m_LostList.Add(new COwnedLostItem(nameBuffer, valueBuffer));
  495.             dwIndex++;
  496.             valueBufferSize = sizeof(valueBuffer);
  497.             nameBufferSize = sizeof(nameBuffer);
  498.         }
  499.     }
  500.  
  501.     // Iterate over the owned list. Look up each entry in the helper app list.  If
  502.     // it is not handled by the current Netscape, then move it to the lost list.
  503.     int count = m_OwnedList.GetSize();
  504.     for (int i = 0; i < count; i++)
  505.     {
  506.         COwnedLostItem* theItem = (COwnedLostItem*)(m_OwnedList[i]);
  507.         
  508.         if (theItem->m_nHandleMethod != OL_CURRENT_NETSCAPE)
  509.         {
  510.             // Move to the lost list
  511.             void* thePtr = m_OwnedList[i];
  512.             m_OwnedList.RemoveAt(i);
  513.             m_LostList.Add(thePtr);
  514.             i--;
  515.             count--;
  516.         }
  517.     }
  518.  
  519.     // Iterate over the lost list.  If any entry is now handled by the current Netscape, move it to
  520.     // the owner list
  521.     count = m_LostList.GetSize();
  522.     for (i = 0; i < count; i++)
  523.     {
  524.         COwnedLostItem* theItem = (COwnedLostItem*)(m_LostList[i]);
  525.         
  526.         if (theItem->m_nHandleMethod == OL_CURRENT_NETSCAPE)
  527.         {
  528.             // Move to the owned list
  529.             m_LostList.RemoveAt(i);
  530.             m_OwnedList.Add(theItem);
  531.             i--;
  532.             count--;
  533.         }
  534.     }
  535.  
  536.     // Iterate over all the helper apps and find any additional entries that aren't in the
  537.     // owned list or lost list (and that should be).
  538.     
  539.     CPtrList* allHelpers = &(CHelperApp::m_cplHelpers);
  540.     for (POSITION pos = allHelpers->GetHeadPosition(); pos != NULL;)
  541.     {
  542.         CHelperApp* app = (CHelperApp*)allHelpers->GetNext(pos);
  543.         CString helperMime(app->cd_item->ci.type);
  544.  
  545.         COwnedLostItem theItem(helperMime);
  546.         if (theItem.m_nHandleMethod == OL_CURRENT_NETSCAPE &&
  547.             !IsInOwnedList(helperMime))
  548.         {
  549.             // This should be in the owned list, since we apparently control it.
  550.             COwnedLostItem* realItem = new COwnedLostItem(helperMime);
  551.             m_OwnedList.Add(realItem);
  552.         }
  553.         else if (theItem.m_nHandleMethod == OL_OLD_NETSCAPE &&
  554.             !IsInLostList(helperMime))
  555.         {
  556.             // This item is currently used by the old Netscape.  Let's
  557.             // offer to update to the current version of NS.
  558.             COwnedLostItem* realItem = new COwnedLostItem(helperMime);
  559.             m_LostList.Add(realItem);
  560.         }
  561.     }
  562.  
  563.     // Netscape will automatically wrest control of HTML files from a previous version
  564.     // so we don't REALLY want HTML in our lost list if it is controlled by an older version
  565.     // of netscape.  It should be moved to our OWNED list instead, and the handle method
  566.     // should be updated.
  567.     if (IsInLostList("text/html"))
  568.     {
  569.         COwnedLostItem* theItem = RemoveFromLostList("text/html");
  570.         if (theItem)
  571.         {
  572.             if (theItem->m_nHandleMethod == OL_OLD_NETSCAPE)
  573.             {
  574.                 theItem->m_nHandleMethod = OL_CURRENT_NETSCAPE;
  575.                 m_OwnedList.Add(theItem);  // Move it to the owned list
  576.             }
  577.             else m_LostList.Add(theItem); // Put it back
  578.         }
  579.     }
  580.  
  581.     if (IsInLostList("application/x-unknown-content-type-NetscapeMarkup"))
  582.     {
  583.         COwnedLostItem* theItem = RemoveFromLostList("application/x-unknown-content-type-NetscapeMarkup");
  584.         if (theItem)
  585.         {
  586.             if (theItem->m_nHandleMethod == OL_OLD_NETSCAPE)
  587.             {
  588.                 theItem->m_nHandleMethod = OL_CURRENT_NETSCAPE;
  589.                 m_OwnedList.Add(theItem);  // Move it to the owned list
  590.             }
  591.             else m_LostList.Add(theItem); // Put it back
  592.         }
  593.     }
  594. }
  595.  
  596. void COwnedAndLostList::WriteLists()
  597. {
  598.     // Need to write each of these lists.
  599.     CString pathString;
  600.     pathString.LoadString(IDS_NETHELP_REGISTRY); // Software\Netscape\Netscape Navigator
  601.  
  602.     // Write the ignored list and lost lists
  603.     CString path = pathString + "Lost";
  604.     ::RegDeleteKey(HKEY_CURRENT_USER, path);
  605.  
  606.     HKEY key;
  607.     
  608.     if (::RegCreateKey(HKEY_CURRENT_USER, path, &key) == ERROR_SUCCESS)
  609.     {
  610.         // Write out all the lost elements
  611.         int count = m_LostList.GetSize();
  612.         
  613.         for (int i = 0; i < count; i++)
  614.         {
  615.             COwnedLostItem* theItem = (COwnedLostItem*)(m_LostList[i]);
  616.             CString regValue = theItem->GetRegistryValue();
  617.  
  618.             RegSetValueEx(key, theItem->m_csMimeType, NULL, REG_SZ, 
  619.                 (const unsigned char*)(const char*)regValue, regValue.GetLength() + 1); 
  620.         }
  621.     }
  622.  
  623.     ::RegCloseKey(key);
  624.  
  625.     path = pathString + "Owned";
  626.     ::RegDeleteKey(HKEY_CURRENT_USER, path);
  627.  
  628.     if (::RegCreateKey(HKEY_CURRENT_USER, path, &key) == ERROR_SUCCESS)
  629.     {
  630.         // Write out all the lost elements
  631.         int count = m_OwnedList.GetSize();
  632.         
  633.         for (int i = 0; i < count; i++)
  634.         {
  635.             COwnedLostItem* theItem = (COwnedLostItem*)(m_OwnedList[i]);
  636.             CString regValue = theItem->GetRegistryValue();
  637.  
  638.             RegSetValueEx(key, theItem->m_csMimeType, NULL, REG_SZ, 
  639.                 (const unsigned char*)(const char*)regValue, regValue.GetLength() + 1); 
  640.         }
  641.     }
  642.  
  643.     ::RegCloseKey(key);
  644. }
  645.  
  646.  
  647. BOOL COwnedAndLostList::IsInOwnedList(const CString& mimeType)
  648. {
  649.     int count = m_OwnedList.GetSize();
  650.     for (int i = 0; i < count; i++)
  651.     {
  652.         COwnedLostItem* theItem = (COwnedLostItem*)m_OwnedList[i];
  653.  
  654.         if (theItem->m_csMimeType == mimeType)
  655.             return TRUE;
  656.     }
  657.  
  658.     return FALSE;
  659. }
  660.  
  661. BOOL COwnedAndLostList::IsInLostList(const CString& mimeType)
  662. {
  663.     int count = m_LostList.GetSize();
  664.     for (int i = 0; i < count; i++)
  665.     {
  666.         COwnedLostItem* theItem = (COwnedLostItem*)m_LostList[i];
  667.  
  668.         if (theItem->m_csMimeType == mimeType)
  669.             return TRUE;
  670.     }
  671.  
  672.     return FALSE;
  673. }
  674.  
  675. COwnedLostItem* COwnedAndLostList::RemoveFromLostList(const CString& mimeType)
  676. {
  677.     int count = m_LostList.GetSize();
  678.     for (int i = 0; i < count; i++)
  679.     {
  680.         COwnedLostItem* theItem = (COwnedLostItem*)(m_LostList[i]);
  681.         if (mimeType == theItem->m_csMimeType)
  682.         {
  683.             m_LostList.RemoveAt(i);
  684.             return theItem;
  685.         }
  686.     }
  687.  
  688.     return NULL;
  689. }
  690.  
  691. BOOL COwnedAndLostList::NonemptyLostIgnoredIntersection()
  692. {
  693.     int count = m_LostList.GetSize();
  694.     for (int i = 0; i < count; i++)
  695.     {
  696.         COwnedLostItem* theItem = (COwnedLostItem*)(m_LostList[i]);
  697.         if (!theItem->m_bIgnored && !theItem->m_bBroken)
  698.             return TRUE;
  699.     }
  700.  
  701.     return FALSE;
  702. }
  703.