Skip to content

Commit 0c1da1b

Browse files
Migrating from structs to objects in DiskManager
1 parent a9ce30c commit 0c1da1b

File tree

12 files changed

+158
-254
lines changed

12 files changed

+158
-254
lines changed

WinDiskWriter GUI/Views/PickerView/ IdentifiableMenuItem/IdentifiableMenuItem.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10+
#import "DiskInfo.h"
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

1314
@interface IdentifiableMenuItem : NSMenuItem
1415

15-
@property (strong, nonatomic, readwrite) id userIdentifiableData;
16+
@property (strong, nonatomic, readwrite) DiskInfo *diskInfo;
1617

17-
- (instancetype)initWithTitle: (NSString *)title
18-
identifiableUserData: (id)identifiableUserData;
19-
20-
- (instancetype)initWithDeviceVendor: (NSString *)deviceVendor
21-
deviceModel: (NSString *)deviceModel
22-
storageCapacityInBytes: (NSUInteger)storageCapacityInBytes
23-
bsdName: (NSString *)bsdName;
18+
- (instancetype)initWithDiskInfo: (DiskInfo *)diskInfo;
2419

2520
@end
2621

WinDiskWriter GUI/Views/PickerView/ IdentifiableMenuItem/IdentifiableMenuItem.m

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,22 @@
66
// Copyright © 2023 TechUnRestricted. All rights reserved.
77
//
88

9-
#import "IdentifiableMenuItem.h"
109
#import "NSMutableAttributedString+Common.h"
10+
#import "IdentifiableMenuItem.h"
11+
#import "NSString+Common.h"
1112
#import "HelperFunctions.h"
1213

1314
@implementation IdentifiableMenuItem
1415

