Exemple #1
0
        static int Main(string[] args)
        {
            if (args[0] == "--help")
            {
                Console.WriteLine("usage:\r\nvget image-file filename [newname]\r\nvget --help");
                return(0);
            }
            switch (args.Length)
            {
            case 2:
            case 3:
                if (!System.IO.File.Exists(args[0]))
                {
                    Console.Error.WriteLine("vget: Disk image file does not exist.");
                    return(1);
                }
                try
                {
                    FATVolume fv = new FATVolume(args[0]);
                    if (!fv.Exists(args[1]))
                    {
                        Console.Error.WriteLine("vget: File does not exist on image.");
                        return(1);
                    }
                    args[1] = args[1].Replace('/', '\\');
                    string name =
                        args.Length == 3 ?
                        args[2] :
                        args[1].Contains("\\") ?
                        args[1].Substring(args[1].LastIndexOf('\\') + 1) :
                        args[1];

                    System.IO.Stream sw = new System.IO.FileStream(name, System.IO.FileMode.Create);
                    System.IO.Stream sr = fv.OpenFile(args[1], System.IO.FileAccess.Read, System.IO.FileMode.Open);
                    byte[]           x  = new byte[1024];
                    while (sr.Position < sr.Length)
                    {
                        sw.Write(x, 0, sr.Read(x, 0, (int)Math.Min(1024, sr.Length - sr.Position)));
                    }
                    sr.Close();
                    sw.Close();
                    fv.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("vget: error: {0}", e.Message);
                    return(1);
                }
                return(0);

            default:
                Console.Error.WriteLine("vget: wrong number of arguments given");
                Console.WriteLine("usage:\r\nvget image-file filename newname\r\nvget --help");
                return(1);
            }
        }
Exemple #2
0
        static int Main(string[] args)
        {
            if (args[0] == "--help")
            {
                Console.WriteLine("usage:\r\nvout image-file filename\r\nvout --help");
                return(0);
            }
            switch (args.Length)
            {
            case 2:
                if (!System.IO.File.Exists(args[0]))
                {
                    Console.Error.WriteLine("vout: Disk image file does not exist.");
                    return(1);
                }
                try
                {
                    FATVolume fv = new FATVolume(args[0]);
                    if (!fv.Exists(args[1]))
                    {
                        Console.Error.WriteLine("vout: File does not exist on image.");
                        return(1);
                    }
                    System.IO.StreamReader tr = new System.IO.StreamReader(fv.OpenFile(args[1], System.IO.FileAccess.Read, System.IO.FileMode.Open));
                    System.Console.Out.Write(tr.ReadToEnd());
                    tr.Close();
                    fv.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("vout: error: {0}", e.Message);
                    return(1);
                }
                return(0);

            default:
                Console.Error.WriteLine("vout: wrong number of arguments given");
                Console.WriteLine("usage:\r\nvout image-file filename\r\nvout --help");
                return(1);
            }
        }
Exemple #3
0
        static int Main(string[] args)
        {
            if (args[0] == "--help")
            {
                Console.WriteLine("usage:\r\nvexists image-file filename [-f|-d]\r\nvexists --help");
                return(0);
            }
            int       b = 0;
            FATVolume fv;

            switch (args.Length)
            {
            case 2:
                if (!System.IO.File.Exists(args[0]))
                {
                    Console.Error.WriteLine("vexists: Disk image file does not exist.");
                    return(0);
                }
                try
                {
                    fv = new FATVolume(args[0]);
                    b  = fv.Exists(args[1]) == false ? 0 : 1;
                    fv.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("vexists: error: {0}", e.Message);
                    return(0);
                }
                return(b);

            case 3:
                if (!System.IO.File.Exists(args[0]))
                {
                    Console.Error.WriteLine("vexists: Disk image file does not exist.");
                    return(0);
                }
                if (args[2] != "-d" && args[2] != "-f")
                {
                    Console.Error.WriteLine("vexists: Third argument is not -d or -f");
                    return(0);
                }
                try
                {
                    fv = new FATVolume(args[0]);
                    b  = (args[2] == "-f" ? fv.FileExists(args[1]) : fv.DirectoryExists(args[1])) == false ? 0 : 1;
                    fv.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.WriteLine("vexists: error: {0}", e.Message);
                    return(0);
                }
                return(b);

            default:
                Console.Error.WriteLine("vexists: wrong number of arguments given");
                Console.WriteLine("usage:\r\nvexists image-file filename [-f|-d]\r\nvexists --help");
                return(0);
            }
        }
