Example #1
0
        private void ProcessDirectory(string path)
        {
            var di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                return;
            }
            foreach (DiskSceneFileInfo info in SaveLoadScript.IterScenes(di))
            {
                //don't add bogus files to the catalog
                if (info.IsHeaderValid())
                {
                    AddSketchToSet(info);
                }
            }
            m_Sketches.Sort();
        }
 public DiskSceneFileInfo(string path, bool embedded = false, bool readOnly = false)
 {
     Debug.Assert(embedded == false || readOnly == true); // if embedded, should always be readonly.
     m_embedded = embedded;
     if (m_embedded)
     {
         m_fullpath  = path;
         m_TiltFile  = null;
         m_humanName = kInvalidHumanName;
     }
     else
     {
         m_fullpath  = Path.GetFullPath(path);
         m_TiltFile  = new TiltFile(m_fullpath);
         m_humanName = Path.GetFileNameWithoutExtension(SaveLoadScript.RemoveMd5Suffix(m_fullpath));
     }
     m_AssetId      = null;
     m_SourceId     = null;
     m_readOnly     = readOnly;
     m_creationTime = null;
 }
Example #3
0
        /// Returns strokes read from the passed .tilt file
        public static List <Stroke> GetStrokesFromTilt(string path)
        {
            var            file = new DiskSceneFileInfo(path, readOnly: true);
            SketchMetadata metadata;

            using (var jsonReader = new JsonTextReader(
                       new StreamReader(
                           SaveLoadScript.GetMetadataReadStream(file)))) {
                // TODO: should cache this?
                var serializer = new JsonSerializer();
                serializer.ContractResolver = new CustomJsonContractResolver();
                serializer.Error           += (sender, args) => {
                    throw new Exception(args.ErrorContext.Error.Message);
                };
                metadata = serializer.Deserialize <SketchMetadata>(jsonReader);
            }

            using (var stream = file.GetReadStream(TiltFile.FN_SKETCH)) {
                var bufferedStream = new BufferedStream(stream, 4096);
                return(SketchWriter.GetStrokes(
                           bufferedStream, metadata.BrushIndex, BitConverter.IsLittleEndian));
            }
        }
Example #4
0
        /// Returns all non-null asset ids from the passed sketch's metadata.
        /// null return value means "empty list".
        /// Raises exception on error.
        private static List <string> GetModelIds(SceneFileInfo sceneFileInfo)
        {
            // Json deserializing is in a separate method that doesn't access Unity objects so that it
            // can be called on a thread. The json deserializing can be pretty slow and can cause
            // frame drops if performed on the main thread.
            Stream metadata = SaveLoadScript.GetMetadataReadStream(sceneFileInfo);

            if (metadata == null)
            {
                if (sceneFileInfo.Exists)
                {
                    // ??? Let's try to provoke an exception to propagate to the caller
                    using (var dummy = File.OpenRead(sceneFileInfo.FullPath)) { }
                    throw new Exception($"Unknown error opening metadata {sceneFileInfo.FullPath}");
                }
                else
                {
                    throw new Exception(
                              "Reading metadata from nonexistent " +
                              $"{sceneFileInfo.InfoType} {sceneFileInfo.HumanName}");
                }
            }
            using (var jsonReader = new JsonTextReader(new StreamReader(metadata)))
            {
                var jsonData = SaveLoadScript.m_Instance.DeserializeMetadata(jsonReader);
                if (SaveLoadScript.m_Instance.LastMetadataError != null)
                {
                    throw new Exception($"Deserialize error: {SaveLoadScript.m_Instance.LastMetadataError}");
                }
                if (jsonData.ModelIndex == null)
                {
                    return(null);
                }
                return(jsonData.ModelIndex.Select(m => m.AssetId).Where(a => a != null).ToList());
            }
        }