~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/modules/plugin/samples/npthread/windows/plugload.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "windows.h"
 
39
 
 
40
DWORD GetPluginsDir(char * path, DWORD maxsize)
 
41
{
 
42
  if(!path)
 
43
    return 0;
 
44
 
 
45
  path[0] = '\0';
 
46
 
 
47
  DWORD res = GetModuleFileName(NULL, path, maxsize);
 
48
  if(res == 0)
 
49
    return 0;
 
50
 
 
51
  if(path[strlen(path) - 1] == '\\')
 
52
    path[lstrlen(path) - 1] = '\0';
 
53
 
 
54
  char *p = strrchr(path, '\\');
 
55
 
 
56
  if(p)
 
57
    *p = '\0';
 
58
 
 
59
  strcat(path, "\\plugins");
 
60
 
 
61
  res = strlen(path);
 
62
  return res;
 
63
}
 
64
 
 
65
HINSTANCE LoadRealPlugin(char * mimetype)
 
66
{
 
67
  if(!mimetype || !strlen(mimetype))
 
68
    return NULL;
 
69
 
 
70
  BOOL bDone = FALSE;
 
71
  WIN32_FIND_DATA ffdataStruct;
 
72
 
 
73
  char szPath[_MAX_PATH];
 
74
  char szFileName[_MAX_PATH];
 
75
 
 
76
  GetPluginsDir(szPath, _MAX_PATH);
 
77
 
 
78
  strcpy(szFileName, szPath);
 
79
  strcat(szFileName, "\\00*");
 
80
 
 
81
  HANDLE handle = FindFirstFile(szFileName, &ffdataStruct);
 
82
  if(handle == INVALID_HANDLE_VALUE) {
 
83
    FindClose(handle);
 
84
    return NULL;
 
85
  }
 
86
 
 
87
  DWORD versize = 0L;
 
88
  DWORD zero = 0L;
 
89
  char * verbuf = NULL;
 
90
 
 
91
  do {
 
92
    strcpy(szFileName, szPath);
 
93
    strcat(szFileName, "\\");
 
94
    strcat(szFileName, ffdataStruct.cFileName);
 
95
    if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
 
96
      versize = GetFileVersionInfoSize(szFileName, &zero);
 
97
            if (versize > 0)
 
98
                    verbuf = new char[versize];
 
99
      else 
 
100
        continue;
 
101
 
 
102
      if(!verbuf)
 
103
                    continue;
 
104
 
 
105
      GetFileVersionInfo(szFileName, NULL, versize, verbuf);
 
106
 
 
107
      char *mimetypes = NULL;
 
108
      UINT len = 0;
 
109
 
 
110
      if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len)
 
111
         || !mimetypes || !len) {
 
112
        delete [] verbuf;
 
113
        continue;
 
114
      }
 
115
 
 
116
      // browse through a string of mimetypes
 
117
      mimetypes[len] = '\0';
 
118
      char * type = mimetypes;
 
119
 
 
120
      BOOL more = TRUE;
 
121
      while(more) {
 
122
        char * p = strchr(type, '|');
 
123
        if(p)
 
124
          *p = '\0';
 
125
        else
 
126
          more = FALSE;
 
127
 
 
128
        if(0 == stricmp(mimetype, type)) {
 
129
          // this is it!
 
130
          delete [] verbuf;
 
131
          FindClose(handle);
 
132
          HINSTANCE hLib = LoadLibrary(szFileName);
 
133
          return hLib;
 
134
        }
 
135
 
 
136
        type = p;
 
137
        type++;
 
138
      }
 
139
 
 
140
      delete [] verbuf;
 
141
    }
 
142
 
 
143
  } while(FindNextFile(handle, &ffdataStruct));
 
144
 
 
145
  FindClose(handle);
 
146
  return NULL;
 
147
}
 
148
 
 
149
void UnloadRealPlugin(HINSTANCE hLib)
 
150
{
 
151
  if(!hLib)
 
152
    FreeLibrary(hLib);
 
153
}