-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRom.cs
119 lines (103 loc) · 3.92 KB
/
Rom.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
using System;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media.Imaging;
namespace RomSync
{
public class Rom : INotifyPropertyChanged
{
// List of images available to set Icon to. Depends on the extension for the file.
private readonly static BitmapImage VectrexImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/vectrex.png"));
private readonly static BitmapImage UnknownImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/unknown.png"));
private readonly static BitmapImage NESImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/nes.png"));
private readonly static BitmapImage ZIPImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/ZIP.png"));
private readonly static BitmapImage WaitingImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/waiting.png"));
private readonly static BitmapImage GreenCheckImage = new BitmapImage(new System.Uri("pack://application:,,,/Resources/greencheck.png"));
// Information about the Rom - the name, extension, directory, etc. is all in this object.
public FileInfo FileInfo { get; set; }
// Returns the Icon of the image, depending on what the file extension is.
public BitmapImage Icon
{
get
{
switch(FileInfo.Extension)
{
case (".vec"):
return VectrexImage;
case (".nes"):
case (".fds"):
return NESImage;
case (".zip"):
return ZIPImage;
default:
return UnknownImage;
}
}
}
// Returns the image that represents the sync status of this Rom.
public BitmapImage SyncStatusImage
{
get
{
switch (SyncStatus)
{
case -1:
return null;
case 0:
return WaitingImage;
case 1:
return GreenCheckImage;
default:
return null;
}
}
}
private int syncStatus;
/// <summary>
/// -1 = unset, 0 = unsynced, 1 = synced
/// </summary>
public int SyncStatus
{
get
{
return syncStatus;
}
set
{
syncStatus = value;
if (syncStatus < -1 || syncStatus > 1)
{
throw new ArgumentOutOfRangeException();
}
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to propertyName
// causes the property/method (in this case, property) name of the caller to used as the argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public override bool Equals(object x)
{
return x.GetHashCode() == this.GetHashCode();
}
public override int GetHashCode()
{
int hash = 7;
// Suitable nullity checks etc, of course :)
hash = hash + FileInfo.Name.GetHashCode();
return hash;
}
public Rom(FileInfo fileInfo)
{
FileInfo = fileInfo;
SyncStatus = -1;
}
}
}