Esempio n. 1
0
 void ComboBox1SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex == 0)
     {
         listView1.View = View.Details;
     }
     else if (comboBox1.SelectedIndex == 1)
     {
         listView1.View = View.LargeIcon;
     }
     else if (comboBox1.SelectedIndex == 2)
     {
         listView1.View = View.SmallIcon;
     }
     else if (comboBox1.SelectedIndex == 3)
     {
         listView1.View = View.Tile;
     }
     else if (comboBox1.SelectedIndex == 4)
     {
         listView1.View = View.List;
     }
     else
     {
         errorReport a = new errorReport(1, "Unimplemented feature.");
         a.messageBoxE();
     }
 }
Esempio n. 2
0
        errorReport dropSelfInProgramFiles()
        {
            //drops items into the program files. (overwrites files)
            errorReport returnValue = new errorReport();

            try{
                string programPath    = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                string executablePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                if (!Directory.Exists(programPath + @"\NWZip"))
                {
                    Directory.CreateDirectory(programPath + @"\NWZip");
                }
                if (System.IO.File.Exists(programPath + @"\NWZip\NWZip.exe"))
                {
                    System.IO.File.Delete(programPath + @"\NWZip\NWZip.exe");
                }
                System.IO.File.Copy(executablePath, programPath + @"\NWZip\NWZip.exe");
            }catch (Exception ex) {
                returnValue = new errorReport(1, ex.Message + "\r\nTry running the program again as administrator.");
            }
            return(returnValue);
        }
Esempio n. 3
0
        void BtnAddFileClick(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //add the file to the current directory in the archive, and update listView
                string filenameToAdd = currentDirInArchive;
                if (!currentDirInArchive.EndsWith("/", StringComparison.CurrentCulture))
                {
                    filenameToAdd += "/";
                }
                filenameToAdd  = filenameToAdd.Replace("\\", "/");
                filenameToAdd += stripSlashes(openFileDialog1.FileName);

                bool filesContains = false;
                for (int i = 0; i < files.Length; ++i)
                {
                    if (files[i] == filenameToAdd)
                    {
                        filesContains = true;
                    }
                }

                if (!filesContains)
                {
                    Array.Resize(ref files, files.Length + 1);
                    files[files.Length - 1] = filenameToAdd;

                    updateListView();
                    hasArchiveChanged = true;
                    updateMainWindowTitle();
                }
                else
                {
                    errorReport err = new errorReport(1, "File already exists in this directory.");
                    err.messageBoxE();
                }
            }
        }
Esempio n. 4
0
        errorReport writeFileAssociations()
        {
            //Write the file associations to the registry
            //to HKEY_CLASSES_ROOT
            errorReport returnValue = new errorReport();

            try{
                string      programPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                RegistryKey rk          = Registry.ClassesRoot.CreateSubKey(".nwz");
                if (rk != null)
                {
                    rk.SetValue("", "nwzfiletype", RegistryValueKind.String);
                    rk.Close();
                }
                rk = Registry.ClassesRoot.CreateSubKey("nwzfiletype");
                if (rk != null)
                {
                    rk.SetValue("", "NWZip Archive", RegistryValueKind.String);                     //file description
                    rk.Close();
                }
                rk = Registry.ClassesRoot.CreateSubKey(@"nwzfiletype\DefaultIcon");
                if (rk != null)
                {
                    rk.SetValue("", "\"" + programPath + "\\NWZip\\NWZip.exe\",0", RegistryValueKind.String);                     //icon
                    rk.Close();
                }
                rk = Registry.ClassesRoot.CreateSubKey(@"nwzfiletype\shell");
                if (rk != null)
                {
                    rk.Close();
                    rk = Registry.ClassesRoot.CreateSubKey(@"nwzfiletype\shell\open");
                    if (rk != null)
                    {
                        rk.Close();
                        rk = Registry.ClassesRoot.CreateSubKey(@"nwzfiletype\shell\open\command");
                        if (rk != null)
                        {
                            rk.SetValue("", "\"" + programPath + "\\NWZip\\NWZip.exe\" \"%1\"", RegistryValueKind.String);
                            rk.Close();
                        }
                    }
                }
                //to HKEY_LOCAL_MACHINE
                rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\.nwz");
                if (rk != null)
                {
                    rk.SetValue("", "nwzfiletype", RegistryValueKind.String);
                    rk.Close();
                }
                rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\nwzfiletype");
                if (rk != null)
                {
                    rk.SetValue("", "NWZip Archive", RegistryValueKind.String);                     //file description
                    rk.Close();
                }
                rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\nwzfiletype\DefaultIcon");
                if (rk != null)
                {
                    rk.SetValue("", "\"" + programPath + "\\NWZip\\NWZip.exe\",0", RegistryValueKind.String);                     //icon
                    rk.Close();
                }
                rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\nwzfiletype\shell");
                if (rk != null)
                {
                    rk.Close();
                    rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\nwzfiletype\shell\open");
                    if (rk != null)
                    {
                        rk.Close();
                        rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\nwzfiletype\shell\open\command");
                        if (rk != null)
                        {
                            rk.SetValue("", "\"" + programPath + "\\NWZip\\NWZip.exe\" \"%1\"", RegistryValueKind.String);
                            rk.Close();
                        }
                    }
                }
            }catch (Exception ex) {
                returnValue = new errorReport(1, ex.Message + "\r\nTry running the program again as administrator.");
            }
            return(returnValue);
        }
Esempio n. 5
0
        void PropertiesToolStripMenuItemClick(object sender, EventArgs e)         //listView > Properties
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 6
0
        void OnlyIfEmptyToolStripMenuItemClick(object sender, EventArgs e)         //listView > DeleteFolder > OnlyIfEmpty
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 7
0
        void RecursiveRecommendedToolStripMenuItemClick(object sender, EventArgs e)         //listView > DeleteFolder > Recursively
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 8
0
        void SelectedFileToolStripMenuItemClick(object sender, EventArgs e)         //listView > Extract > SelectedFile
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 9
0
        void CurrentDirectoryToolStripMenuItemClick(object sender, EventArgs e)         //listView > Extract > CurrentDir
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 10
0
        void BtnExtractClick(object sender, EventArgs e)
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 11
0
        void SaveAsFileClick(object sender, EventArgs e)         //File > Save As
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 12
0
        void ClearRecentFilesToolStripMenuItemClick(object sender, EventArgs e)         //File > Open Recent > Clear Recent Archives
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 13
0
        void DeleteFolderToolStripMenuItemClick(object sender, EventArgs e)         //treeView > DeleteFolder[]
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 14
0
        // open the archive details window
        void ArchiveDetailsClick(object sender, EventArgs e)         //Archive > Details
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 15
0
        // open the archive encryption window
        void ArchiveEncryptionClick(object sender, EventArgs e)         //Archive > Encryption
        {
            errorReport a = new errorReport(1, "Unimplemented feature.");

            a.messageBoxE();
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a shortcut
        /// </summary>
        /// <param name="pathTo">Shortcut's file opened when double clicked (ie. shortcut's target)</param>
        /// <param name="description">Shortcut's description</param>
        /// <param name="shortcutPath">Path of the shortcut to be saved</param>
        /// <param name="overwrite">Overwrite the shortcut if it exists</param>
        /// <returns>A class (errorReport) which contains error information (integer status, string message)</returns>
        public unsafe static errorReport createShortcut(string pathTo, string description, string shortcutPath, bool overwrite)
        {
            errorReport retVal = new errorReport();             //initial value of ERROR_SUCCESS

            //handle overwriting
            if (overwrite)
            {
                try{
                    if (System.IO.File.Exists(shortcutPath))
                    {
                        System.IO.File.Delete(shortcutPath);
                    }
                }catch (Exception ex) {
                    retVal = new errorReport(1, ex.Message + "\r\nCould not overwrite the shortcut. Try running the program again as administrator.");
                }
            }
            else
            {
                if (System.IO.File.Exists(shortcutPath))
                {
                    retVal = new errorReport(1, "Can't overwrite the shortcut.");
                }
            }
            //limits of shortcuts
            if (pathTo.Length > MAX_PATH)
            {
                retVal = new errorReport(1, "Your system does not support this program installing shortcuts.");
            }
            if (description.Length > MAX_PATH)
            {
                retVal = new errorReport(1, "Your system does not support this program installing shortcuts.");
            }
            if (shortcutPath.Length > MAX_PATH)
            {
                retVal = new errorReport(1, "Your system does not support this program installing shortcuts.");
            }
            //get heap for later memory allocation
            void *prcHeap = GetProcessHeap();
            char *wsz     = (char *)0;

            if (prcHeap != (void *)0)
            {
                wsz = (char *)HeapAlloc(prcHeap, HEAP_ZERO_MEMORY, (ulong)(sizeof(char) * (MAX_PATH + 1)));                                //allocate space for WCHARs
            }
            if (prcHeap == (void *)0)
            {
                retVal = new errorReport(1, "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
            }
            if (wsz == (char *)0)
            {
                retVal = new errorReport(1, "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
            }
            if (retVal.status == 0)
            {
                if (prcHeap != (void *)0)
                {
                    //allocate MAX_PATH+1 bytes of memory then set the pointer to the beginning of that memory
                    byte *pathToCA       = (byte *)HeapAlloc(prcHeap, HEAP_ZERO_MEMORY, (ulong)(sizeof(byte) * (MAX_PATH + 1)));
                    byte *descriptionCA  = (byte *)HeapAlloc(prcHeap, HEAP_ZERO_MEMORY, (ulong)(sizeof(byte) * (MAX_PATH + 1)));
                    byte *shortcutPathCA = (byte *)HeapAlloc(prcHeap, HEAP_ZERO_MEMORY, (ulong)(sizeof(byte) * (MAX_PATH + 1)));
                    if (pathToCA != (byte *)0)
                    {
                        if (descriptionCA != (byte *)0)
                        {
                            if (shortcutPathCA != (byte *)0)
                            {
                                //copy strs
                                for (int i = 0; i < pathTo.Length; ++i)
                                {
                                    pathToCA[i] = unchecked ((byte)pathTo[i]);
                                }
                                for (int i = 0; i < description.Length; ++i)
                                {
                                    descriptionCA[i] = unchecked ((byte)description[i]);
                                }
                                for (int i = 0; i < shortcutPath.Length; ++i)
                                {
                                    shortcutPathCA[i] = unchecked ((byte)shortcutPath[i]);                                    //note: not good for unicode username users
                                }
                                long hres = CoInitialize(UIntPtr.Zero);
                                if (hres >= 0)                                 //check if the COM library succeeded to load
                                //GUIDs (mingw?), can be found in the registry
                                {
                                    Guid IID_IPersistFile = new Guid("0000010B-0000-0000-C000-000000000046");
                                    Guid IID_IShellLink   = new Guid("000214EE-0000-0000-C000-000000000046");                               //ANSI (IID_IShellLinkA)
                                    Guid CLSID_ShellLink  = new Guid("00021401-0000-0000-C000-000000000046");

                                    //temp Pointers
                                    void *eax;
                                    void *edx;
                                    void *ecx;
                                    void *eax1;

                                    //CoCreateInstance (create an instance of IShellLink, and set shellLinkInterfacePtr as the pointer to that interface)
                                    void *shellLinkInterfacePtr;
                                    hres = CoCreateInstance(&CLSID_ShellLink, null, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void *)&shellLinkInterfacePtr);
                                    if (hres >= 0)
                                    {
                                        void *persistFileInterfacePtr;
                                        //shellLinkInterfacePtr->SetPath(byte*) (shellLinkInterfacePtr = %0, pathToCA = %1)
                                        eax = shellLinkInterfacePtr;                                   //mov eax, %0
                                        edx = shellLinkInterfacePtr;                                   //mov edx, %0
                                        edx = (void *)(*((uint **)edx));                               //mov edx, dword ptr [edx]
                                        edx = unchecked ((void *)((byte *)edx + 0x50));                //add edx, 50h
                                        ecx = (void *)(*((uint **)edx));                               //mov ecx, dword ptr [edx]
                                        edx = (void *)pathToCA;                                        //mov edx, %1
                                        //push edx
                                        //push eax
                                        //call ecx
                                        setPathDelegate setPath = (setPathDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(ecx), typeof(setPathDelegate));
                                        setPath(eax, edx);

                                        //shellLinkInterfacePtr->SetDescription(byte*) (shellLinkInterfacePtr = %0, descriptionCA = %1)
                                        eax = shellLinkInterfacePtr;                                 //mov eax, %0
                                        edx = shellLinkInterfacePtr;                                 //mov edx, %0
                                        edx = (void *)(*((uint **)edx));                             //mov edx, dword ptr [edx]
                                        edx = unchecked ((void *)((byte *)edx + 0x1C));              //add edx, 1Ch
                                        ecx = (void *)(*((uint **)edx));                             //mov ecx, dword ptr [edx]
                                        edx = descriptionCA;                                         //mov edx, %1
                                        //push edx
                                        //push eax
                                        //call ecx
                                        setDescriptionDelegate setDescription = (setDescriptionDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(ecx), typeof(setDescriptionDelegate));
                                        setDescription(eax, edx);

                                        //hres = shellLinkInterfacePtr->QueryInterface(Guid*, void*) (shellLinkInterfacePtr = %0, persistFileInterfacePtr = %1, IID_IPersistFile = %2)
                                        eax  = shellLinkInterfacePtr;                      //mov eax, %0
                                        ecx  = eax;                                        //mov ecx, eax
                                        eax  = shellLinkInterfacePtr;                      //mov eax, %0
                                        eax  = (void *)(*((uint **)eax));                  //mov eax, dword ptr [eax]
                                        edx  = (void *)(*((uint **)eax));                  //mov edx, dword ptr [eax]
                                        eax  = (void *)(&persistFileInterfacePtr);         //lea eax, [%1]
                                        eax1 = eax;                                        //push eax ; save it as "eax1" for later use
                                        eax  = (void *)(&IID_IPersistFile);                //lea eax, [%2]
                                        //push eax
                                        //push ecx
                                        //call edx
                                        queryInterfaceDelegate queryInterface = (queryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(edx), typeof(queryInterfaceDelegate));
                                        hres = queryInterface(ecx, eax, eax1);
                                        if (hres >= 0)
                                        {
                                            MultiByteToWideChar(0, 0, shortcutPathCA, -1, wsz, MAX_PATH);

                                            //hres = persistFileInterfacePtr->Save(char*, bool) (persistFileInterfacePtr = %0, wsz = %1)
                                            eax = persistFileInterfacePtr;                                //mov eax, %0
                                            edx = persistFileInterfacePtr;                                //mov edx, %0
                                            edx = (void *)(*((uint **)edx));                              //mov edx, dword ptr [edx]
                                            edx = unchecked ((void *)((byte *)edx + 0x18));               //add edx, 18h
                                            ecx = (void *)(*((uint **)edx));                              //mov edx, dword ptr [edx]
                                            //push 1
                                            edx = (void *)wsz;                                            //mov edx, %1
                                            //push edx
                                            //push eax
                                            //call ecx
                                            saveDelegate save = (saveDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(ecx), typeof(saveDelegate));
                                            hres = save(eax, edx, (void *)1);

                                            //persistFileInterfacePtr->Release() (persistFileInterfacePtr = %0)
                                            eax = persistFileInterfacePtr;                         //mov eax, %0
                                            edx = eax;                                             //mov edx, eax
                                            eax = persistFileInterfacePtr;                         //mov eax, %0
                                            eax = (void *)(*((uint **)eax));                       //mov eax, dword ptr [eax]
                                            eax = unchecked ((void *)((byte *)eax + 0x8));         //add eax, 8
                                            eax = (void *)(*((uint **)eax));                       //mov eax, dword ptr [eax]
                                            //push edx
                                            //call eax
                                            releaseDelegate releasePRF = (releaseDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(eax), typeof(releaseDelegate));
                                            releasePRF(edx);
                                        }
                                        else
                                        {
                                            //could not query the interface
                                            retVal = new errorReport(unchecked ((uint)hres), "Error creating shortcuts. Try restarting the prgraom. Running it as administrator may also help.");
                                        }
                                        //shellLinkInterfacePtr->Release() (shellLinkInterfacePtr = %0)
                                        eax = shellLinkInterfacePtr;                       //mov eax, %0
                                        edx = eax;                                         //mov edx, eax
                                        eax = shellLinkInterfacePtr;                       //mov eax, %0
                                        eax = (void *)(*((uint **)eax));                   //mov eax, dword ptr [eax]
                                        eax = unchecked ((void *)((byte *)eax + 0x8));     //add eax, 8
                                        eax = (void *)(*((uint **)eax));                   //mov eax, dword ptr [eax]
                                        //push edx
                                        //call eax
                                        releaseDelegate releaseSHL = (releaseDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(eax), typeof(releaseDelegate));
                                        releaseSHL(edx);
                                    }
                                    else
                                    {
                                        //error in CoCreateInstance
                                        retVal = new errorReport(unchecked ((uint)hres), "Error creating shortcuts. Try restarting the prgraom. Running it as administrator may also help.");
                                    }
                                    //uninitialize (clean up)
                                    CoUninitialize();
                                }
                                else
                                {
                                    retVal = new errorReport(unchecked ((uint)hres), "Error creating shortcuts. Try restarting the prgraom. Running it as administrator may also help.");
                                }
                                //free memory
                                HeapFree(prcHeap, 0, pathToCA);
                                HeapFree(prcHeap, 0, descriptionCA);
                                HeapFree(prcHeap, 0, shortcutPathCA);
                            }
                            else
                            {
                                //wasn't enough memory on heap to allocate shortcutPathCA
                                HeapFree(prcHeap, 0, pathToCA);
                                HeapFree(prcHeap, 0, descriptionCA);
                                retVal = new errorReport(1, "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
                            }
                        }
                        else
                        {
                            //wasn't enough memory on heap to allocate descriptionCA
                            HeapFree(prcHeap, 0, pathToCA);
                            retVal = new errorReport(1, "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
                        }
                    }
                    else
                    {
                        //wasn't enough memory on heap to allocate pathToCA
                        retVal = new errorReport(1, "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
                    }
                }
                else
                {
                    //could not GetProcessHeap()
                    retVal = new errorReport(GetLastError(), "Error creating shortcuts. Try restarting the program. Running it as administrator may also help.");
                }
            }
            //free wsz
            if (wsz != (char *)0)
            {
                HeapFree(prcHeap, 0, wsz);
            }
            return(retVal);
        }