Class: OLEStorageLitePPSRoot

Inherits:
OLEStorageLitePPS show all
Defined in:
lib/WriteExcel/storage_lite.rb

Constant Summary

Constants inherited from OLEStorageLite

OLEStorageLite::DATA_SIZE_SMALL, OLEStorageLite::LONG_INT_SIZE, OLEStorageLite::PPS_SIZE, OLEStorageLite::PPS_TYPE_DIR, OLEStorageLite::PPS_TYPE_FILE, OLEStorageLite::PPS_TYPE_ROOT

Instance Attribute Summary

Attributes inherited from OLEStorageLitePPS

#child, #data, #dir_pps, #name, #next_pps, #no, #pps_file, #prev_pps, #size, #start_block, #time_1st, #time_2nd, #type

Instance Method Summary collapse

Methods inherited from OLEStorageLite

#asc2ucs, #localDate2OLE, #ucs2asc

Constructor Details

#initialize(raTime1st, raTime2nd, raChild) ⇒ OLEStorageLitePPSRoot

Returns a new instance of OLEStorageLitePPSRoot.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/WriteExcel/storage_lite.rb', line 157

def initialize(raTime1st, raTime2nd, raChild)
  super(
    nil,
    asc2ucs('Root Entry'),
    PPS_TYPE_ROOT,
    nil,
    nil,
    nil,
    raTime1st,
    raTime2nd,
    nil,
    nil,
    nil,
    raChild)
end

Instance Method Details

#_saveBbd(iSbdSize, iBsize, iPpsCnt, rh_info) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/WriteExcel/storage_lite.rb', line 465

def _saveBbd(iSbdSize, iBsize, iPpsCnt, rh_info)
  file = rh_info[:fileh]
  #0. Calculate Basic Setting

  iBbCnt    = rh_info[:big_block_size] / LONG_INT_SIZE
  iBlCnt    = iBbCnt - 1
  i1stBdL   = (rh_info[:big_block_size] - 0x4C) / LONG_INT_SIZE
  i1stBdMax = i1stBdL * iBbCnt  - i1stBdL
  iBdExL    = 0
  iAll      = iBsize + iPpsCnt + iSbdSize
  iAllW     = iAll
  iBdCntW   = iAllW / iBbCnt
  iBdCntW  += 1 if iAllW % iBbCnt > 0
  iBdCnt    = 0
  #0.1 Calculate BD count

  iBBleftover = iAll - i1stBdMax
  if iAll >i1stBdMax
    while true
      iBdCnt  = iBBleftover / iBlCnt
      iBdCnt += 1 if iBBleftover % iBlCnt > 0

      iBdExL  = iBdCnt / iBlCnt
      iBdExL += 1 if iBdCnt % iBlCnt > 0
      iBBleftover = iBBleftover + iBdExL
      break if iBdCnt == (iBBleftover / iBlCnt + ((iBBleftover % iBlCnt) > 0 ? 1: 0))
    end
  end
  iAllW  += iBdExL
  iBdCnt += i1stBdL
  #print "iBdCnt = iBdCnt \n"


  #1. Making BD

  #1.1 Set for SBD

  if iSbdSize > 0
    0.upto(iSbdSize-1-1) do |i|
      file.write([i + 1].pack('V'))
    end
    file.write([-2].pack('V'))
  end
  #1.2 Set for B

  0.upto(iBsize-1-1) do |i|
    file.write([i + iSbdSize + 1].pack('V'))
  end
  file.write([-2].pack('V'))

  #1.3 Set for PPS

  0.upto(iPpsCnt-1-1) do |i|
    file.write([i+iSbdSize+iBsize+1].pack("V"))
  end
  file.write([-2].pack('V'))
  #1.4 Set for BBD itself ( 0xFFFFFFFD : BBD)

  0.upto(iBdCnt-1) do |i|
    file.write([0xFFFFFFFD].pack("V"))
  end
  #1.5 Set for ExtraBDList

  0.upto(iBdExL-1) do |i|
    file.write([0xFFFFFFFC].pack("V"))
  end
  #1.6 Adjust for Block

  if (iAllW + iBdCnt) % iBbCnt > 0
    file.write([-1].pack('V') *  (iBbCnt - ((iAllW + iBdCnt) % iBbCnt)))
  end
  #2.Extra BDList

  if iBdCnt > i1stBdL
    iN  = 0
    iNb = 0
    i1stBdL.upto(iBdCnt-1) do |i|
      if iN >= iBbCnt-1
        iN   = 0
        iNb += 1
        file.write([iAll+iBdCnt+iNb].pack("V"))
      end
      file.write([iBsize+iSbdSize+iPpsCnt+i].pack("V"))
      iN += 1
    end
    if (iBdCnt-i1stBdL) % (iBbCnt-1) > 0
      file.write([-1].pack("V") * ((iBbCnt-1) - ((iBdCnt-i1stBdL) % (iBbCnt-1))))
    end
    file.write([-2].pack('V'))
  end
