override protected void DoOpen (FileInfo info) { try { Gsf.Global.Init (); Input input = new InputStdio (info.FullName); if (input != null) { input = input.Uncompress(); file = new InfileMSOle (input); input.Dispose (); } if (input == null || file == null) { Log.Warn ("Unable to open '{0}': input/file is null", info.FullName); Error (); return; } OpenStorage (info); } catch (Exception e) { Log.Warn (e, "Unable to open " + info.FullName); Error (); return; } }
override protected void DoOpen(FileInfo info) { try { Gsf.Global.Init(); Input input = new InputStdio(info.FullName); if (input != null) { input = input.Uncompress(); file = new InfileMSOle(input); input.Dispose(); } if (input == null || file == null) { Log.Warn("Unable to open '{0}': input/file is null", info.FullName); Error(); return; } OpenStorage(info); } catch (Exception e) { Log.Warn(e, "Unable to open " + info.FullName); Error(); return; } }
/* --------------------------------------------------------------------------- * factory method Open(filename) * --------------------------------------------------------------------------- * Opens the given file, creates a new infile instance, associates the file * with the newly created instance and returns a result pair with the infile * reference and a status code. * * pre-conditions: * o filename must reference an existing, accessible file. * * post-conditions: * o new infile created and returned * o line and column counters of the newly created infile are set to 1 * o Success is returned in status * * error-conditions: * o if the file represented by filename cannot be found * infile is null, status is FileNotFound * o if the file represented by filename cannot be accessed * infile is null, status is FileAccessDenied * ------------------------------------------------------------------------ */ public static Result <IInfile, InfileStatus> Open(string filename) { InfileStatus status; Infile infile = null; byte[] buffer = null; ulong buflen = 0; ulong bytesRead = 0; if (string.IsNullOrEmpty(filename)) { status = InfileStatus.InvalidReference; return(new Result <IInfile, InfileStatus>(null, status)); } /* end if */ var result = FileIO.Open(filename, FileIOMode.Read); if (result.Value() == null) { switch (result.Status()) { case FileIOStatus.InvalidReference: status = InfileStatus.InvalidReference; break; case FileIOStatus.FileNotFound: status = InfileStatus.FileNotFound; break; case FileIOStatus.FileAccessDenied: status = InfileStatus.FileAccessDenied; break; default: status = InfileStatus.IOSubsystemError; break; } /* end switch */ return(new Result <IInfile, InfileStatus> (null, status)); } /* end if */ result.Value().ReadNBytes(ref buffer, buflen, out bytesRead); result.Value().Close(); if ((buffer == null) || (buflen == 0)) { status = InfileStatus.SourceFileIsEmpty; return(new Result <IInfile, InfileStatus> (null, status)); } /* end if */ infile = new Infile(); infile.filename = filename; infile.index = 0; infile.line = 1; infile.column = 1; infile.markerIsSet = false; infile.markedIndex = 0; infile.buflen = buflen; infile.buffer = buffer; infile.status = InfileStatus.Success; infile.isOpen = true; return(new Result <IInfile, InfileStatus>(infile, infile.status)); } /* end Open */