System.Data.SQLite

Check-in [7c412389c2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:no message
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 7c412389c2469b0a42de657ff883e67f037e1a2b
User & Date: rmsimpson 2006-02-14 14:46:24.000
Context
2006-02-14
19:41
1.0.26.1 check-in: 0cff10df69 user: rmsimpson tags: sourceforge
14:46
no message check-in: 7c412389c2 user: rmsimpson tags: sourceforge
03:07
no message check-in: 64d79942dc user: rmsimpson tags: sourceforge
Changes
Unified Diff Ignore Whitespace Patch
Changes to tools/install/InstallDesigner.cs.
25
26
27
28
29
30
31

32
33
34
35

36


37
38


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91






92
93












94
95
96
97
98
99
100
    private static Guid standardCFDataSourcesGuid = new Guid("{0EBAAB6E-CA80-4b4a-8DDF-CBE6BF058C72}");
    private static Guid oledbDataProviderGuid = new Guid("{7F041D59-D76A-44ed-9AA2-FBF6B0548B80}");
    private static Guid oledbAltDataProviderGuid = new Guid("{7F041D59-D76A-44ed-9AA2-FBF6B0548B81}");
    private static Guid jetDataSourcesGuid = new Guid("{466CE797-67A4-4495-B75C-A3FD282E7FC3}");
    private static Guid jetAltDataSourcesGuid = new Guid("{466CE797-67A4-4495-B75C-A3FD282E7FC4}");
    private static string[] compactFrameworks = new string[] { "PocketPC", "SmartPhone", "WindowsCE" };


    private static System.Reflection.Assembly assm = null;
    private bool _ignoreChecks = true;

    static InstallDesigner()

    {


      if (assm == null)
      {


        try
        {
          assm = System.Reflection.Assembly.LoadFrom("..\\System.Data.SQLite.DLL");
        }
        catch
        {
        }
      }

      if (assm == null)
      {
        try
        {
          assm = System.Reflection.Assembly.LoadFrom("..\\x64\\System.Data.SQLite.DLL");
        }
        catch
        {
        }
      }

      if (assm == null)
      {
        try
        {
          assm = System.Reflection.Assembly.LoadFrom("..\\itanium\\System.Data.SQLite.DLL");
        }
        catch
        {
        }
      }

      OpenFileDialog dlg = new OpenFileDialog();
      while (assm == null)
      {
        dlg.Multiselect = false;
        dlg.InitialDirectory = Environment.CurrentDirectory;
        dlg.FileName = "System.Data.SQLite.DLL";
        dlg.Filter = "System.Data.SQLite.DLL|System.Data.SQLite.DLL";
        if (dlg.ShowDialog() == DialogResult.OK)
        {
          try
          {
            assm = System.Reflection.Assembly.LoadFrom(dlg.FileName);
          }
          catch
          {
          }
        }
        else
          throw new ArgumentException("Unable to find or load System.Data.SQLite.DLL");
      }

    }







    public InstallDesigner()
    {












      InitializeComponent();
    }

    private void InstallDesigner_Load(object sender, EventArgs e)
    {
      RegistryKey key;








>
|


<
>

>
>
|
|
>
>
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|

>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    private static Guid standardCFDataSourcesGuid = new Guid("{0EBAAB6E-CA80-4b4a-8DDF-CBE6BF058C72}");
    private static Guid oledbDataProviderGuid = new Guid("{7F041D59-D76A-44ed-9AA2-FBF6B0548B80}");
    private static Guid oledbAltDataProviderGuid = new Guid("{7F041D59-D76A-44ed-9AA2-FBF6B0548B81}");
    private static Guid jetDataSourcesGuid = new Guid("{466CE797-67A4-4495-B75C-A3FD282E7FC3}");
    private static Guid jetAltDataSourcesGuid = new Guid("{466CE797-67A4-4495-B75C-A3FD282E7FC4}");
    private static string[] compactFrameworks = new string[] { "PocketPC", "SmartPhone", "WindowsCE" };

    private string _regRoot = "8.0";
    private System.Reflection.Assembly _assm = null;
    private bool _ignoreChecks = true;


    System.Reflection.Assembly SQLite
    {
      get
      {
        if (_assm == null)
        {
          Environment.CurrentDirectory = Path.GetDirectoryName(typeof(InstallDesigner).Assembly.Location);

          try
          {
            _assm = System.Reflection.Assembly.LoadFrom("..\\System.Data.SQLite.DLL");
          }
          catch
          {
          }
        }

        if (_assm == null)
        {
          try
          {
            _assm = System.Reflection.Assembly.LoadFrom("..\\x64\\System.Data.SQLite.DLL");
          }
          catch
          {
          }
        }

        if (_assm == null)
        {
          try
          {
            _assm = System.Reflection.Assembly.LoadFrom("..\\itanium\\System.Data.SQLite.DLL");
          }
          catch
          {
          }
        }

        OpenFileDialog dlg = new OpenFileDialog();
        while (_assm == null)
        {
          dlg.Multiselect = false;
          dlg.InitialDirectory = Environment.CurrentDirectory;
          dlg.FileName = "System.Data.SQLite.DLL";
          dlg.Filter = "System.Data.SQLite.DLL|System.Data.SQLite.DLL";
          if (dlg.ShowDialog() == DialogResult.OK)
          {
            try
            {
              _assm = System.Reflection.Assembly.LoadFrom(dlg.FileName);
            }
            catch
            {
            }
          }
          else
            throw new ArgumentException("Unable to find or load System.Data.SQLite.DLL");
        }
        return _assm;
      }

      set
      {
        _assm = value;
      }
    }

    public InstallDesigner()
    {
      string[] args = Environment.GetCommandLineArgs();

      for (int n = 0; n < args.Length; n++)
      {
        if (String.Compare(args[n], "/regroot", true) == 0 ||
          String.Compare(args[n], "-regroot", true) == 0)
        {
          _regRoot = args[n + 1];
          break;
        }
      }

      InitializeComponent();
    }

    private void InstallDesigner_Load(object sender, EventArgs e)
    {
      RegistryKey key;

205
206
207
208
209
210
211
212
213
214
215
216
217









218


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
          install = true;
          break;
        }
      }

      if (install && !installed)
      {
        AssemblyCache.InstallAssembly(assm.Location, null, AssemblyCommitFlags.Default);
      }
      else if (!install && installed)
      {
        System.Reflection.AssemblyName name = assm.GetName();
        AssemblyCacheUninstallDisposition disp;









        AssemblyCache.UninstallAssembly(name.FullName + ", ProcessorArchitecture=" + name.ProcessorArchitecture, null, out disp);


      }
    }

    private void ReplaceJet(string keyname)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataProviders", keyname), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbDataProviderGuid.ToString("B")))
        {
          using (RegistryKey dest = key.CreateSubKey(oledbAltDataProviderGuid.ToString("B")))
          {
            if (source == null) return;
            CopyKey(source, dest);
          }
        }
        key.DeleteSubKeyTree(oledbDataProviderGuid.ToString("B"));
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataSources", keyname), true))
      {
        using (RegistryKey source = key.OpenSubKey(jetDataSourcesGuid.ToString("B")))
        {
          using (RegistryKey dest = key.CreateSubKey(jetAltDataSourcesGuid.ToString("B")))
          {
            if (source == null) return;
            CopyKey(source, dest);
          }
        }
        key.DeleteSubKeyTree(jetDataSourcesGuid.ToString("B"));
      }

      Install(keyname, oledbDataProviderGuid, jetDataSourcesGuid);
    }

    private void RestoreJet(string keyname)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataProviders", keyname), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
        {
          if (source == null) return;
        }
      }

      Uninstall(keyname, oledbDataProviderGuid, jetDataSourcesGuid);

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataProviders", keyname), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
        {
          if (source != null)
          {
            using (RegistryKey dest = key.CreateSubKey(oledbDataProviderGuid.ToString("B")))
            {
              CopyKey(source, dest);
            }
            key.DeleteSubKeyTree(oledbAltDataProviderGuid.ToString("B"));
          }
        }
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataSources", keyname), true))
      {
        using (RegistryKey source = key.OpenSubKey(jetAltDataSourcesGuid.ToString("B")))
        {
          if (source != null)
          {
            using (RegistryKey dest = key.CreateSubKey(jetDataSourcesGuid.ToString("B")))
            {
              CopyKey(source, dest);
            }
            key.DeleteSubKeyTree(jetAltDataSourcesGuid.ToString("B"));
          }
        }
      }
    }

    private void Install(string keyname, Guid provider, Guid source)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataProviders", keyname), true))
      {
        using (RegistryKey subkey = key.CreateSubKey(provider.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
          subkey.SetValue(null, ".NET Framework Data Provider for SQLite");
          subkey.SetValue("InvariantName", "System.Data.SQLite");
          subkey.SetValue("Technology", "{77AB9A9D-78B9-4ba7-91AC-873F5338F1D2}");
          subkey.SetValue("CodeBase", Path.GetFullPath("SQLite.Designer.DLL"));







|



<

>
>
>
>
>
>
>
>
>
|
>
>





|












|

















|









|














|

















|







229
230
231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
          install = true;
          break;
        }
      }

      if (install && !installed)
      {
        AssemblyCache.InstallAssembly(SQLite.Location, null, AssemblyCommitFlags.Default);
      }
      else if (!install && installed)
      {

        AssemblyCacheUninstallDisposition disp;

        AssemblyCacheEnum entries = new AssemblyCacheEnum("System.Data.SQLite");

        string s;
        while (true)
        {
          s = entries.GetNextAssembly();
          if (String.IsNullOrEmpty(s)) break;

          AssemblyCache.UninstallAssembly(s, null, out disp);
        }
        SQLite = null;
      }
    }

    private void ReplaceJet(string keyname)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbDataProviderGuid.ToString("B")))
        {
          using (RegistryKey dest = key.CreateSubKey(oledbAltDataProviderGuid.ToString("B")))
          {
            if (source == null) return;
            CopyKey(source, dest);
          }
        }
        key.DeleteSubKeyTree(oledbDataProviderGuid.ToString("B"));
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
      {
        using (RegistryKey source = key.OpenSubKey(jetDataSourcesGuid.ToString("B")))
        {
          using (RegistryKey dest = key.CreateSubKey(jetAltDataSourcesGuid.ToString("B")))
          {
            if (source == null) return;
            CopyKey(source, dest);
          }
        }
        key.DeleteSubKeyTree(jetDataSourcesGuid.ToString("B"));
      }

      Install(keyname, oledbDataProviderGuid, jetDataSourcesGuid);
    }

    private void RestoreJet(string keyname)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
        {
          if (source == null) return;
        }
      }

      Uninstall(keyname, oledbDataProviderGuid, jetDataSourcesGuid);

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
      {
        using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
        {
          if (source != null)
          {
            using (RegistryKey dest = key.CreateSubKey(oledbDataProviderGuid.ToString("B")))
            {
              CopyKey(source, dest);
            }
            key.DeleteSubKeyTree(oledbAltDataProviderGuid.ToString("B"));
          }
        }
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
      {
        using (RegistryKey source = key.OpenSubKey(jetAltDataSourcesGuid.ToString("B")))
        {
          if (source != null)
          {
            using (RegistryKey dest = key.CreateSubKey(jetDataSourcesGuid.ToString("B")))
            {
              CopyKey(source, dest);
            }
            key.DeleteSubKeyTree(jetAltDataSourcesGuid.ToString("B"));
          }
        }
      }
    }

    private void Install(string keyname, Guid provider, Guid source)
    {
      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
      {
        using (RegistryKey subkey = key.CreateSubKey(provider.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
          subkey.SetValue(null, ".NET Framework Data Provider for SQLite");
          subkey.SetValue("InvariantName", "System.Data.SQLite");
          subkey.SetValue("Technology", "{77AB9A9D-78B9-4ba7-91AC-873F5338F1D2}");
          subkey.SetValue("CodeBase", Path.GetFullPath("SQLite.Designer.DLL"));
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
              subsubsubkey.SetValue(null, "SQLite.Designer.SQLiteDataConnectionSupport");
#endif
            }
          }
        }
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataSources", keyname), true))
      {
        using (RegistryKey subkey = key.CreateSubKey(source.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
          subkey.SetValue(null, "SQLite Database File");
          using (RegistryKey subsubkey = subkey.CreateSubKey("SupportingProviders", RegistryKeyPermissionCheck.ReadWriteSubTree))
          {
            subsubkey.CreateSubKey(provider.ToString("B")).Close();







|







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
              subsubsubkey.SetValue(null, "SQLite.Designer.SQLiteDataConnectionSupport");
#endif
            }
          }
        }
      }

      using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
      {
        using (RegistryKey subkey = key.CreateSubKey(source.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
          subkey.SetValue(null, "SQLite Database File");
          using (RegistryKey subsubkey = subkey.CreateSubKey("SupportingProviders", RegistryKeyPermissionCheck.ReadWriteSubTree))
          {
            subsubkey.CreateSubKey(provider.ToString("B")).Close();
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
              subkey.SetValue("InvariantName", "System.Data.SQLite");
              subkey.SetValue("RuntimeAssembly", "System.Data.SQLite.DLL");
            }
          }
        }
      }

      string path = Path.GetDirectoryName(assm.Location);

      while (path.Length > 0)
      {
        if (File.Exists(path + "\\CompactFramework\\System.Data.SQLite.DLL") == false)
        {
          path = Path.GetDirectoryName(path);
        }







|







380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
              subkey.SetValue("InvariantName", "System.Data.SQLite");
              subkey.SetValue("RuntimeAssembly", "System.Data.SQLite.DLL");
            }
          }
        }
      }

      string path = Path.GetDirectoryName(SQLite.Location);

      while (path.Length > 0)
      {
        if (File.Exists(path + "\\CompactFramework\\System.Data.SQLite.DLL") == false)
        {
          path = Path.GetDirectoryName(path);
        }
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
          xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("type"));
          xmlParent.AppendChild(xmlNode);
        }
      }
      xmlNode.Attributes.GetNamedItem("name").Value = "SQLite Data Provider";
      xmlNode.Attributes.GetNamedItem("invariant").Value = "System.Data.SQLite";
      xmlNode.Attributes.GetNamedItem("description").Value = ".Net Framework Data Provider for SQLite";
      xmlNode.Attributes.GetNamedItem("type").Value = "System.Data.SQLite.SQLiteFactory, " + assm.GetName().FullName;

      xmlDoc.Save(xmlFileName);
    }

    private static XmlDocument GetConfig(string keyname, out string xmlFileName)
    {
      // xmlFileName = Environment.ExpandEnvironmentVariables("%WinDir%\\Microsoft.NET\\Framework\\v2.0.50727\\CONFIG\\machine.config");







|







481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
          xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("type"));
          xmlParent.AppendChild(xmlNode);
        }
      }
      xmlNode.Attributes.GetNamedItem("name").Value = "SQLite Data Provider";
      xmlNode.Attributes.GetNamedItem("invariant").Value = "System.Data.SQLite";
      xmlNode.Attributes.GetNamedItem("description").Value = ".Net Framework Data Provider for SQLite";
      xmlNode.Attributes.GetNamedItem("type").Value = "System.Data.SQLite.SQLiteFactory, " + SQLite.GetName().FullName;

      xmlDoc.Save(xmlFileName);
    }

    private static XmlDocument GetConfig(string keyname, out string xmlFileName)
    {
      // xmlFileName = Environment.ExpandEnvironmentVariables("%WinDir%\\Microsoft.NET\\Framework\\v2.0.50727\\CONFIG\\machine.config");
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
      return null;
    }

    private void Uninstall(string keyname, Guid provider, Guid source)
    {
      try
      {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataProviders", keyname), true))
        {
          if (key != null) key.DeleteSubKeyTree(provider.ToString("B"));
        }
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\8.0\\DataSources", keyname), true))
        {
          if (key != null) key.DeleteSubKeyTree(source.ToString("B"));
        }

        for (int n = 0; n < compactFrameworks.Length; n++)
        {
          using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v2.0.0.0\\{0}\\DataProviders", compactFrameworks[n]), true))







|



|







518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
      return null;
    }

    private void Uninstall(string keyname, Guid provider, Guid source)
    {
      try
      {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree(provider.ToString("B"));
        }
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree(source.ToString("B"));
        }

        for (int n = 0; n < compactFrameworks.Length; n++)
        {
          using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v2.0.0.0\\{0}\\DataProviders", compactFrameworks[n]), true))