/[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 96 - (show annotations) (download)
Wed Oct 13 00:11:17 2010 UTC (11 years, 1 month ago) by rvvs89
File size: 2016 byte(s)
EditFile control now supports picking files.
Selected file metadata is now serialized and hence recoverable from the logbook.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9
10 namespace MetadataPlugin.Source
11 {
12 public partial class EditFile : UserControl
13 {
14 private byte[] data;
15 private MetadataFile.MetadataFileData reference;
16
17 public EditFile()
18 {
19 InitializeComponent();
20 }
21
22 public MetadataFile.MetadataFileData Data
23 {
24 get
25 {
26 reference.Name = nameField.Text;
27 reference.Data = data;
28 return reference;
29 }
30 set
31 {
32 nameField.Text = value.Name == null ? "<No file selected>" : value.Name;
33 data = value.Data;
34 sizeField.Text = string.Format("{0}", data == null ? 0 : data.Length);
35 reference = value;
36 }
37 }
38
39 private void selectButton_Click(object sender, EventArgs e)
40 {
41 if (openFileDialog.ShowDialog() == DialogResult.OK)
42 {
43 FileStream stream = File.OpenRead(openFileDialog.FileName);
44 int off = 0;
45 byte[] newData = new byte[stream.Length];
46 int rem = newData.Length;
47 while (rem > 0)
48 {
49 int read = stream.Read(newData, off, rem);
50 if (read <= 0)
51 {
52 // TODO: display error
53 return;
54 }
55 rem -= read;
56 off += read;
57 }
58 nameField.Text = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
59 data = newData;
60 sizeField.Text = string.Format("{0}", data == null ? 0 : data.Length);
61 }
62 }
63 }
64 }

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26