• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KSP-CKAN / CKAN / 18955927993

30 Oct 2025 09:45PM UTC coverage: 85.243% (+3.4%) from 81.873%
18955927993

Pull #4454

github

HebaruSan
Build on Windows, upload multi-platform coverage
Pull Request #4454: Build on Windows, upload multi-platform coverage

2003 of 2167 branches covered (92.43%)

Branch coverage included in aggregate %.

9 of 9 new or added lines in 3 files covered. (100.0%)

42 existing lines in 20 files now uncovered.

11959 of 14212 relevant lines covered (84.15%)

1.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.66
/Core/Registry/InstalledModule.cs
1
using System;
2
using System.Linq;
3
using System.ComponentModel;
4
using System.Collections.Generic;
5
using System.IO;
6
using System.Runtime.Serialization;
7

8
using CKAN.IO;
9
using Newtonsoft.Json;
10

11
namespace CKAN
12
{
13
    [JsonObject(MemberSerialization.OptIn)]
14
    public class InstalledModuleFile
15
    {
16
        [JsonConstructor]
17
        public InstalledModuleFile()
2✔
18
        {
2✔
19
        }
2✔
20
    }
21

22
    /// <summary>
23
    /// A simple class that represents an installed module. Includes the time of installation,
24
    /// the module itself, and a list of files installed with it.
25
    ///
26
    /// Primarily used by the Registry class.
27
    /// </summary>
28

29
    [JsonObject(MemberSerialization.OptIn)]
30
    public class InstalledModule
31
    {
32
        #region Fields and Properties
33

34
        [JsonProperty]
35
        private readonly DateTime install_time;
36

37
        [JsonProperty]
38
        private readonly CkanModule source_module;
39

40
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
41
        [DefaultValue(false)]
42
        private bool auto_installed;
43

44
        // TODO: Our InstalledModuleFile already knows its path, so this could just
45
        // be a list. However we've left it as a dictionary for now to maintain
46
        // registry format compatibility.
47
        [JsonProperty]
48
        private Dictionary<string, InstalledModuleFile> installed_files;
49

50
        public IReadOnlyCollection<string> Files       => installed_files.Keys;
2✔
51
        public string                      identifier  => source_module.identifier;
2✔
52
        public CkanModule                  Module      => source_module;
2✔
53
        public DateTime                    InstallTime => install_time;
2✔
54

55
        public bool AutoInstalled
56
        {
57
            get => auto_installed;
2✔
58
            set {
2✔
59
                if (Module.IsDLC)
2✔
60
                {
×
61
                    throw new ModuleIsDLCKraken(Module);
×
62
                }
63
                auto_installed = value;
2✔
64
            }
2✔
65
        }
66

67
        #endregion
68

69
        #region Constructors
70

71
        public InstalledModule(GameInstance? ksp, CkanModule module, IEnumerable<string> relative_files, bool autoInstalled)
2✔
72
        {
2✔
73
            install_time = DateTime.Now;
2✔
74
            source_module = module;
2✔
75
            // We need case insensitive path matching on Windows
76
            installed_files = new Dictionary<string, InstalledModuleFile>(Platform.PathComparer);
2✔
77
            auto_installed = autoInstalled;
2✔
78

79
            if (ksp != null)
2✔
80
            {
2✔
81
                foreach (string file in relative_files)
8✔
82
                {
2✔
83
                    if (Path.IsPathRooted(file))
2✔
84
                    {
×
85
                        throw new PathErrorKraken(file, "InstalledModule *must* have relative paths");
×
86
                    }
87

88
                    // IMF needs a KSP object so it can compute the SHA1.
89
                    installed_files[file] = new InstalledModuleFile();
2✔
90
                }
2✔
91
            }
2✔
92
        }
2✔
93

94
        #endregion
95

96
        #region Serialisation Fixes
97

98
        [OnDeserialized]
99
        private void DeSerialisationFixes(StreamingContext context)
100
        {
2✔
101
            installed_files ??= new Dictionary<string, InstalledModuleFile>();
2✔
102
            if (Platform.IsWindows)
2✔
103
            {
1✔
104
                // We need case insensitive path matching on Windows
105
                installed_files = new Dictionary<string, InstalledModuleFile>(installed_files,
1✔
106
                                                                              Platform.PathComparer);
107
            }
1✔
108
        }
2✔
109

110
        /// <summary>
111
        /// Ensures all files for this module have relative paths.
112
        /// Called when upgrading registry versions. Should be a no-op
113
        /// if called on newer registries.
114
        /// </summary>
115
        public void Renormalise(GameInstance inst)
116
        {
2✔
117
            installed_files = installed_files.ToDictionary(
2✔
118
                                  kvp => Path.IsPathRooted(kvp.Key)
2✔
119
                                             ? inst.ToRelativeGameDir(kvp.Key)
120
                                             : CKANPathUtils.NormalizePath(kvp.Key),
121
                                  kvp => kvp.Value,
2✔
122
                                  // We need case insensitive path matching on Windows
123
                                  Platform.PathComparer);
124
        }
2✔
125

126
        #endregion
127

128
        public bool AllFilesExist(GameInstance    instance,
129
                                  HashSet<string> filters)
130
            // Don't make them reinstall files they've filtered out since installing
UNCOV
131
            => Files.Where(f => !filters.Any(filt => f.Contains(filt)))
×
132
                    .Select(instance.ToAbsoluteGameDir)
133
                    .All(p => Directory.Exists(p) || File.Exists(p));
2✔
134

135
        public long ActualInstallSize(GameInstance instance)
136
            => Files.Select(instance.ToAbsoluteGameDir)
2✔
137
                    .Select(f => new FileInfo(f))
2✔
138
                    .Sum(fi => fi.Exists ? fi.Length : 0);
2✔
139

140
        public override string ToString()
141
            => string.Format(AutoInstalled ? Properties.Resources.InstalledModuleToStringAutoInstalled
×
142
                                           : Properties.Resources.InstalledModuleToString,
143
                             Module,
144
                             InstallTime);
145
    }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc