Exemplo n.º 1
0
        [UnityEditor.Callbacks.OnOpenAsset(1)]//打开任意Asset文件会调用下面方法
        public static bool OpenAssetBySuffix(int instanceID, int line)
        {
            string strFilePath = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));

            strFilePath = strFilePath.Replace("/", "\\");
            string strFileName = Directory.GetParent(Application.dataPath) + "\\" + strFilePath;

            if (strFileName.EndsWith(".shader"))
            {
                var bundle = new FileBundle()
                {
                    environmentPath = "VSCodePath",
                    exeName         = "Code.exe",
                    suffix          = ".shader"
                };
                return(OpenFile(strFileName, bundle));
            }
            else if (strFileName.EndsWith(".md"))
            {
                var bundle = new FileBundle()
                {
                    environmentPath = "VSCodePath",
                    exeName         = "Code.exe",
                    suffix          = ".md"
                };
                return(OpenFile(strFileName, bundle));
            }
            return(false);
        }
Exemplo n.º 2
0
        private void Merge(FileBundleEx destBundle, FileBundle srcBundle, List <string> bundleFiles, IEnumerable <string> files)
        {
            destBundle.BeginWrite();

            var paths = new List <string>();
            var path  = GetSelectedFolderPath();

            AddPath(destBundle, path);
            paths.Add(path);

            foreach (var fileName in files)
            {
                string file = Path.GetFileName(fileName);
                if (path != null)
                {
                    file = String.Format("{0}\\{1}", path, file);
                }

                for (int i = 0; i < bundleFiles.Count; i++)
                {
                    if (String.Compare(bundleFiles[i], file, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bundleFiles.RemoveAt(i);
                        Progress.Current++;
                        break;
                    }
                }

                FileInfo info = new FileInfo(fileName);
                InjectFile(destBundle, file, fileName, info.LastWriteTimeUtc);

                Progress.Current++;
            }

            foreach (var file in bundleFiles)
            {
                int index = file.LastIndexOf('\\');
                if (index > 0)
                {
                    path = file.Substring(0, index);
                    if (!paths.Contains(path))
                    {
                        AddPath(destBundle, path);
                        paths.Add(path);
                    }
                }

                CopyFile(destBundle, srcBundle, file);
                Progress.Current++;
            }

            destBundle.EndWrite();

            _backgroundWorkerService.InvokeOnUiThread(() =>
            {
                Progress.IsEnabled = false;
            });
        }
Exemplo n.º 3
0
        private static void AddPath(FileBundle bundle, string path)
        {
            int index = path.LastIndexOf('\\');

            if (index > 0)
            {
                AddPath(bundle, path.Substring(0, index));
            }

            bundle.CreateDirectory(path);
        }
Exemplo n.º 4
0
        void test()
        {
            FileBundle fb   = new FileBundle();
            int        size = 0;

            while ((size = fb.NextInt()) != 0)
            {
                string fName = fb.NextString(size);
                size = fb.NextInt();
                byte[] data = fb.NextArray(size);
            }
        }
Exemplo n.º 5
0
        private FileBundle CreateBundle(TestStream memoryStream)
        {
            var mockFileSystem = new Mock <IFileSystemService>();

            mockFileSystem.Setup(f => f.FileExists(BundleFileName)).Returns(false);
            mockFileSystem.Setup(f => f.CreateFile(BundleFileName)).Returns(memoryStream);
            mockFileSystem.Setup(f => f.OpenFile(BundleFileName, OpenFileMode.Read)).Returns(memoryStream);
            mockFileSystem.Setup(f => f.OpenFile(BundleFileName, OpenFileMode.ReadWrite)).Returns(memoryStream);
            var bundle = new FileBundle(BundleFileName, 3, mockFileSystem.Object);

            return(bundle);
        }
Exemplo n.º 6
0
        public void TestEmptyFile()
        {
            var mockFileSystem = new Mock <IFileSystemService>();

            mockFileSystem.Setup(f => f.FileExists(BundleFileName)).Returns(true);
            mockFileSystem.Setup(f => f.OpenFile(BundleFileName, OpenFileMode.Read)).Returns(new MemoryStream(emptyFile));

            var bundle = new FileBundle(BundleFileName, mockFileSystem.Object);

            Assert.That(bundle.GetDirectories(), Is.Empty);
            Assert.That(bundle.GetFiles(), Is.Empty);
            Assert.That(bundle.FileName, Is.EqualTo(BundleFileName));
        }
Exemplo n.º 7
0
        private FileBundle OpenBundle(TestStream memoryStream, byte[] originalData)
        {
            memoryStream.Write(originalData, 0, originalData.Length);
            memoryStream.Seek(0, SeekOrigin.Begin);

            var mockFileSystem = new Mock <IFileSystemService>();

            mockFileSystem.Setup(f => f.FileExists(BundleFileName)).Returns(true);
            mockFileSystem.Setup(f => f.OpenFile(BundleFileName, OpenFileMode.Read)).Returns(memoryStream);
            mockFileSystem.Setup(f => f.OpenFile(BundleFileName, OpenFileMode.ReadWrite)).Returns(memoryStream);
            var bundle = new FileBundle(BundleFileName, 3, mockFileSystem.Object);

            return(bundle);
        }
Exemplo n.º 8
0
        public void TestCreateBundle()
        {
            var memoryStream   = new MemoryStream();
            var mockFileSystem = new Mock <IFileSystemService>();

            mockFileSystem.Setup(f => f.FileExists(BundleFileName)).Returns(false);
            mockFileSystem.Setup(f => f.CreateFile(BundleFileName)).Returns(memoryStream);

            var bundle = new FileBundle(BundleFileName, 3, mockFileSystem.Object);

            var buffer = memoryStream.ToArray();

            Assert.That(buffer, Is.EqualTo(emptyFile));
        }
Exemplo n.º 9
0
        private static void CopyFile(FileBundle destBundle, FileBundle sourceBundle, string file)
        {
            using (Stream outputStream = destBundle.CreateFile(file))
            {
                destBundle.SetModified(file, sourceBundle.GetModified(file));

                using (Stream inputStream = sourceBundle.OpenFile(file, OpenFileMode.Read))
                {
                    byte[] buffer = new byte[8192];
                    do
                    {
                        int read = inputStream.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                        {
                            break;
                        }

                        outputStream.Write(buffer, 0, read);
                    } while (true);
                }
            }
        }
Exemplo n.º 10
0
        private static void InjectFile(FileBundle bundle, string file, string fileName, DateTime lastWriteTime)
        {
            using (Stream outputStream = bundle.CreateFile(file))
            {
                bundle.SetModified(file, lastWriteTime);

                using (Stream inputStream = File.OpenRead(fileName))
                {
                    byte[] buffer = new byte[8192];
                    do
                    {
                        int read = inputStream.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                        {
                            break;
                        }

                        outputStream.Write(buffer, 0, read);
                    } while (true);
                }
            }
        }
Exemplo n.º 11
0
        public static bool OpenFile(string strFileName, FileBundle bundle)
        {
            string editorPath = Environment.GetEnvironmentVariable(bundle.environmentPath);

            if (editorPath != null && editorPath.Length > 0)
            {
                System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName    = editorPath + (editorPath.EndsWith("\\") ? "" : "\\") + bundle.exeName;
                startInfo.Arguments   = "\"" + strFileName + "\"";
                process.StartInfo     = startInfo;
                Debug.Log("Open " + strFileName + " By " + startInfo.FileName);
                process.Start();
                return(true);
            }
            else
            {
                Debug.LogError("null environment : " + bundle.environmentPath);
                return(false);
            }
        }