Пример #1
0
        protected byte[][] LoadAllBinaries(Context context, string source, string fileName)
        {
            string   sourcePath     = SourcePath + FileSystem.GetDirectorySeparator() + fileName;
            DateTime sourceDateTime = FileSystem.GetLastWriteTime(sourcePath);

            byte[][] binaries = new byte[context.Devices.Length][];

            if (!Directory.Exists(BinaryPath))
            {
                throw new DirectoryNotFoundException(BinaryPath);
            }

            using (BinaryMetaInfo bmi = BinaryMetaInfo.FromPath(BinaryPath, FileAccess.Read, FileShare.Read))
            {
                Device[] devices;

                devices = context.Devices;
                for (int i = 0; i < devices.Length; i++)
                {
                    if (binaries[i] != null)
                    {
                        continue;
                    }

                    Device   device = devices[i];
                    string   binaryFilePath;
                    MetaFile mf = bmi.FindMetaFile("", fileName, Context.Platform.Name, device.Name, device.DriverVersion, Defines, BuildOptions);
                    if (mf == null)
                    {
                        throw new FileNotFoundException("No compiled binary file present in MetaFile");
                    }
                    binaryFilePath = BinaryPath + FileSystem.GetDirectorySeparator() + mf.BinaryName;
                    if (AttemptUseSource)
                    {
                        // This exception will be caught inside the manager and cause recompilation
                        if (FileSystem.GetLastWriteTime(binaryFilePath) < sourceDateTime)
                        {
                            throw new Exception("Binary older than source");
                        }
                    }
                    binaries[i] = FileSystem.ReadAllBytes(binaryFilePath);

                    // Check of there are other identical devices that can use the binary we just loaded
                    // If there are, patch it in in the proper slots in the list of binaries
                    for (int j = i + 1; j < devices.Length; j++)
                    {
                        if (devices[i].Name == devices[j].Name &&
                            devices[i].Vendor == devices[j].Vendor &&
                            devices[i].Version == devices[j].Version &&
                            devices[i].AddressBits == devices[j].AddressBits &&
                            devices[i].DriverVersion == devices[j].DriverVersion &&
                            devices[i].EndianLittle == devices[j].EndianLittle)
                        {
                            binaries[j] = binaries[i];
                        }
                    }
                }
            }
            return(binaries);
        }
Пример #2
0
        protected void SaveAllBinaries(Context context, string source, string fileName, byte[][] binaries)
        {
            XmlSerializer xml = new XmlSerializer(typeof(BinaryMetaInfo));

            TestAndCreateDirectory(BinaryPath);
            using (BinaryMetaInfo bmi = BinaryMetaInfo.FromPath(BinaryPath, FileAccess.ReadWrite, FileShare.None))
            {
                for (int i = 0; i < context.Devices.Length; i++)
                {
                    Device device = context.Devices[i];
                    string binaryFileName;

                    MetaFile mf = bmi.FindMetaFile(source, fileName, context.Platform.Name, device.Name, device.DriverVersion, Defines, BuildOptions);
                    if (mf == null)
                    {
                        mf = bmi.CreateMetaFile(source, fileName, context.Platform.Name, device.Name, device.DriverVersion, Defines, BuildOptions);
                    }

                    binaryFileName = BinaryPath + FileSystem.GetDirectorySeparator() + mf.BinaryName;
                    FileSystem.WriteAllBytes(binaryFileName, binaries[i]);
                }
                bmi.TrimBinaryCache(FileSystem, MaxCachedBinaries);
                bmi.Save();
            }
        }