|
-
Nov 1st, 2007, 09:54 AM
#1
Thread Starter
Fanatic Member
[2005] Zipping and Unzipping Files
I know this has been asked before but everything I can find points to the same solution in the codebank
http://www.vbforums.com/showthread.p...ghlight=ziplib
Well I tried this solution and after running the conversion wizard to convert it to 2005 instead of 2003 that it comes with I get a huge list of errors. They are probably easy to fix errors but I'm just starting with VB .Net (finally) and I'm not very fluent in it yet. I'm starting small in VB .NET and trying to write a file browser program that will allow me to look through some files I have and preview webpages stored in those files.
I have to have the ability to unzip files because some of these folders contain zipped files that have to be unzipped in order to view the wepage zipped there.
So anyway on to the problem... When I try to work with this file, I add the reference to the #ziplib library and these are the errors I have left and cannot build the library due to it.
Code:
Error 2 Option Strict On disallows implicit conversions from 'Long' to 'Integer'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 326 32 Wunnell.IO
Error 3 Option Strict On disallows implicit conversions from 'Boolean' to 'String'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 551 55 Wunnell.IO
Error 4 Option Strict On disallows implicit conversions from 'Boolean' to 'String'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 586 55 Wunnell.IO
Error 5 Overload resolution failed because no accessible 'New' accepts this number of arguments. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 649 33 Wunnell.IO
Error 6 Option Strict On disallows implicit conversions from 'Boolean' to 'String'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 651 54 Wunnell.IO
Error 7 Option Strict On disallows implicit conversions from 'Boolean' to 'String'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 691 55 Wunnell.IO
Error 8 Overload resolution failed because no accessible 'New' accepts this number of arguments. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 746 33 Wunnell.IO
Error 9 Option Strict On disallows implicit conversions from 'Boolean' to 'String'. C:\Users\Steven Hickerson\Downloads\VB\Wunnell.IO 1.0.0.1\Wunnell.IO\Wunnell.IO\Zip.vb 748 54 Wunnell.IO
Can anyone give me a hand in getting this up and running?
Thanks!
-
Nov 1st, 2007, 09:58 AM
#2
Re: [2005] Zipping and Unzipping Files
 Originally Posted by StevenHickerson