Exemple #4
0
        static int Main(string[] args)
        {
            switch (args.Length)
            {
            case 0:
                System.Console.WriteLine("usage: vfinfo image-name path");
                return(1);

            case 1:
                if (args[0] == "--help")
                {
                    System.Console.WriteLine("usage: vattr image-name path rhsa");
                    return(0);
                }
                System.Console.Error.WriteLine("missing parameter - path");
                return(1);

            case 2:
                try
                {
                    FATVolume fatvol = new FATVolume(args[0]);
                    if (!fatvol.Exists(args[1]))
                    {
                        throw new Exception(string.Format("File or directory {0} does not exist on disk image.", args[1]));
                    }
                    FileInfo       fi   = fatvol.GetFileInfo(args[1]);
                    FileAttributes a    = fi.Attributes;
                    string         attr = "";
                    if (a == FileAttributes.None)
                    {
                        attr += ("(no attributes) ");
                    }
                    if ((a & FileAttributes.Directory) != FileAttributes.None)
                    {
                        attr += ("directory ");
                    }
                    if ((a & FileAttributes.ReadOnly) != FileAttributes.None)
                    {
                        attr += ("read only ");
                    }
                    if ((a & FileAttributes.Hidden) != FileAttributes.None)
                    {
                        attr += ("hidden ");
                    }
                    if ((a & FileAttributes.System) != FileAttributes.None)
                    {
                        attr += ("system ");
                    }
                    if ((a & FileAttributes.Archive) != FileAttributes.None)
                    {
                        attr += ("archive ");
                    }
                    Console.WriteLine("         Name:\t{0}", fi.Name);
                    Console.WriteLine("   Attributes:\t{0}", attr);
                    Console.WriteLine("         Size:\t{0} bytes", fi.Size);
                    Console.WriteLine("First cluster:\t{0}", fi.FirstCluster);
                    Console.WriteLine("Creation date:\t{0} {1}", fi.CreateTime.ToLongDateString(), fi.CreateTime.ToLongTimeString());
                    Console.WriteLine("Modified date:\t{0} {1}", fi.LastWriteTime.ToLongDateString(), fi.LastWriteTime.ToLongTimeString());
                    Console.WriteLine($"  Access date:\t{fi.LastAccessDate.ToLongDateString()}");
                    fatvol.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.Write("error: ");
                    System.Console.Error.WriteLine(e.Message);
                    return(1);
                }
                return(0);

            default:
                System.Console.Error.WriteLine("too many paramaters");
                System.Console.Error.WriteLine("usage: vfinfo image-name path");
                return(1);
            }
        }
Exemple #5
0
        static int Main(string[] args)
        {
            switch (args.Length)
            {
            case 0:
                System.Console.WriteLine("usage: vattr image-name path rhsa");
                return(1);

            case 1:
                if (args[0] == "--help")
                {
                    System.Console.WriteLine("usage: vattr image-name path rhsa");
                    return(0);
                }
                System.Console.Error.WriteLine("missing parameter - path");
                return(1);

            case 2:
                System.Console.Error.WriteLine("missing parameter - attributes");
                return(1);

            case 3:
                try
                {
                    FATVolume fatvol = new FATVolume(args[0]);
                    if (!fatvol.Exists(args[1]))
                    {
                        throw new Exception(string.Format("File or directory {0} does not exist on disk image.", args[1]));
                    }
                    FileAttributes a = fatvol.GetAttributes(args[1]) & (FileAttributes.Directory);
                    for (int i = 0; i < args[2].Length; i++)
                    {
                        switch (args[2][i])
                        {
                        case 'r':
                            a |= FileAttributes.ReadOnly;
                            break;

                        case 'h':
                            a |= FileAttributes.Hidden;
                            break;

                        case 's':
                            a |= FileAttributes.System;
                            break;

                        case 'a':
                            a |= FileAttributes.Archive;
                            break;

                        default:
                            throw new Exception(string.Format("Unrecognized attrubute - '{0}'", args[2][i]));
                        }
                    }
                    fatvol.SetAttributes(args[1], a);
                    fatvol.Close();
                }
                catch (Exception e)
                {
                    System.Console.Error.Write("error: ");
                    System.Console.Error.WriteLine(e.Message);
                    return(1);
                }
                return(0);

            default:
                System.Console.Error.WriteLine("too many paramaters");
                System.Console.Error.WriteLine("usage: vattr image-name path rhsa");
                return(1);
            }
        }