PDAclub.pl - Forum użytkowników technologii mobilnych

Windows Mobile (Classic, Professional, Standard), Windows Phone 6.x oraz 7/8.x/10 => Oprogramowanie PPC => Dla programistów => Wątek zaczęty przez: makler2006 w Luty 16, 2006, 10:21:38

Tytuł: problem z atrybutami folderu Settings i Programs w PPC??
Wiadomość wysłana przez: makler2006 w Luty 16, 2006, 10:21:38
Witam!
Mam mały problem. Potrzebuję zmienić nazwę katalogów Settings i Programs znajdujących się w Menu Start PocketPC. Oba te foldery nie pozwalają na zmianę nazwy, bo pisze że są Read Only. Zatem przy funkcji rename dodałem zdjęcie flagi ReadOnly i ustawienie tego, na dodatek robię dodatkowo ustawienie flagi normal i dalej nic, co robię źle?? Oto kod w C# do Compact Framework:
using using System.IO;

public static FileAttributes GetAttributes(string path)
      {
         if(path.Length > 260)
         {
            throw new PathTooLongException();
         }

         if(path.Trim().Length == 0)
         {
            throw new ArgumentException();
         }

         uint attr = GetFileAttributes(path);

         if(attr ==  0xFFFFFFFF)
         {
            int e = Marshal.GetLastWin32Error();
            if((e == 2) || (e == 3))
            {
               throw new FileNotFoundException();
            }
            else
            {
               throw new Exception("Unmanaged Error: " + e);
            }
         }
         return (FileAttributes)attr;
      }

      public static void SetAttributes(string path, FileAttributes fileAttributes)
      {
         if(path.Length > 260)
         {
            throw new PathTooLongException();
         }

         if(path.Trim().Length == 0)
         {
            throw new ArgumentException();
         }

         if(! SetFileAttributes(path, (uint)fileAttributes))
         {
            int e = Marshal.GetLastWin32Error();
            if((e == 2) || (e == 3))
            {
               throw new FileNotFoundException();
            }
            else
            {
               throw new Exception("Unmanaged Error: " + e);
            }
         }
      }

private void renameFolderName(string srcPatch, string dstPatch)
      {
         DirectoryInfo fl = new DirectoryInfo(srcPatch);
         //uint attr = GetFileAttributes(srcPatch);
         //attr -= (uint)FileAttributes.ReadOnly;
         if(fl.Exists==true)
         {
            try
            {

               // remove readonly attribute
               if ((fl.Attributes & System.IO.FileAttributes.ReadOnly) != 0)
                  fl.Attributes -= System.IO.FileAttributes.ReadOnly;
               if ((fl.Attributes & System.IO.FileAttributes.Archive) != 0)
                  fl.Attributes -= System.IO.FileAttributes.Archive;
               if ((fl.Attributes & System.IO.FileAttributes.System) != 0)
                  fl.Attributes -= System.IO.FileAttributes.System;
               if ((fl.Attributes & System.IO.FileAttributes.Hidden) != 0)
                  fl.Attributes -= System.IO.FileAttributes.Hidden;

            //   fl.Attributes = System.IO.FileAttributes.Normal;
               SetAttributes(srcPatch, fl.Attributes);

               SetAttributes(srcPatch, System.IO.FileAttributes.Normal);
            
               fl.MoveTo(dstPatch);
            }
            catch(Exception e)
            {
               MessageBox.Show("Nie można zmienić nazwy pliku: "+srcPatch,e.ToString());
            }
         }
         else
         {
         //   MessageBox.Show("Plik o ścieżce "+srcPatch+" nie istnieje!");
         }
      }
Tytuł: problem z atrybutami folderu Settings i Programs w PPC??
Wiadomość wysłana przez: fp w Luty 17, 2006, 06:42:06
swoją drogą,... czemu chcesz zmienić nazwy tych katalogów??