-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from derail-valley-modding/sim-update
Bugfixes
- Loading branch information
Showing
17 changed files
with
690 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace SkinConfigurator | ||
{ | ||
[Serializable] | ||
public class ConfiguratorSettings | ||
{ | ||
private static string SettingsFile => Path.Combine(Environment.CurrentDirectory, "settings.json"); | ||
private static JsonSerializerOptions _serializeOptions = new() | ||
{ | ||
IncludeFields = true, | ||
WriteIndented = true, | ||
}; | ||
|
||
public string DefaultSkinWorkFolder; | ||
public string DerailValleyDirectory; | ||
|
||
public ConfiguratorSettings() | ||
{ | ||
DefaultSkinWorkFolder = Environment.CurrentDirectory; | ||
DerailValleyDirectory = SteamHelper.GetModsDirectory() ?? Environment.CurrentDirectory; | ||
} | ||
|
||
public ConfiguratorSettings(ConfiguratorSettings other) | ||
{ | ||
DefaultSkinWorkFolder = other.DefaultSkinWorkFolder; | ||
DerailValleyDirectory = other.DerailValleyDirectory; | ||
} | ||
|
||
public static ConfiguratorSettings LoadConfig() | ||
{ | ||
try | ||
{ | ||
using var stream = File.OpenRead(SettingsFile); | ||
return JsonSerializer.Deserialize<ConfiguratorSettings>(stream, _serializeOptions) ?? new ConfiguratorSettings(); | ||
} | ||
catch | ||
{ | ||
return new ConfiguratorSettings(); | ||
} | ||
} | ||
|
||
public static void SaveConfig(ConfiguratorSettings settings) | ||
{ | ||
try | ||
{ | ||
using var stream = File.Open(SettingsFile, FileMode.Create); | ||
JsonSerializer.Serialize(stream, settings, _serializeOptions); | ||
} | ||
catch | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
public class SettingsModel : INotifyPropertyChanged | ||
{ | ||
public ConfiguratorSettings Data { get; private set; } | ||
|
||
public SettingsModel(ConfiguratorSettings data) | ||
{ | ||
Data = new ConfiguratorSettings(data); | ||
} | ||
|
||
[JsonIgnore] | ||
public string WorkingFolder | ||
{ | ||
get => Data.DefaultSkinWorkFolder; | ||
set | ||
{ | ||
Data.DefaultSkinWorkFolder = value; | ||
OnPropertyChanged(nameof(WorkingFolder)); | ||
} | ||
} | ||
|
||
[JsonIgnore] | ||
public string DerailValleyDirectory | ||
{ | ||
get => Data.DerailValleyDirectory; | ||
set | ||
{ | ||
Data.DerailValleyDirectory = value; | ||
OnPropertyChanged(nameof(DerailValleyDirectory)); | ||
} | ||
} | ||
|
||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
private void OnPropertyChanged(string propertyName) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using SMShared; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace SkinConfigurator | ||
{ | ||
internal class FolderPackager : SkinPackager | ||
{ | ||
public FolderPackager(string path, SkinPackModel model) : base(path, model) | ||
{ | ||
Directory.CreateDirectory(path); | ||
ClearDirectory(_destPath); | ||
} | ||
|
||
private static void ClearDirectory(string dirPath) | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(dirPath)) | ||
{ | ||
File.Delete(file); | ||
} | ||
foreach (var dir in Directory.EnumerateDirectories(dirPath)) | ||
{ | ||
Directory.Delete(dir, true); | ||
} | ||
} | ||
|
||
private string GetAbsoluteDestination(string relativeDest) => Path.Combine(_destPath, relativeDest); | ||
|
||
protected override void WriteModInfo() | ||
{ | ||
string dest = GetAbsoluteDestination(Constants.MOD_INFO_FILE); | ||
using var stream = File.Open(dest, FileMode.Create); | ||
JsonSerializer.Serialize(stream, _model.ModInfoModel, _serializeOptions); | ||
} | ||
|
||
protected override void WriteSkin(SkinConfigModel skin) | ||
{ | ||
string folderName = GetSkinFolderName(skin.Name, skin.CarId); | ||
string folderPath = GetAbsoluteDestination(folderName); | ||
Directory.CreateDirectory(folderPath); | ||
|
||
string jsonPath = Path.Combine(folderPath, Constants.SKIN_CONFIG_FILE); | ||
using var jsonStream = File.Open(jsonPath, FileMode.Create); | ||
JsonSerializer.Serialize(jsonStream, skin, _serializeOptions); | ||
|
||
// textures & whatever else | ||
foreach (var sourceFile in Directory.EnumerateFiles(skin.FolderPath)) | ||
{ | ||
string relativePath = GetTargetFileName(folderName, sourceFile, skin.CarId); | ||
string absPath = GetAbsoluteDestination(relativePath); | ||
File.Copy(sourceFile, absPath, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.