Example #1
0
        /// <summary>
        /// Decripta tutti i file tenendo traccia sulla griglia del vecchio AGL per ognuno
        /// Tale operazione può essere effettuata solo al collegamento del dispositivo
        /// </summary>
        void DecryptAllFiles()
        {
            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                var row = dataGrid.Rows[i];
                if (row.Cells[0].Value == null)
                {
                    continue;
                }

                var filename = DevicePath + row.Cells[0].Value.ToString();

                var aglService = new Services.FileAGLService(filename);
                if (aglService.Exists() == false)
                {
                    continue;
                }
                var decryptoService = new Services.FileDecryptService(filename);

                string currentPassword = string.Empty;

                if (OwnerMode)
                {
                    // in tal caso mi basa una sola delle chiavi associate per accedere al file
                    var keys = GetKeysByRowIndex(i);
                    if (keys == null || keys.Count == 0)
                    {
                        dataGrid.Rows.RemoveAt(i);
                        continue;
                    }

                    currentPassword = keys[0];
                }
                else
                {
                    currentPassword = UserPassword;

                    // memorizza l'AGL del file
                    var restoreService = new Services.FileSSRestoreService(DeviceName, row.Cells[0].Value.ToString());
                    restoreService.Store(aglService.GetBytes());

                    RestoreData.Add(restoreService);
                }

                if (decryptoService.Decrypt(currentPassword, OwnerMode) && !OwnerMode)
                {
                    RestoreData[RestoreData.Count - 1].SetKey(decryptoService.Key);
                }
            }
        }
