2014-12-18 18:21:38 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2012 dorkbox, llc
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-09-22 09:25:27 +02:00
|
|
|
package dorkbox.cabParser.structure;
|
2014-12-18 18:21:38 +01:00
|
|
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
2017-09-22 09:25:27 +02:00
|
|
|
import dorkbox.cabParser.CabParser;
|
2017-08-23 13:54:31 +02:00
|
|
|
|
2014-12-18 18:21:38 +01:00
|
|
|
public final class CabEnumerator implements Enumeration<Object> {
|
|
|
|
private int fileCount = 0;
|
|
|
|
private int folderCount = 0;
|
|
|
|
|
2016-02-10 18:57:16 +01:00
|
|
|
private CabParser cabParser;
|
2014-12-18 18:21:38 +01:00
|
|
|
|
|
|
|
private boolean b;
|
|
|
|
private int folderIndex;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object nextElement() {
|
|
|
|
if (!this.b) {
|
2016-02-10 18:57:16 +01:00
|
|
|
if (this.fileCount < this.cabParser.header.cFiles) {
|
|
|
|
return this.cabParser.files[this.fileCount++];
|
2014-12-18 18:21:38 +01:00
|
|
|
}
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:57:16 +01:00
|
|
|
if (this.cabParser.files[this.fileCount].iFolder != this.folderIndex) {
|
|
|
|
this.folderIndex = this.cabParser.files[this.fileCount].iFolder;
|
2014-12-18 18:21:38 +01:00
|
|
|
|
2016-02-10 18:57:16 +01:00
|
|
|
if (this.folderCount < this.cabParser.folders.length) {
|
|
|
|
return this.cabParser.folders[this.folderCount++];
|
2014-12-18 18:21:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:57:16 +01:00
|
|
|
if (this.fileCount < this.cabParser.header.cFiles) {
|
|
|
|
return this.cabParser.files[this.fileCount++];
|
2014-12-18 18:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:57:16 +01:00
|
|
|
public CabEnumerator(CabParser decoder, boolean b) {
|
|
|
|
this.cabParser = decoder;
|
2014-12-18 18:21:38 +01:00
|
|
|
this.b = b;
|
|
|
|
this.folderIndex = -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasMoreElements() {
|
2016-02-10 18:57:16 +01:00
|
|
|
return this.fileCount < this.cabParser.header.cFiles;
|
2014-12-18 18:21:38 +01:00
|
|
|
}
|
|
|
|
}
|