示例#1
0
文件: ResMan.cs 项目: scemino/nscumm
 public void Flush()
 {
     for (uint clusCnt = 0; clusCnt < _prj.noClu; clusCnt++)
     {
         Clu cluster = _prj.clu[clusCnt];
         for (uint grpCnt = 0; grpCnt < cluster.noGrp; grpCnt++)
         {
             Grp group = cluster.grp[grpCnt];
             for (uint resCnt = 0; resCnt < group.noRes; resCnt++)
                 if (group.resHandle[resCnt].cond != MemMan.MEM_FREED)
                 {
                     _memMan.SetCondition(group.resHandle[resCnt], MemMan.MEM_CAN_FREE);
                     group.resHandle[resCnt].refCount = 0;
                 }
         }
         if (cluster.file != null)
         {
             cluster.file.Dispose();
             cluster.file = null;
             cluster.refCount = 0;
         }
     }
     _openClus = 0;
     _openCluStart = _openCluEnd = null;
     // the memory manager cached the blocks we asked it to free, so explicitly make it free them
     _memMan.Flush();
 }
示例#2
0
文件: ResMan.cs 项目: scemino/nscumm
        private Stream ResFile(uint id)
        {
            Clu cluster = _prj.clu[((id >> 24) - 1)];
            if (cluster.file == null)
            {
                _openClus++;
                if (_openCluEnd == null)
                {
                    _openCluStart = _openCluEnd = cluster;
                }
                else
                {
                    _openCluEnd.nextOpen = cluster;
                    _openCluEnd = cluster;
                }
                string fileName;
                // Supposes that big endian means mac cluster file and little endian means PC cluster file.
                // This works, but we may want to separate the file name from the endianess or try .CLM extension if opening.clu file fail.
                if (_isBigEndian)
                    fileName = $"{_prj.clu[(id >> 24) - 1].label.Trim('\0')}.CLM";
                else
                    fileName = $"{_prj.clu[(id >> 24) - 1].label.Trim('\0')}.CLU";
                var path = ScummHelper.LocatePath(_directory, fileName);
                cluster.file = ServiceLocator.FileStorage.OpenFileRead(path);

                while (_openClus > MAX_OPEN_CLUS)
                {
                    Debug.Assert(_openCluStart != null);
                    Clu closeClu = _openCluStart;
                    _openCluStart = _openCluStart.nextOpen;

                    if (closeClu != null)
                    {
                        closeClu.file?.Dispose();
                        closeClu.file = null;
                        closeClu.nextOpen = null;
                    }
                    _openClus--;
                }
            }
            return cluster.file;
        }