forked from ispysoftware/iSpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImporter.cs
130 lines (115 loc) · 3.67 KB
/
Importer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
125
126
127
128
129
130
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace iSpyApplication
{
public partial class Importer : Form
{
public MainForm mainForm;
public Importer()
{
InitializeComponent();
this.Text = LocRm.GetString("ImportObjects");
label1.Text = LocRm.GetString("File");
button2.Text = LocRm.GetString("OK");
}
public override sealed string Text
{
get { return base.Text; }
set { base.Text = value; }
}
private void Importer_Load(object sender, EventArgs e)
{
mainForm = (MainForm) Owner;
}
private void button2_Click(object sender, EventArgs e)
{
foreach (var itm in clbAdd.CheckedItems)
{
var o = itm as clb;
if (o?.C != null)
{
var a = _c.actions.entries.Where(p => p.objecttypeid == 2 && p.objectid == o.C.id).ToList();
o.C.id = MainForm.NextCameraId;
o.C.settings.micpair = -1;
MainForm.AddObject(o.C);
foreach (var ent in a)
{
ent.objectid = o.C.id;
MainForm.AddObject(ent);
}
mainForm.DisplayCamera(o.C, true);
}
//if (o?.M != null)
//{
// o.M.id = MainForm.NextMicrophoneId;
// MainForm.AddObject(o.M);
// mainForm.DisplayMicrophone(o.M);
//}
}
if (MainForm.Conf.AutoLayout)
mainForm.LayoutObjects(0, 0);
Close();
}
private string _lastPath = "";
private void button1_Click(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.InitialDirectory = _lastPath;
ofd.Filter = "iSpy Files (*.ispy)|*.ispy|XML Files (*.xml)|*.xml";
if (ofd.ShowDialog(this) == DialogResult.OK)
{
string fileName = ofd.FileName;
try
{
var fi = new FileInfo(fileName);
_lastPath = fi.DirectoryName;
}
catch
{
}
if (fileName.Trim() != "")
{
try
{
_c = MainForm.GetObjects(fileName.Trim());
ListObjects(_c);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, LocRm.GetString("Error"));
}
}
}
}
}
private objects _c;
private void ListObjects(objects c)
{
clbAdd.Items.Clear();
foreach (var cam in c.cameras)
{
clbAdd.Items.Add(new clb(cam));
}
}
private class clb
{
public clb(objectsCamera c)
{
C = c;
}
//public clb(objectsMicrophone m)
//{
// M = m;
//}
public objectsCamera C;
//public objectsMicrophone M;
public override string ToString()
{
return C.name;//!=null?C.name:M.name;
}
}
}
}