Skip to content

Commit

Permalink
Added new experimental update with big improvement of json functional…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
Fulgurance committed Jul 7, 2024
1 parent c8f46d8 commit 728dfc8
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 392 deletions.
72 changes: 31 additions & 41 deletions ISM/CommandLine.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ module ISM
availableKernel = ISM::AvailableKernel.new(kernelDirectory)

kernelOptionFiles.each do |kernelOptionFile|
kernelOption = ISM::KernelOption.new
kernelOption.loadInformationFile(@settings.rootPath+ISM::Default::Path::KernelOptionsDirectory+"/"+kernelDirectory+"/"+kernelOptionFile)

availableKernel.options << kernelOption
availableKernel.options << ISM::KernelOption.loadConfiguration(@settings.rootPath+ISM::Default::Path::KernelOptionsDirectory+"/"+kernelDirectory+"/"+kernelOptionFile)
end

@kernels << availableKernel
Expand All @@ -95,14 +92,12 @@ module ISM
end

def loadSoftware(port : String, name : String, version : String) : ISM::SoftwareInformation
software = ISM::SoftwareInformation.new

software.loadInformationFile( @settings.rootPath +
ISM::Default::Path::SoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::Information)
software = ISM::SoftwareInformation.loadConfiguration( @settings.rootPath +
ISM::Default::Path::SoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::Information)

if File.exists?(@settings.rootPath +
ISM::Default::Path::SettingsSoftwaresDirectory +
Expand All @@ -111,13 +106,12 @@ module ISM
version + "/" +
ISM::Default::Filename::SoftwareSettings)

softwareSettings = ISM::SoftwareInformation.new
softwareSettings.loadInformationFile( @settings.rootPath +
ISM::Default::Path::SettingsSoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::SoftwareSettings)
softwareSettings = ISM::SoftwareInformation.loadConfiguration( @settings.rootPath +
ISM::Default::Path::SettingsSoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::SoftwareSettings)

softwareSettings.options.each do |option|

Expand Down Expand Up @@ -179,9 +173,8 @@ module ISM
portsFiles = Dir.children(@settings.rootPath+ISM::Default::Path::PortsDirectory)

portsFiles.each do |portFile|
port = ISM::Port.new(portFile[0..-6])
port.loadPortFile
@ports << port
path = ISM::Port.filePath(portFile[0..-6])
@ports << ISM::Port.loadConfiguration(path)
end
end

Expand All @@ -193,14 +186,11 @@ module ISM
mirrorsFiles = Dir.children(@settings.rootPath+ISM::Default::Path::MirrorsDirectory)

if mirrorsFiles.size == 0
mirror = ISM::Mirror.new
mirror.loadMirrorFile
@mirrors << mirror
@mirrors << ISM::Mirror.loadConfiguration
else
mirrorsFiles.each do |mirrorFile|
mirror = ISM::Mirror.new(mirrorFile[0..-6])
mirror.loadMirrorFile
@mirrors << mirror
path = ISM::Mirror.filePath(mirrorFile[0..-6])
@mirrors << ISM::Mirror.loadConfiguration(path)
end
end
end
Expand Down Expand Up @@ -232,12 +222,12 @@ module ISM
installedSoftware = ISM::SoftwareInformation.new

begin
installedSoftware.loadInformationFile( @settings.rootPath +
ISM::Default::Path::InstalledSoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::Information)
installedSoftware.loadConfiguration(@settings.rootPath +
ISM::Default::Path::InstalledSoftwaresDirectory +
port + "/" +
name + "/" +
version + "/" +
ISM::Default::Filename::Information)
rescue
end

Expand Down Expand Up @@ -323,11 +313,11 @@ module ISM
path = ISM::FavouriteGroup.filePath(favouriteGroupName)

if File.exists?(path)

favouriteGroup = ISM::FavouriteGroup.loadConfiguration(path)
favouriteGroup.loadConfiguration
favouriteGroup.softwares.delete(fullVersionName)
favouriteGroup.writeConfiguration
favouriteGroup = ISM::FavouriteGroup.loadConfiguration(path)
favouriteGroup.loadConfiguration
favouriteGroup.softwares.delete(fullVersionName)
favouriteGroup.writeConfiguration
end
end

def removeInstalledSoftware(software : ISM::SoftwareInformation)
Expand Down Expand Up @@ -393,7 +383,7 @@ module ISM
installedOne = ISM::SoftwareInformation.new

if File.exists?(software.installedFilePath)
installedOne.loadInformationFile(software.installedFilePath)
installedOne.loadConfiguration(software.installedFilePath)
end

alreadyInstalled = installedOne.isValid
Expand Down Expand Up @@ -946,7 +936,7 @@ module ISM
realLineNumber = taskError.line-targetStartingLine
targetPath = line[line.index("/")..-1]

software.loadInformationFile(targetPath)
software.loadConfiguration(targetPath)
break
end

Expand Down
38 changes: 23 additions & 15 deletions ISM/CommandLinePortsSettings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,47 @@ module ISM

class CommandLinePortsSettings

record PortsSettings,
targetVersion : String do
include JSON::Serializable
end
include JSON::Serializable

property targetVersion : String

def initialize(@targetVersion = ISM::Default::CommandLinePortsSettings::TargetVersion)
end

def filePath : String
def self.filePath : String
return Ism.settings.rootPath+ISM::Default::CommandLinePortsSettings::PortsSettingsFilePath
end

def loadPortsSettingsFile
if !File.exists?(filePath)
writePortsSettingsFile
def self.generateConfiguration(path = filePath)
file = File.open(path,"w")
self.new.to_json
file.close
end

def self.loadConfiguration(path = filePath)
if !File.exists?(path)
generateConfiguration(path)
end

information = PortsSettings.from_json(File.read(filePath))
@targetVersion = information.targetVersion
from_json(File.read(path))
end

def writePortsSettingsFile
portsSettings = PortsSettings.new(@targetVersion)
def loadConfiguration(path = self.class.filePath)
if !File.exists?(path)
writeConfiguration(path)
end

self.class.from_json(File.read(path))
end

file = File.open(filePath,"w")
portsSettings.to_json(file)
def writeConfiguration(path = self.class.filePath)
file = File.open(path,"w")
to_json(file)
file.close
end

def setTargetVersion(@targetVersion)
writePortsSettingsFile
writeConfiguration
end

end
Expand Down
Loading

0 comments on commit 728dfc8

Please sign in to comment.