15-
- (instancetype)initWithTitle: (NSString *)title
16-
identifiableUserData: (id)identifiableUserData {
17-
self = [super init];
18-
19-
[self setTitle: title];
20-
[self setUserIdentifiableData: identifiableUserData];
21-
22-
return self;
23-
}
24-
25-
- (instancetype)initWithDeviceVendor: (NSString *)deviceVendor
26-
deviceModel: (NSString *)deviceModel
27-
storageCapacityInBytes: (NSUInteger)storageCapacityInBytes
28-
bsdName: (NSString *)bsdName {
16+
- (instancetype)initWithDiskInfo: (DiskInfo *)diskInfo {
2917
self = [super init];
3018

19+
NSString *deviceVendor = [diskInfo.deviceVendor strip];
20+
NSString *deviceModel = [diskInfo.deviceModel strip];
21+
NSString *bsdName = diskInfo.BSDName;
22+
23+
UInt64 storageCapacityInBytes = [diskInfo.mediaSize unsignedIntValue];
24+
3125
NSMutableAttributedString *mutableAttributesStringResult = [NSMutableAttributedString attributedStringWithString: [NSString stringWithFormat:@"%@ %@", deviceVendor, deviceModel]
3226
weight: 6
3327
size: NSFont.systemFontSize];
@@ -42,7 +36,7 @@ - (instancetype)initWithDeviceVendor: (NSString *)deviceVendor
4236

4337
[self setAttributedTitle: mutableAttributesStringResult];
4438

45-
[self setUserIdentifiableData: bsdName];
39+
[self setDiskInfo: diskInfo];
4640

4741
return self;
4842
}

WinDiskWriter GUI/Windows/MainWindow/MainWindow.m

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ - (instancetype)initWithNSRect: (NSRect)nsRect
9898

9999
- (void)resetProgress {
100100
[self setCurrentProgressWithWrittenBytes: 0
101-
fileSizeBytes: 0];
101+
fileSizeBytes: 0];
102102

103103
[currentOperationProgressBarView resetProgressSynchronously];
104104
[totalOperationProgressBarView resetProgressSynchronously];
@@ -527,10 +527,9 @@ - (void)writeAction {
527527
[self setIsScheduledForStop: NO];
528528
[self setEnabledUIState: NO];
529529

530-
NSString *bsdName = [(IdentifiableMenuItem *)devicePickerView.selectedItem userIdentifiableData];
531-
DiskManager *destinationDiskDM = [[DiskManager alloc] initWithBSDName:bsdName];
530+
DiskInfo *destinationDiskInfo = [(IdentifiableMenuItem *)devicePickerView.selectedItem diskInfo];
531+
DiskManager *destinationDiskDM = [[DiskManager alloc] initWithBSDName:destinationDiskInfo.BSDName];
532532

533-
struct DiskInfo destinationDiskInfo = [destinationDiskDM getDiskInfo];
534533
if (destinationDiskDM == NULL || !destinationDiskInfo.isDeviceUnit) {
535534
[self displayWarningAlertWithTitle: BSD_DEVICE_IS_NO_LONGER_AVAILABLE_TITLE
536535
subtitle: PRESS_UPDATE_BUTTON_SUBTITLE
@@ -584,7 +583,7 @@ - (void)writeAction {
584583
logType: ASLogTypeLog];
585584

586585
NSString *diskEraseOperationText = [NSString stringWithFormat:@"Device %@ (%@ %@) is ready to be erased with the following properties: (partition_name: \"%@\", partition_scheme: \"%@\", filesystem: \"%@\", patch_security_checks: \"%d\").",
587-
bsdName,
586+
destinationDiskInfo.BSDName,
588587
destinationDiskInfo.deviceVendor,
589588
destinationDiskInfo.deviceModel,
590589
newPartitionName,
@@ -605,13 +604,13 @@ - (void)writeAction {
605604
filesystem: selectedFileSystem
606605
newName: newPartitionName
607606
error: &diskEraseError];
608-
607+
609608
if (diskEraseError != NULL) {
610609
[self displayWarningAlertWithTitle: DISK_ERASE_FAILURE_TITLE
611610
subtitle: diskEraseError.stringValue
612611
icon: NSImageNameCaution];
613612

614-
[self->logsAutoScrollTextView appendTimestampedLine: DISK_ERASE_FAILURE_TITLE
613+
[self->logsAutoScrollTextView appendTimestampedLine: [DISK_ERASE_FAILURE_TITLE stringByAppendingFormat: @" (Error message: %@)", diskEraseError.stringValue]
615614
logType: ASLogTypeFatal];
616615

617616
WriteExitForce();
@@ -644,7 +643,7 @@ - (void)writeAction {
644643
skipSecurityChecks: skipSecurityChecks];
645644

646645
NSError *writeError = NULL;
647-
646+
648647
[diskWriter startWritingWithError: &writeError
649648
progressCallback: ^DWAction(DWFile * _Nonnull dwFile, uint64 copiedBytes, DWOperationType operationType, DWOperationResult operationResult, NSError * _Nonnull error) {
650649
if (self.isScheduledForStop) {
@@ -660,7 +659,7 @@ - (void)writeAction {
660659

661660
[self setCurrentProgressWithWrittenBytes: copiedBytes
662661
fileSizeBytes: dwFile.size];
663-
662+
664663
NSString *destinationCurrentFilePath = [targetPartitionPath stringByAppendingPathComponent: dwFile.sourcePath];
665664
NSMutableString *onscreenLogText = [NSMutableString string];
666665

@@ -796,24 +795,21 @@ - (void)updateDeviceList {
796795

797796
[logsAutoScrollTextView appendTimestampedLine:@"Clearing the device picker list." logType:ASLogTypeLog];
798797

799-
NSArray<NSString *> *bsdNames = [DiskManager getBSDDrivesNames];
798+
NSArray<NSString *> *bsdNames = [DiskManager BSDDrivesNames];
800799

801800
NSString *textLog = [NSString stringWithFormat:@"Found devices: %@", [bsdNames componentsJoinedByString:@", "]];
802801
[logsAutoScrollTextView appendTimestampedLine:textLog logType:ASLogTypeLog];
803802

804803
for (NSString *bsdName in bsdNames) {
805804
DiskManager *diskManager = [[DiskManager alloc] initWithBSDName: bsdName];
806-
struct DiskInfo diskInfo = [diskManager getDiskInfo];
805+
DiskInfo *diskInfo = [diskManager diskInfo];
807806

808807
if (diskInfo.isNetworkVolume || diskInfo.isInternal ||
809808
!diskInfo.isDeviceUnit || !diskInfo.isWholeDrive || !diskInfo.isWritable) {
810809
continue;
811810
}
812811

813-
IdentifiableMenuItem *identifiableMenuItem = [[IdentifiableMenuItem alloc] initWithDeviceVendor: [diskInfo.deviceVendor strip]
814-
deviceModel: [diskInfo.deviceModel strip]
815-
storageCapacityInBytes: [diskInfo.mediaSize floatValue]
816-
bsdName: bsdName];
812+
IdentifiableMenuItem *identifiableMenuItem = [[IdentifiableMenuItem alloc] initWithDiskInfo:diskInfo];
817813

818814
[devicePickerView.menu addItem:identifiableMenuItem];
819815
}
@@ -830,12 +826,12 @@ - (void)setEnabledUIState:(BOOL)enabledUIState {
830826
if (enabledUIState) {
831827
[self resetProgress];
832828
[self->currentOperationLabelView setStringValue: @"Ready for action"];
833-
829+
834830
[self->quitMenuItem setAction:@selector(terminate:)];
835831

836832
[self->bytesWrittenLabelView setStringValue: @""];
837833
[self->bytesFileSizeLabelView setStringValue: @""];
838-
834+
839835
[self->startStopButtonView setTitle: BUTTON_START_TITLE];
840836
[self->startStopButtonView setAction: @selector(startAction)];
841837
} else {

windiskwriter.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
E249FBA72A5B1A96003B8D24 /* FrameLayoutVertical.m in Sources */ = {isa = PBXBuildFile; fileRef = E249FBA62A5B1A96003B8D24 /* FrameLayoutVertical.m */; };
102102
E250F6D329A4F4D0003BBF7D /* DWFilesContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = E250F6D229A4F4D0003BBF7D /* DWFilesContainer.m */; };
103103
E25946072982A77F000C60A4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E25946062982A77F000C60A4 /* main.m */; };
104+
E27FF65F2AAA2C1500C0356F /* DiskInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E27FF65E2AAA2C1500C0356F /* DiskInfo.m */; };
105+
E27FF6602AAA2C1500C0356F /* DiskInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E27FF65E2AAA2C1500C0356F /* DiskInfo.m */; };
104106
E289E2BC298EE0BD0011B620 /* BootModes.m in Sources */ = {isa = PBXBuildFile; fileRef = E289E2BB298EE0BD0011B620 /* BootModes.m */; };
105107
E289E2C1298EE66F0011B620 /* NSFileManager+Common.m in Sources */ = {isa = PBXBuildFile; fileRef = E289E2C0298EE66F0011B620 /* NSFileManager+Common.m */; };
106108
E2B52BBD29858D8000DF362B /* Filesystems.m in Sources */ = {isa = PBXBuildFile; fileRef = E2B52BBC29858D8000DF362B /* Filesystems.m */; };
@@ -428,6 +430,8 @@
428430
E250F6D229A4F4D0003BBF7D /* DWFilesContainer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DWFilesContainer.m; sourceTree = "<group>"; };
429431
E25946032982A77F000C60A4 /* windiskwriter */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = windiskwriter; sourceTree = BUILT_PRODUCTS_DIR; };
430432
E25946062982A77F000C60A4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; usesTabs = 1; };
433+
E27FF65D2AAA2C1500C0356F /* DiskInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DiskInfo.h; sourceTree = "<group>"; };
434+
E27FF65E2AAA2C1500C0356F /* DiskInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DiskInfo.m; sourceTree = "<group>"; };
431435
E289E2BA298EE0BD0011B620 /* BootModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BootModes.h; sourceTree = "<group>"; };
432436
E289E2BB298EE0BD0011B620 /* BootModes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BootModes.m; sourceTree = "<group>"; };
433437
E289E2BF298EE66F0011B620 /* NSFileManager+Common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Common.h"; sourceTree = "<group>"; };
@@ -1270,6 +1274,15 @@
12701274
path = AppDelegate;
12711275
sourceTree = "<group>";
12721276
};
1277+
E27FF6612AAA2C1800C0356F /* DiskInfo */ = {
1278+
isa = PBXGroup;
1279+
children = (
1280+
E27FF65D2AAA2C1500C0356F /* DiskInfo.h */,
1281+
E27FF65E2AAA2C1500C0356F /* DiskInfo.m */,
1282+
);
1283+
path = DiskInfo;
1284+
sourceTree = "<group>";
1285+
};
12731286
E289E2B9298EE08D0011B620 /* BootModes */ = {
12741287
isa = PBXGroup;
12751288
children = (
@@ -1396,6 +1409,7 @@
13961409
E2CCB29329854D9B004EE171 /* DiskManager */ = {
13971410
isa = PBXGroup;
13981411
children = (
1412+
E27FF6612AAA2C1800C0356F /* DiskInfo */,
13991413
E289E2B9298EE08D0011B620 /* BootModes */,
14001414
E2B52BBA29858D6E00DF362B /* Filesystems */,
14011415
E2B52BBE2985923400DF362B /* PartitionSchemes */,
@@ -1705,6 +1719,7 @@
17051719
E24364E22A72CCE600541719 /* TextInputView.m in Sources */,
17061720
E2C73B422A857C2D008B9FAC /* VibrantTextView.m in Sources */,
17071721
E249FBA72A5B1A96003B8D24 /* FrameLayoutVertical.m in Sources */,
1722+
E27FF6602AAA2C1500C0356F /* DiskInfo.m in Sources */,
17081723
E2CCCD872A3A11EE00D101DE /* FrameLayoutBase.m in Sources */,
17091724
E2C73B3B2A855FD5008B9FAC /* AdvancedTextView.m in Sources */,
17101725
E23298B92A37C23700869736 /* AppDelegate.m in Sources */,
@@ -1787,6 +1802,7 @@
17871802
E2247B4D2986FA1E000B24A1 /* xpress_decompress.c in Sources */,
17881803
E2247B332986FA1D000B24A1 /* encoding.c in Sources */,
17891804
E2247B552986FA1E000B24A1 /* error.c in Sources */,
1805+
E27FF65F2AAA2C1500C0356F /* DiskInfo.m in Sources */,
17901806
E2247B4A2986FA1E000B24A1 /* test_support.c in Sources */,
17911807
E2247B312986FA1D000B24A1 /* inode_table.c in Sources */,
17921808
E2247B5E2986FA1E000B24A1 /* xpress_compress.c in Sources */,
@@ -1834,9 +1850,11 @@
18341850
CLANG_CXX_LIBRARY = "libc++";
18351851
CLANG_ENABLE_OBJC_WEAK = NO;
18361852
CODE_SIGN_ENTITLEMENTS = "WinDiskWriter GUI/WinDiskWriter_GUI.entitlements";
1853+
CODE_SIGN_IDENTITY = "Apple Development";
18371854
CODE_SIGN_STYLE = Automatic;
18381855
COMBINE_HIDPI_IMAGES = YES;
18391856
CURRENT_PROJECT_VERSION = 1;
1857+
DEVELOPMENT_TEAM = 3T4SUAKT3L;
18401858
GENERATE_INFOPLIST_FILE = YES;
18411859
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 TechUnRestricted. All rights reserved.";
18421860
INFOPLIST_KEY_NSPrincipalClass = NSApplication;
@@ -1863,9 +1881,11 @@
18631881
CLANG_CXX_LIBRARY = "libc++";
18641882
CLANG_ENABLE_OBJC_WEAK = NO;
18651883
CODE_SIGN_ENTITLEMENTS = "WinDiskWriter GUI/WinDiskWriter_GUI.entitlements";
1884+
CODE_SIGN_IDENTITY = "Apple Development";
18661885
CODE_SIGN_STYLE = Automatic;
18671886
COMBINE_HIDPI_IMAGES = YES;
18681887
CURRENT_PROJECT_VERSION = 1;
1888+
DEVELOPMENT_TEAM = 3T4SUAKT3L;
18691889
GENERATE_INFOPLIST_FILE = YES;
18701890
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2023 TechUnRestricted. All rights reserved.";
18711891
INFOPLIST_KEY_NSPrincipalClass = NSApplication;

0 commit comments

Comments
 (0)