/// <summary>
        /// Saves a craft to the hard drive
        /// </summary>
        public void SaveCraftToDisk(CraftEntry craft)
        {
            string folder;

            switch (craft.CraftType)
            {
            case CraftType.Vab:
                folder = CommonUtil.CombinePaths(SaveFolder, "Ships", "VAB");
                break;

            case CraftType.Sph:
                folder = CommonUtil.CombinePaths(SaveFolder, "Ships", "SPH");
                break;

            case CraftType.Subassembly:
                folder = CommonUtil.CombinePaths(SaveFolder, "Subassemblies");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var path = CommonUtil.CombinePaths(folder, $"{craft.CraftName}.craft");

            File.WriteAllBytes(path, craft.CraftData);

            //Add it to the queue notification as we are in another thread
            DownloadedCraftsNotification.Enqueue(craft.CraftName);
        }
        /// <summary>
        /// Sends a craft to the server if possible
        /// </summary>
        public void SendCraft(CraftEntry craft)
        {
            if (TimeUtil.IsInInterval(ref _lastRequest, SettingsSystem.ServerSettings.MinCraftLibraryRequestIntervalMs))
            {
                MessageSender.SendCraftMsg(craft);
                LunaScreenMsg.PostScreenMessage(LocalizationContainer.ScreenText.CraftUploaded, 10f, ScreenMessageStyle.UPPER_CENTER);
            }
            else
            {
                var msg = LocalizationContainer.ScreenText.CraftLibraryInterval.Replace("$1",
                                                                                        TimeSpan.FromMilliseconds(SettingsSystem.ServerSettings.MinCraftLibraryRequestIntervalMs).TotalSeconds.ToString(CultureInfo.InvariantCulture));

                LunaScreenMsg.PostScreenMessage(msg, 20f, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Beispiel #3
0
        public void SendCraftMsg(CraftEntry craft)
        {
            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <CraftLibraryDataMsgData>();

            msgData.Craft.FolderName = craft.FolderName;
            msgData.Craft.CraftName  = craft.CraftName;
            msgData.Craft.CraftType  = craft.CraftType;

            msgData.Craft.NumBytes = craft.CraftNumBytes;

            if (msgData.Craft.Data.Length < craft.CraftNumBytes)
            {
                msgData.Craft.Data = new byte[craft.CraftNumBytes];
            }

            Array.Copy(craft.CraftData, msgData.Craft.Data, craft.CraftNumBytes);

            SendMessage(msgData);
        }
Beispiel #4
0
        private static void SaveNewCraft(CraftLibraryDataMsgData craftMsg)
        {
            var craft = new CraftEntry
            {
                CraftName     = craftMsg.Craft.CraftName,
                CraftType     = craftMsg.Craft.CraftType,
                FolderName    = craftMsg.Craft.FolderName,
                CraftNumBytes = craftMsg.Craft.NumBytes,
                CraftData     = new byte[craftMsg.Craft.NumBytes]
            };

            Array.Copy(craftMsg.Craft.Data, craft.CraftData, craftMsg.Craft.NumBytes);

            if (System.CraftDownloaded.TryGetValue(craftMsg.Craft.FolderName, out var downloadedCrafts))
            {
                downloadedCrafts.AddOrUpdate(craftMsg.Craft.CraftName, craft, (key, existingVal) => craft);
            }

            System.SaveCraftToDisk(craft);
        }