@@ -888,31 +888,32 @@ class SubnetCalcAppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate,
888888 panel. allowedFileTypes = [ " csv " ]
889889 panel. begin ( completionHandler: { ( result) in
890890 if ( result == NSApplication . ModalResponse. OK && panel. url != nil ) {
891+ var fileMgt : FileManager
891892 if #available( OSX 10 . 14 , * ) {
892- let fileMgt = FileManager ( authorization: NSWorkspace . Authorization ( ) )
893- fileMgt. createFile ( atPath: panel. url!. path, contents: nil , attributes: nil )
894- //var cvsData = NSMutableData.init(capacity: Constants.BUFFER_LINES)
895- var cvsData = Data ( capacity: Constants . BUFFER_LINES)
896- let cvsFile = FileHandle ( forWritingAtPath: panel. url!. path)
897- if ( cvsFile != nil ) {
898- var cvsStr = " #;Subnet ID;Range;Broadcast \n "
899- for index in ( 0 ... ( self . ipsc!. maxSubnets ( ) - 1 ) ) {
900- let mask : UInt32 = UInt32 ( index) << ( 32 - self . ipsc!. maskBits)
901- let ipaddr = ( IPSubnetCalc . numerize ( ipAddress: self . ipsc!. subnetId ( ) ) ) | mask
902- let ipsc_tmp = IPSubnetCalc ( ipAddress: IPSubnetCalc . digitize ( ipAddress: ipaddr) , maskbits: self . ipsc!. maskBits)
903- if ( ipsc_tmp != nil ) {
904- cvsStr. append ( " \( index + 1 ) ; \( ipsc_tmp!. subnetId ( ) ) ; \( ipsc_tmp!. subnetRange ( ) ) ; \( ipsc_tmp!. subnetBroadcast ( ) ) \n " )
905- }
906- }
907- cvsData. append ( cvsStr. data ( using: String . Encoding. ascii) !)
908- cvsFile!. write ( cvsData)
909- cvsFile!. synchronizeFile ( )
910- cvsFile!. closeFile ( )
911- }
893+ fileMgt = FileManager ( authorization: NSWorkspace . Authorization ( ) )
912894 } else {
913895 // Fallback on earlier versions
896+ fileMgt = FileManager . default
897+ }
898+ fileMgt. createFile ( atPath: panel. url!. path, contents: nil , attributes: nil )
899+ //var cvsData = NSMutableData.init(capacity: Constants.BUFFER_LINES)
900+ var cvsData = Data ( capacity: Constants . BUFFER_LINES)
901+ let cvsFile = FileHandle ( forWritingAtPath: panel. url!. path)
902+ if ( cvsFile != nil ) {
903+ var cvsStr = " #;Subnet ID;Range;Broadcast \n "
904+ for index in ( 0 ... ( self . ipsc!. maxSubnets ( ) - 1 ) ) {
905+ let mask : UInt32 = UInt32 ( index) << ( 32 - self . ipsc!. maskBits)
906+ let ipaddr = ( IPSubnetCalc . numerize ( ipAddress: self . ipsc!. subnetId ( ) ) ) | mask
907+ let ipsc_tmp = IPSubnetCalc ( ipAddress: IPSubnetCalc . digitize ( ipAddress: ipaddr) , maskbits: self . ipsc!. maskBits)
908+ if ( ipsc_tmp != nil ) {
909+ cvsStr. append ( " \( index + 1 ) ; \( ipsc_tmp!. subnetId ( ) ) ; \( ipsc_tmp!. subnetRange ( ) ) ; \( ipsc_tmp!. subnetBroadcast ( ) ) \n " )
910+ }
911+ }
912+ cvsData. append ( cvsStr. data ( using: String . Encoding. ascii) !)
913+ cvsFile!. write ( cvsData)
914+ cvsFile!. synchronizeFile ( )
915+ cvsFile!. closeFile ( )
914916 }
915-
916917 }
917918 }
918919 )
0 commit comments