They are probably easy to fix errors but I'm just starting with VB .Net (finally) and I'm not very fluent in it yet.
I feel your pain. I'm in the exact same boat. Interesting experience being a noob again ain't it? 
I've had many of these same errors. You need to post the lines of code that are throwing the errors. The fixes, as I recall, were fairly simple, but we would need to see what is generating them.
-
Nov 1st, 2007, 10:41 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Zipping and Unzipping Files
Ok I traced it back as far as I can, even looked in the sharp lib source to see if I could get an idea of what is going on there.
All the problems are a result of calling
ZipNameTransform()
This line
Code:
transform = New ZipNameTransform(true, sourceName)
is used in 2 locations and is the one causing errors 5 & 8. I'm not sure what is trying to be done in the wrapper class in the codebank here, so not exactly sure what steps to take to fix it.
All the other errors for conversion type, the int conversion was easy enough I just used cint() to fix it, are dealing with ZipNameTransform. In all cases it's
Code:
New ZipNameTransform(False)
When checking what arguments should be passed it says
Code:
New ( TrimPrefix as string )
Again I don't know the function of this to know what to do to fix it?
Is it possible that it's a error in the latest release of the #ziplib and it should be asking for a boolean instead of a string, or is zipnametransform being called in correctly in the codebank project.
I could put quotes around all the False and Trues to make them strings but I don't know if thats a proper solution to the problem or not. As for the arguments, I'm not sure where to even begin on pass the correct arguments to make sure the file name gets transformed correctly. If I dont have that right it simply wont work because the filename wont exist =P
This is going to make this post long but since it may be needed.. here ist he ZipNameTransform Class, it's not in VB so I don't know the syntax very well I can only follow the jest of it.
Code:
using System;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Core;
namespace ICSharpCode.SharpZipLib.Zip
{
/// <summary>
/// ZipNameTransform transforms names as per the Zip file naming convention.
/// </summary>
/// <remarks>The use of absolute names is supported although its use is not valid
/// according to Zip naming conventions, and should not be used if maximum compatability is desired.</remarks>
public class ZipNameTransform : INameTransform
{
#region Constructors
/// <summary>
/// Initialize a new instance of <see cref="ZipNameTransform"></see>
/// </summary>
public ZipNameTransform()
{
}
/// <summary>
/// Initialize a new instance of <see cref="ZipNameTransform"></see>
/// </summary>
/// <param name="trimPrefix">The string to trim from front of paths if found.</param>
public ZipNameTransform(string trimPrefix)
{
TrimPrefix = trimPrefix;
}
#endregion
/// <summary>
/// Static constructor.
/// </summary>
static ZipNameTransform()
{
char[] invalidPathChars;
#if NET_1_0 || NET_1_1 || NETCF_1_0
invalidPathChars = Path.InvalidPathChars;
#else
invalidPathChars = Path.GetInvalidPathChars();
#endif
int howMany = invalidPathChars.Length + 2;
InvalidEntryCharsRelaxed = new char[howMany];
Array.Copy(invalidPathChars, 0, InvalidEntryCharsRelaxed, 0, invalidPathChars.Length);
InvalidEntryCharsRelaxed[howMany - 1] = '*';
InvalidEntryCharsRelaxed[howMany - 2] = '?';
howMany = invalidPathChars.Length + 4;
InvalidEntryChars = new char[howMany];
Array.Copy(invalidPathChars, 0, InvalidEntryChars, 0, invalidPathChars.Length);
InvalidEntryChars[howMany - 1] = ':';
InvalidEntryChars[howMany - 2] = '\\';
InvalidEntryChars[howMany - 3] = '*';
InvalidEntryChars[howMany - 4] = '?';
}
/// <summary>
/// Transform a directory name according to the Zip file naming conventions.
/// </summary>
/// <param name="name">The directory name to transform.</param>
/// <returns>The transformed name.</returns>
public string TransformDirectory(string name)
{
name = TransformFile(name);
if (name.Length > 0) {
if ( !name.EndsWith("/") ) {
name += "/";
}
}
else {
throw new ZipException("Cannot have an empty directory name");
}
return name;
}
/// <summary>
/// Transform a windows file name according to the Zip file naming conventions.
/// </summary>
/// <param name="name">The file name to transform.</param>
/// <returns>The transformed name.</returns>
public string TransformFile(string name)
{
if (name != null) {
string lowerName = name.ToLower();
if ( (trimPrefix_ != null) && (lowerName.IndexOf(trimPrefix_) == 0) ) {
name = name.Substring(trimPrefix_.Length);
}
// The following can throw exceptions when the name contains invalid characters
if (Path.IsPathRooted(name) == true) {
// NOTE:
// for UNC names... \\machine\share\zoom\beet.txt gives \zoom\beet.txt
name = name.Substring(Path.GetPathRoot(name).Length);
}
name = name.Replace(@"\", "/");
while ( (name.Length > 0) && (name[0] == '/')) {
name = name.Remove(0, 1);
}
name = MakeValidName(name, '_');
}
else {
name = string.Empty;
}
return name;
}
/// <summary>
/// Get/set the path prefix to be trimmed from paths if present.
/// </summary>
/// <remarks>The prefix is trimmed before any conversion from
/// a windows path is done.</remarks>
public string TrimPrefix
{
get { return trimPrefix_; }
set {
trimPrefix_ = value;
if (trimPrefix_ != null) {
trimPrefix_ = trimPrefix_.ToLower();
}
}
}
/// <summary>
/// Force a name to be valid by replacing invalid characters with a fixed value
/// </summary>
/// <param name="name">The name to force valid</param>
/// <param name="replacement">The replacement character to use.</param>
/// <returns>Returns a valid name</returns>
static string MakeValidName(string name, char replacement)
{
int index = name.IndexOfAny(InvalidEntryChars);
if (index > 0) {
StringBuilder builder = new StringBuilder(name);
while (index >= 0 ) {
builder[index] = replacement;
if (index >= name.Length) {
index = -1;
}
else {
index = name.IndexOfAny(InvalidEntryChars, index + 1);
}
}
name = builder.ToString();
}
return name;
}
/// <summary>
/// Test a name to see if it is a valid name for a zip entry.
/// </summary>
/// <param name="name">The name to test.</param>
/// <param name="relaxed">If true checking is relaxed about windows file names and absolute paths.</param>
/// <returns>Returns true if the name is a valid zip name; false otherwise.</returns>
/// <remarks>Zip path names are actually in Unix format, and should only contain relative paths.
/// This means that any path stored should not contain a drive or
/// device letter, or a leading slash. All slashes should forward slashes '/'.
/// An empty name is valid for a file where the input comes from standard input.
/// A null name is not considered valid.
/// </remarks>
public static bool IsValidName(string name, bool relaxed)
{
bool result = (name != null);
if ( result ) {
if ( relaxed ) {
result = name.IndexOfAny(InvalidEntryCharsRelaxed) < 0;
}
else {
result =
(name.IndexOfAny(InvalidEntryChars) < 0) &&
(name.IndexOf('/') != 0);
}
}
return result;
}
/// <summary>
/// Test a name to see if it is a valid name for a zip entry.
/// </summary>
/// <param name="name">The name to test.</param>
/// <returns>Returns true if the name is a valid zip name; false otherwise.</returns>
/// <remarks>Zip path names are actually in unix format,
/// and should only contain relative paths if a path is present.
/// This means that the path stored should not contain a drive or
/// device letter, or a leading slash. All slashes should forward slashes '/'.
/// An empty name is valid where the input comes from standard input.
/// A null name is not considered valid.
/// </remarks>
public static bool IsValidName(string name)
{
bool result =
(name != null) &&
(name.IndexOfAny(InvalidEntryChars) < 0) &&
(name.IndexOf('/') != 0)
;
return result;
}
#region Instance Fields
string trimPrefix_;
#endregion
#region Class Fields
static readonly char[] InvalidEntryChars;
static readonly char[] InvalidEntryCharsRelaxed;
#endregion
}
}
Last edited by StevenHickerson; Nov 1st, 2007 at 10:54 AM.
-
Nov 1st, 2007, 11:05 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Zipping and Unzipping Files
Ok I really do feel like a noob, you know making all the noob mistakes and posting prematurely. I think I figured this out on my own, but as long as the post is here I may as well make use of it.
It looks to me as if the ZipNameTransform class has been changed since the code in the codebank was written. It looks like there use to be three different types of Transforms, Relative, Full, and none.
If I'm understanding the code correctly in the class the only thing a transform is doing is making sure the filename is a valid filename for the zip utility.
Since it looks like they combine all the types into one, I should be able to just change all the ZipNameTransforms to New ZipNameTransform() without any arguments since I don't think I'm going to be worrying about remove text prefix. I could always add that as a variable to the functions that call it if I want to keep the functionality there in my projects.
Does that look correct to you guys that understand the code the class is written in better? Like i said, I dont know the syntax of that code exactly but I can follow it and understand what it's doing more or less.
-
Nov 1st, 2007, 11:19 AM
#5
Re: [2005] Zipping and Unzipping Files
I'll leave it to the C# folks to determine if the code makes sense.
I'm posting to ask a favor.
 Originally Posted by StevenHickerson
It looks to me as if the ZipNameTransform class has been changed since the code in the codebank was written. It looks like there use to be three different types of Transforms, Relative, Full, and none.
Would you pop back to that thread in the codebank and post your observations? This might help someone else who is trying to use it, and also the author of the thread in trying to update it. Include a link to this thread.
Thanks.
Last edited by Hack; Nov 1st, 2007 at 11:24 AM.
-
Nov 1st, 2007, 12:00 PM
#6
Re: [2005] Zipping and Unzipping Files
Did you notice that it was written in 2003/1.1?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 1st, 2007, 01:14 PM
#7
Thread Starter
Fanatic Member
Re: [2005] Zipping and Unzipping Files
Yeah I noticed it was written way back when, but it's still the only solution pointed to on the forums so thats what I was trying to use I found a fix at least I think I have and will post it under the thread in codebank for future people that try to use it.
-
Nov 1st, 2007, 01:31 PM
#8
Re: [2005] Zipping and Unzipping Files
Ok, cool. Thanks I'll look at it in a bit.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 1st, 2007, 04:38 PM
#9
Re: [2005] Zipping and Unzipping Files
try my example on unzipping using sharpziplib
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|