Example #2
0
        // Inizializza l'AGL dei file presenti sul dispositivo
        void InitAGL()
        {
            var groups = new Dictionary <string, string>();

            if (OwnerMode)
            {
                groups = Keys.Get(DeviceId);
            }

            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                var row = dataGrid.Rows[i];

                if (row.Cells[0].Value == null)
                {
                    continue;
                }
                string filename = DevicePath + row.Cells[0].Value.ToString();
                var    agl      = new Services.FileAGLService(filename);

                if (OwnerMode)
                {
                    if (agl.Exists())
                    {
                        foreach (var name in groups.Keys)
                        {
                            string temp    = string.Empty;
                            int    clIndex = GetColumnIndex(name);
                            if (clIndex != -1)
                            {
                                if (agl.Access(groups[name], out temp))
                                {
                                    row.Cells[clIndex].Value = true;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // no wner mode
                }
            }
        }
Example #3
0
        /// <summary>
        /// Riempie la griglia
        /// Rileva i file presenti nel dispositivo e li riporta nella tabella
        /// </summary>
        void InitFiles()
        {
            foreach (var file in Directory.GetFiles(DevicePath))
            {
                var attr = File.GetAttributes(file);
                if (attr != (FileAttributes.Hidden | FileAttributes.Archive) && attr != FileAttributes.Hidden)
                {
                    if (OwnerMode)
                    {
                        dataGrid.Rows.Add(Path.GetFileName(file));
                    }
                    else
                    {
                        // Nel caso non sono il proprietario del dispositivo, devo aggiungere solo i file a cui posso accedere
                        // e ovviamente i file privi di AGL
                        var    aglService = new Services.FileAGLService(file);
                        string temp       = string.Empty;
                        if (aglService.Exists())
                        {
                            if (aglService.Access(UserPassword, out temp))
                            {
                                int index = dataGrid.Rows.Add(Path.GetFileName(file), true);
                                dataGrid.Rows[index].Cells[1].ReadOnly = true;
                            }
                        }
                        else
                        {
                            dataGrid.Rows.Add(Path.GetFileName(file));
                        }
                    }
                }
            }
            // Per scielta, decido di non gestire cartelle e sottocartelle del dispositivo,
            // in modo tale da semplificare un pò il progetto

            /*
             * foreach (var folder in Directory.GetDirectories(DevicePath))
             * {
             *  var attr = File.GetAttributes(folder);
             *  if (attr != (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Directory))
             *      dataGrid.Rows.Add(Path.GetFileName(folder), true);
             * }
             */
        }
Example #4
0
 /// <summary>
 /// Riempie la griglia
 /// Rileva i file presenti nel dispositivo e li riporta nella tabella
 /// </summary>
 void InitFiles()
 {
     foreach (var file in Directory.GetFiles(DevicePath))
     {
         var attr = File.GetAttributes(file);
         if (attr != ( FileAttributes.Hidden | FileAttributes.Archive ) && attr != FileAttributes.Hidden)
         {
             if(OwnerMode)
                 dataGrid.Rows.Add(Path.GetFileName(file));
             else
             {
                 // Nel caso non sono il proprietario del dispositivo, devo aggiungere solo i file a cui posso accedere
                 // e ovviamente i file privi di AGL
                 var aglService = new Services.FileAGLService(file);
                 string temp = string.Empty;
                 if (aglService.Exists())
                 {
                     if (aglService.Access(UserPassword, out temp))
                     {
                         int index = dataGrid.Rows.Add(Path.GetFileName(file), true);
                         dataGrid.Rows[index].Cells[1].ReadOnly = true;
                     }
                 }
                 else dataGrid.Rows.Add(Path.GetFileName(file));
             }
         }
     }
     // Per scielta, decido di non gestire cartelle e sottocartelle del dispositivo,
     // in modo tale da semplificare un pò il progetto
     /*
     foreach (var folder in Directory.GetDirectories(DevicePath))
     {
         var attr = File.GetAttributes(folder);
         if (attr != (FileAttributes.System | FileAttributes.Hidden | FileAttributes.Directory))
             dataGrid.Rows.Add(Path.GetFileName(folder), true);
     }
     */
 }
Example #5
0
        // Inizializza l'AGL dei file presenti sul dispositivo
        void InitAGL()
        {
            var groups = new Dictionary<string, string>();
            if (OwnerMode)
            {
                groups = Keys.Get(DeviceId);
            }

            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                var row = dataGrid.Rows[i];

                if (row.Cells[0].Value == null)
                    continue;
                string filename = DevicePath + row.Cells[0].Value.ToString();
                var agl = new Services.FileAGLService(filename);

                if(OwnerMode)
                {
                    if(agl.Exists())
                    {
                        foreach (var name in groups.Keys)
                        {
                            string temp = string.Empty;
                            int clIndex = GetColumnIndex(name);
                            if (clIndex != -1)
                            {
                                if (agl.Access(groups[name], out temp))
                                    row.Cells[clIndex].Value = true;
                            }
                        }
                    }
                }
                else
                {
                    // no wner mode
                }

            }
        }
Example #6
0
        /// <summary>
        /// Decripta tutti i file tenendo traccia sulla griglia del vecchio AGL per ognuno
        /// Tale operazione può essere effettuata solo al collegamento del dispositivo
        /// </summary>
        void DecryptAllFiles()
        {
            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                var row = dataGrid.Rows[i];
                if (row.Cells[0].Value == null)
                    continue;

                var filename = DevicePath + row.Cells[0].Value.ToString();

                var aglService = new Services.FileAGLService(filename);
                if (aglService.Exists() == false)
                    continue;
                var decryptoService = new Services.FileDecryptService(filename);

                string currentPassword = string.Empty;

                if(OwnerMode)
                {
                    // in tal caso mi basa una sola delle chiavi associate per accedere al file
                    var keys = GetKeysByRowIndex(i);
                    if (keys == null || keys.Count == 0)
                    {
                        dataGrid.Rows.RemoveAt(i);
                        continue;
                    }

                    currentPassword = keys[0];
                }
                else
                {
                    currentPassword = UserPassword;

                    // memorizza l'AGL del file
                    var restoreService = new Services.FileSSRestoreService(DeviceName, row.Cells[0].Value.ToString());
                    restoreService.Store(aglService.GetBytes());

                    RestoreData.Add(restoreService);
                }

                if(decryptoService.Decrypt(currentPassword, OwnerMode) && !OwnerMode)
                {
                    RestoreData[RestoreData.Count - 1].SetKey(decryptoService.Key);
                }
            }
        }