Beispiel #1
0
        private BinarySave GetBinaryOutput(Flow flow)
        {
            var binary = new BinarySave();

            for (int i = 0; i < count; i++)
            {
                binary.variables.Add(flow.GetValue <string>(names[i]), flow.GetValue <object>(values[i]));
            }

            return(binary);
        }
        private ControlOutput SaveBinary(Flow flow)
        {
            var binary = promoteToInputPort == true?flow.GetValue <BinarySave>(binarySave) : new BinarySave();

            var loadedSave = append ? BinarySave.Load(GetPath(flow)) : null;

            if (!promoteToInputPort)
            {
                for (int i = 0; i < values.Count; i++)
                {
                    if (!string.IsNullOrEmpty(values[i].key))
                    {
                        binary.Set(flow.GetValue <string>(names[i]), flow.GetValue <object>(values[i]));
                    }
                }
            }

            if (loadedSave != null)
            {
                if (!promoteToInputPort)
                {
                    for (int i = 0; i < binary.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(values[i].key))
                        {
                            loadedSave.Set(flow.GetValue <string>(names[i]), flow.GetValue <object>(values[i]));
                        }
                    }
                }
                else
                {
                    var saveKeys   = binary.variables.Keys.ToArrayPooled();
                    var saveValues = binary.variables.Values.ToArrayPooled();

                    for (int i = 0; i < binary.Count; i++)
                    {
                        loadedSave.Set(saveKeys[i], saveValues[i]);
                    }
                }

                Save(flow, loadedSave);

                lastSave = loadedSave;
            }
            else
            {
                Save(flow, binary);
                lastSave = binary;
            }


            return(complete);
        }
        protected override void Definition()
        {
            if (!usePersistantDataPath)
            {
                path = ValueInput <string>("path", string.Empty);
            }
            fileName = ValueInput <string>(nameof(fileName), string.Empty);
            binary   = ValueOutput <BinarySave>(nameof(binary));

            complete = ControlOutput("complete");
            load     = ControlInput("load", (flow) => {
                flow.SetValue(binary, BinarySave.Load((usePersistantDataPath) ? Application.persistentDataPath + "/data/" + flow.GetValue <string>(fileName) : flow.GetValue <string>(path) + "/" + flow.GetValue <string>(fileName)));
                return(complete);
            });

            Requirement(fileName, binary);
            Requirement(fileName, load);
            Succession(load, complete);
        }
Beispiel #4
0
        /// <summary>
        /// Save a binary save to a file path.
        /// </summary>
        public static void Save(string path, BinarySave binary)
        {
            string filelessPath = string.Empty;

            if (path.Contains("/"))
            {
                filelessPath = path.Remove(path.LastIndexOf("/"));
            }
            else
            {
                filelessPath = path.Remove(path.LastIndexOf(@"\"));
            }

            if (!Directory.Exists(filelessPath))
            {
                Directory.CreateDirectory(filelessPath);
            }

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                SerializationUtility.SerializeValue <BinarySave>(binary, SerializationUtility.CreateWriter(fileStream, new SerializationContext(), DataFormat.Binary));
            }
        }
 private void Save(Flow flow, BinarySave binary)
 {
     BinarySave.Save(GetPath(flow), binary);
 }