end

#_saveBigData(iStBlk, aList, rh_info) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/WriteExcel/storage_lite.rb', line 337

def _saveBigData(iStBlk, aList, rh_info)
  iRes = 0
  file = rh_info[:fileh]

  #1.Write Big (ge 0x1000) Data into Block

  aList.each do |pps|
    if pps.type != PPS_TYPE_DIR
      #print "PPS: pps DEF:", defined(pps->{Data}), "\n"

      pps.size = pps._datalen   #Mod

      if (pps.size >= rh_info[:small_size]) ||
         ((pps.type == PPS_TYPE_ROOT) && !pps.data.nil?)
        #1.1 Write Data

        #Check for update

        if pps.pps_file
          iLen = 0
          pps.pps_file.seek(0, 0) #To The Top

          while sBuff = pps.pps_file.read(4096)
            iLen += sBuff.length
            file.write(sBuff)           #Check for update

          end
        else
          file.write(pps.data)
        end
        if pps.size % rh_info[:big_block_size] > 0
          file.write(
            "\x00" *
             (rh_info[:big_block_size] -
                  (pps.size % rh_info[:big_block_size]))
            )
        end
        #1.2 Set For PPS

        pps.start_block = iStBlk
        iStBlk += pps.size / rh_info[:big_block_size]
        iStBlk += 1 if pps.size % rh_info[:big_block_size] > 0
      end
    end
  end
end

#save(sFile, bNoAs = nil, rh_info = nil) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/WriteExcel/storage_lite.rb', line 173

def save(sFile, bNoAs = nil, rh_info = nil)
  #0.Initial Setting for saving

  rh_info = Hash.new unless rh_info
  if rh_info[:big_block_size]
    rh_info[:big_block_size] = 2 ** adjust2(rh_info[:big_block_size])
  else
    rh_info[:big_block_size] = 2 ** 9
  end
  if rh_info[:small_block_size]
    rh_info[:small_block_size] = 2 ** adjust2(rh_info[:small_block_size])
  else
    rh_info[:small_block_size] = 2 ** 6
  end
  rh_info[:small_size] = 0x1000
  rh_info[:pps_size]   = 0x80

  close_file = true

  #1.Open File

  #1.1 sFile is Ref of scalar

  if sFile.kind_of?(String)
    rh_info[:fileh] = open(sFile, "wb")
  else
    rh_info[:fileh] = sFile.binmode
  end

  iBlk = 0
  #1. Make an array of PPS (for Save)

  aList=[]
  if bNoAs
    _savePpsSetPnt2([self], aList, rh_info)
  else
    _savePpsSetPnt([self], aList, rh_info)
  end
  iSBDcnt, iBBcnt, iPPScnt = _calcSize(aList, rh_info)

  #2.Save Header

  _saveHeader(rh_info, iSBDcnt, iBBcnt, iPPScnt)

  #3.Make Small Data string (write SBD)

  # Small Datas become RootEntry Data

  @data = _makeSmallData(aList, rh_info)

  #4. Write BB

  iBBlk = iSBDcnt
  _saveBigData(iBBlk, aList, rh_info)

  #5. Write PPS

  _savePps(aList, rh_info)

  #6. Write BD and BDList and Adding Header informations

  _saveBbd(iSBDcnt, iBBcnt, iPPScnt, rh_info)

  #7.Close File

  return rh_info[:fileh].close if close_file != 0
end