/[cits3200i]/branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/EditFile.cs


UCC Code Repository

Contents of /branches/metadata-branch-rvvs89/UWAPlugins/MetadataPlugin/Source/EditFile.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations) (download)
Wed Oct 13 00:45:52 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 3239 byte(s)
Recovering an embeded metadata file now works properly.
Calls rundll32.exe to open the Open With dialog.
Needs testing on other operating systems (ie, Windows XP and Vista).
1 using Microsoft.Win32;
2 using System;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Drawing;
6 using System.Data;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO;
10 using System.Runtime.InteropServices;
11 using System.Diagnostics;
12
13 namespace MetadataPlugin.Source
14 {
15 public partial class EditFile : UserControl
16 {
17 private byte[] data;
18 private MetadataFile.MetadataFileData reference;
19 private string tmp = null;
20
21 public EditFile()
22 {
23 InitializeComponent();
24 }
25
26 public MetadataFile.MetadataFileData Data
27 {
28 get
29 {
30 reference.Name = nameField.Text;
31 reference.Data = data;
32 return reference;
33 }
34 set
35 {
36 nameField.Text = value.Name == null ? "<No file selected>" : value.Name;
37 data = value.Data;
38 sizeField.Text = string.Format("{0}", data == null ? 0 : data.Length);
39 openButton.Enabled = data != null;
40 reference = value;
41 if (tmp != null)
42 {
43 File.Delete(tmp);
44 tmp = null;
45 }
46 }
47 }
48
49 private void selectButton_Click(object sender, EventArgs e)
50 {
51 if (openFileDialog.ShowDialog() == DialogResult.OK)
52 {
53 FileStream stream = File.OpenRead(openFileDialog.FileName);
54 int off = 0;
55 byte[] newData = new byte[stream.Length];
56 int rem = newData.Length;
57 while (rem > 0)
58 {
59 int read = stream.Read(newData, off, rem);
60 if (read <= 0)
61 {
62 // TODO: display error
63 stream.Close();
64 return;
65 }
66 rem -= read;
67 off += read;
68 }
69 nameField.Text = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
70 data = newData;
71 sizeField.Text = string.Format("{0}", data == null ? 0 : data.Length);
72 openButton.Enabled = true;
73 }
74 }
75
76 private void openButton_Click(object sender, EventArgs e)
77 {
78 // store file to temporary location
79 tmp = Path.GetTempPath() + nameField.Text;
80 FileStream stream = File.OpenWrite(tmp);
81 int size = data.Length;
82 stream.Write(data, 0, size);
83 stream.Close();
84 ShellExecute(tmp);
85 }
86
87 private void ShellExecute(string file)
88 {
89 Process proc = new Process();
90 ProcessStartInfo pinfo = new ProcessStartInfo("rundll32.exe");
91 pinfo.UseShellExecute = false;
92 pinfo.RedirectStandardOutput = true;
93 pinfo.Arguments = "shell32.dll,OpenAs_RunDLL " + file;
94 proc.StartInfo = pinfo;
95 proc.Start();
96 }
97 }
98 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26