1
+ #nullable enable
2
+
1
3
using System ;
2
4
using System . Collections . Generic ;
3
5
using System . Linq ;
4
6
5
7
using BizHawk . Common . StringExtensions ;
8
+ using BizHawk . Emulation . Common ;
6
9
7
10
namespace BizHawk . Client . Common
8
11
{
@@ -13,99 +16,117 @@ public static class ExternalToolApplicability
13
16
[ Obsolete ( "this is the default behaviour, you can safely omit this attribute" ) ]
14
17
public sealed class Always : ExternalToolApplicabilityAttributeBase
15
18
{
16
- public override bool NotApplicableTo ( CoreSystem system ) => false ;
19
+ public override bool NotApplicableTo ( string sysID )
20
+ => false ;
17
21
18
- public override bool NotApplicableTo ( string romHash , CoreSystem ? system ) => false ;
22
+ public override bool NotApplicableTo ( string romHash , string ? sysID )
23
+ => false ;
19
24
}
20
25
21
26
[ AttributeUsage ( AttributeTargets . Class ) ]
22
27
public sealed class AnyRomLoaded : ExternalToolApplicabilityAttributeBase
23
28
{
24
- public override bool NotApplicableTo ( CoreSystem system ) => system == CoreSystem . Null ;
29
+ public override bool NotApplicableTo ( string sysID )
30
+ => sysID is VSystemID . Raw . NULL ;
25
31
26
- public override bool NotApplicableTo ( string romHash , CoreSystem ? system ) => system == CoreSystem . Null ;
32
+ public override bool NotApplicableTo ( string romHash , string ? sysID )
33
+ => sysID is VSystemID . Raw . NULL ;
27
34
}
28
35
29
36
[ AttributeUsage ( AttributeTargets . Class ) ]
30
37
public sealed class RomWhitelist : ExternalToolApplicabilityAttributeBase
31
38
{
32
39
private readonly IList < string > _romHashes ;
33
40
34
- private readonly CoreSystem _system ;
41
+ private readonly string _sysID ;
35
42
43
+ [ Obsolete ( "replace CoreSystem with string from VSystemID.Raw" ) ]
36
44
public RomWhitelist ( CoreSystem system , params string [ ] romHashes )
45
+ : this ( SystemIdConverter . ConvertBack ( system ) , romHashes ) { }
46
+
47
+ public RomWhitelist ( string sysID , params string [ ] romHashes )
37
48
{
38
- if ( system == CoreSystem . Null ) throw new ArgumentException ( "there are no roms for the NULL system" , nameof ( system ) ) ;
49
+ if ( sysID is VSystemID . Raw . NULL ) throw new ArgumentException ( "there are no roms for the NULL system" , nameof ( sysID ) ) ;
39
50
if ( ! romHashes . All ( NumericStringExtensions . IsHex ) ) throw new ArgumentException ( "misformatted hash" , nameof ( romHashes ) ) ;
40
- _system = system ;
41
51
_romHashes = romHashes . ToList ( ) ;
52
+ _sysID = sysID ;
42
53
}
43
54
44
- public override bool NotApplicableTo ( CoreSystem system ) => system != _system ;
55
+ public override bool NotApplicableTo ( string sysID )
56
+ => sysID != _sysID ;
45
57
46
- public override bool NotApplicableTo ( string romHash , CoreSystem ? system ) => system != _system || ! _romHashes . Contains ( romHash ) ;
58
+ public override bool NotApplicableTo ( string romHash , string ? sysID )
59
+ => sysID != _sysID || ! _romHashes . Contains ( romHash ) ;
47
60
}
48
61
49
62
[ AttributeUsage ( AttributeTargets . Class ) ]
50
63
public sealed class SingleRom : ExternalToolApplicabilityAttributeBase
51
64
{
52
65
private readonly string _romHash ;
53
66
54
- private readonly CoreSystem _system ;
67
+ private readonly string _sysID ;
55
68
69
+ [ Obsolete ( "replace CoreSystem with string from VSystemID.Raw" ) ]
56
70
public SingleRom ( CoreSystem system , string romHash )
71
+ : this ( SystemIdConverter . ConvertBack ( system ) , romHash ) { }
72
+
73
+ public SingleRom ( string sysID , string romHash )
57
74
{
58
- if ( system == CoreSystem . Null ) throw new ArgumentException ( "there are no roms for the NULL system" , nameof ( system ) ) ;
75
+ if ( sysID is VSystemID . Raw . NULL ) throw new ArgumentException ( "there are no roms for the NULL system" , nameof ( sysID ) ) ;
59
76
if ( ! romHash . IsHex ( ) ) throw new ArgumentException ( "misformatted hash" , nameof ( romHash ) ) ;
60
- _system = system ;
61
77
_romHash = romHash ;
78
+ _sysID = sysID ;
62
79
}
63
80
64
- public override bool NotApplicableTo ( CoreSystem system ) => system != _system ;
81
+ public override bool NotApplicableTo ( string sysID )
82
+ => sysID != _sysID ;
65
83
66
- public override bool NotApplicableTo ( string romHash , CoreSystem ? system ) => system != _system || romHash != _romHash ;
84
+ public override bool NotApplicableTo ( string romHash , string ? sysID )
85
+ => sysID != _sysID || romHash != _romHash ;
67
86
}
68
87
69
88
[ AttributeUsage ( AttributeTargets . Class ) ]
70
89
public sealed class SingleSystem : ExternalToolApplicabilityAttributeBase
71
90
{
72
- private readonly CoreSystem _system ;
91
+ private readonly string _sysID ;
73
92
93
+ [ Obsolete ( "replace CoreSystem with string from VSystemID.Raw" ) ]
74
94
public SingleSystem ( CoreSystem system )
75
- {
76
- _system = system ;
77
- }
95
+ : this ( SystemIdConverter . ConvertBack ( system ) ) { }
78
96
79
- public override bool NotApplicableTo ( CoreSystem system ) => system != _system ;
97
+ public SingleSystem ( string sysID )
98
+ => _sysID = sysID ;
80
99
81
- public override bool NotApplicableTo ( string romHash , CoreSystem ? system ) => system != _system ;
100
+ public override bool NotApplicableTo ( string sysID )
101
+ => sysID != _sysID ;
102
+
103
+ public override bool NotApplicableTo ( string romHash , string ? sysID )
104
+ => sysID != _sysID ;
82
105
}
83
106
}
84
107
85
108
public abstract class ExternalToolApplicabilityAttributeBase : Attribute
86
109
{
87
- public abstract bool NotApplicableTo ( CoreSystem system ) ;
110
+ protected static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new ( ) ;
88
111
89
- public abstract bool NotApplicableTo ( string romHash , CoreSystem ? system ) ;
112
+ public abstract bool NotApplicableTo ( string sysID ) ;
90
113
91
- public bool NotApplicableTo ( string romHash ) => NotApplicableTo ( romHash , null ) ;
114
+ public abstract bool NotApplicableTo ( string romHash , string ? sysID ) ;
92
115
93
116
public class DuplicateException : Exception { }
94
117
}
95
118
96
119
[ AttributeUsage ( AttributeTargets . Class ) ]
97
120
public sealed class ExternalToolAttribute : Attribute
98
121
{
99
- public string Description { get ; set ; }
122
+ public string ? Description { get ; set ; }
100
123
101
- public string [ ] LoadAssemblyFiles { get ; set ; }
124
+ public string [ ] ? LoadAssemblyFiles { get ; set ; }
102
125
103
126
public readonly string Name ;
104
127
105
- public ExternalToolAttribute ( string name )
106
- {
107
- Name = string . IsNullOrWhiteSpace ( name ) ? Guid . NewGuid ( ) . ToString ( ) : name ;
108
- }
128
+ public ExternalToolAttribute ( string ? name )
129
+ => Name = string . IsNullOrWhiteSpace ( name ) ? Guid . NewGuid ( ) . ToString ( ) : name ! ;
109
130
110
131
public class MissingException : Exception { }
111
132
}
@@ -118,8 +139,6 @@ public sealed class ExternalToolEmbeddedIconAttribute : Attribute
118
139
119
140
/// <param name="resourcePath">The full path, including the assembly name.</param>
120
141
public ExternalToolEmbeddedIconAttribute ( string resourcePath )
121
- {
122
- ResourcePath = resourcePath ;
123
- }
142
+ => ResourcePath = resourcePath ;
124
143
}
125
144
}
0 commit comments