Example #1
0
        public override NtStatus CreateDirectory(Folder file, string filename, DokanFileInfo info)
        {
            // https://vk.com/id1
            // https://vk.com/durov
            // https://vkontakte.ru/id1

            filename = System.Text.RegularExpressions.Regex.Replace(filename, @"http(s|)://.*/", "");
            // хавает любое занчение: 47348352, club47348352, vkdriveapp

            if (filename.Length == 0)
            {
                return(DokanResult.Error);
            }
            JObject apiResult;

            try
            {
                apiResult =
                    (JObject)
                    VKAPI.Vkapi.Instance.StartTaskSync(new VKAPI.ApiQuery("users.get",
                                                                          new Dictionary <string, string>()
                {
                    { "uids", filename }
                }));
            }
            catch (Exception e)
            {
                if (e.Data.Contains("code") && e.Data["code"].ToString() == "113")
                {
                    Console.WriteLine(@"Invalid user id");
                }
                return(DokanResult.Error);
            }

            ushort count = 0;
            JArray items = (JArray)apiResult.GetValue("items");

            foreach (JObject item in items)
            {
                SerializationObject.User user = item.ToObject <SerializationObject.User>();

                /*
                 * bool isDooble = false;
                 * foreach (VFile file in RootNode.Childs)
                 * {
                 *  if (file.GetType() == typeof(Folder))
                 *  {
                 *      // проверка вхождения ключа нужна при разделении на каталоги. В этом случае сложим группу в корень после перезагрузки все исправится
                 *      if (((Folder)file).Property.ContainsKey("gid") && ((Folder)file).Property["gid"] == gid)
                 *      {
                 *          isDooble = true;
                 *          break;
                 *      }
                 *  }
                 * }
                 * if (isDooble)
                 * {
                 *  count++;
                 *  continue;
                 * }*/

                if (user.FirstName == "DELETED" || user.Deactivated != null)
                {
                    continue;
                }

                VkStorage.Join(StorageKey, user.Id.ToString());

                file.ChildsAdd(CreateUserFolder(user));

                count++;
            }

            if (count > 0)
            {
                return(DokanResult.Success);
            }
            return(DokanResult.Error);
        }
Example #2
0
        public override bool _LoadFile(Folder file)
        {
            _log.Debug("_LoadFile " + file);
            if (file.Property["type"] == "friends.getLists")
            {
                JObject apiResult = (JObject)Vkapi.Instance.StartTaskSync(new ApiQuery("friends.getLists"));
                JArray  items     = (JArray)apiResult.GetValue("items");

                Folder curFolder = new Folder("Все");
                curFolder.Property.Add("type", "friends.get");
                curFolder.Property.Add("lid", "0");
                file.ChildsAdd(curFolder);

                foreach (JObject item in items)
                {
                    curFolder = new Folder(item.GetValue("name").ToString()); // посмотреть типы данных
                    curFolder.Property.Add("type", "friends.get");
                    curFolder.Property.Add("lid", item.GetValue("id").ToString());
                    file.ChildsAdd(curFolder);
                }


                curFolder = new Folder("Мои подписки");
                curFolder.Property.Add("type", "subscriptions.get");
                file.ChildsAdd(curFolder);
                curFolder = new Folder("Другие");
                curFolder.Property.Add("type", "storage.get");
                file.ChildsAdd(curFolder);
            }
            else if (file.Property["type"] == "friends.get")
            {
                int key = Convert.ToInt32(file.Property["lid"]);

                Dictionary <string, string> param = new Dictionary <string, string>()
                {
                    { "fields", "first_name,last_name,domain" }
                };

                if (key > 0)
                {
                    param.Add("list_id", key.ToString());
                }

                JObject apiResult = (JObject)Vkapi.Instance.StartTaskSync(new ApiQuery("friends.get", param));
                JArray  items     = (JArray)apiResult.GetValue("items");

                foreach (JObject item in items)
                {
                    file.ChildsAdd(CreateUserFolder(item.ToObject <SerializationObject.User>()));
                }
            }
            else if (file.Property["type"] == "subscriptions.get")
            {
                /*
                 * JObject apiResult = (JObject)VKAPI.VKAPI.Instance.StartTaskSync(new VKAPI.APIQuery("users.getSubscriptions"));
                 *
                 * XElement responce = XElement.Parse(xml);
                 * IEnumerable<XElement> uids = responce.Element("users").Elements("uid");
                 * List<string> uidsList = new List<string>();
                 *
                 * foreach (XElement uid in uids)
                 * {
                 *  uidsList.Add(uid.Value);
                 * }
                 * if (uidsList.Count == 0)
                 * {
                 *  return true;
                 * }
                 * if (uidsList.Count >= 1000)
                 * {
                 *  // todo readme
                 *  return true;
                 * }
                 *
                 * xml = VKAPI.VKAPI.Instance.StartTaskSync(new VKAPI.APIQuery("users.get", new Dictionary<string, string>() { { "uids", String.Join(",", uidsList) } }));
                 *
                 * responce = XElement.Parse(xml);
                 * IEnumerable<XElement> users = responce.Elements("user");
                 * foreach (XElement user in users)
                 * {
                 *  file.ChildsAdd(CreateUserFolder(user));
                 * }*/
            }
            else if (file.Property["type"] == "storage.get")
            {
                string storageUids = VkStorage.Get(StorageKey);

                file.ChildsAdd(new Settings("Добавить людей.lnk"));
                file.ChildsAdd(
                    new Files.SettingsXls(
                        "VKDirvePathData.xml", "Добавление людей",
                        "Введите ссылку на человека или номер его страницы. Например https://vk.com/durov",
                        "Никого не удалось найти.",
                        "Такой человек уже есть в этом списке."
                        ));

                if (storageUids.Length > 0)
                {
                    JArray items =
                        (JArray)
                        Vkapi.Instance.StartTaskSync(new VKAPI.ApiQuery("users.get",
                                                                        new Dictionary <string, string> {
                        { "user_ids", storageUids.Replace('\n', ',') }
                    }));
                    foreach (JObject item in items)
                    {
                        file.ChildsAdd(CreateUserFolder(item.ToObject <SerializationObject.User>()));
                    }
                }
            }
            else if (file.Property["type"] == "AudioApi.ExecuteGetAlbums")
            {
                System.Collections.ArrayList files = new System.Collections.ArrayList();

                AudioApi.ExecuteGetAlbums(new Dictionary <string, string>()
                {
                    { "owner_id", file.Property["uid"] }
                }, file.Childs);
            }
            else if (file.Property["type"] == "audio.getInAlbum")
            {
                AudioApi.LoadMp3(new Dictionary <string, string>()
                {
                    { "owner_id", file.Property["uid"] },
                    { "album_id", file.Property["album_id"] }
                }, file.Childs);
            }
            else if (file.Property["type"] == "wait")
            {
                // Он там грузится в паралельном потоке. Подождать нужно
                while (!file.IsLoaded)
                {
                    // todo сделать перехват фатала.
                    System.Threading.Thread.Sleep(100);
                }
            }
            return(true);
        }
Example #3
0
        public override bool _LoadFile(Files.Folder file)
        {
            if (file.Property["type"] == "groups.get")
            {
                file.ChildsAdd(new Files.Settings("Добавить группу.lnk"));
                file.ChildsAdd(
                    new Files.SettingsXls(
                        "VKDirvePathData.xml", "Добавление группы",
                        "Введите ссылку на группу или ее идентификатор. Например https://vk.com/club47348352",
                        "Не удалось найти такую группу.",
                        "Такая группа уже существует."
                        ));

                JObject apiResult =
                    (JObject)
                    Vkapi.Instance.StartTaskSync(new ApiQuery("groups.get",
                                                              new Dictionary <string, string> {
                    { "extended", "1" }
                }));
                JArray items = (JArray)apiResult.GetValue("items");

                List <int> gruopIds = new List <int>();

                foreach (JObject item in items)
                {
                    SerializationObject.Group group = item.ToObject <SerializationObject.Group>();
                    file.ChildsAdd(CreateGroupFolder(group));
                    gruopIds.Add(group.Id);
                }

                string gids = VkStorage.Get(StorageKey);
                if (gids.Length > 0)
                {
                    JArray values =
                        (JArray)
                        Vkapi.Instance.StartTaskSync(new ApiQuery("groups.getById",
                                                                  new Dictionary <string, string> {
                        { "group_ids", gids.Replace('\n', ',') }
                    }));

                    foreach (JObject item in items)
                    {
                        SerializationObject.Group group = item.ToObject <SerializationObject.Group>();
                        if (gruopIds.IndexOf(group.Id) > -1)
                        {
                            continue;
                        }
                        file.ChildsAdd(CreateGroupFolder(group));
                    }
                }
            }
            else if (file.Property["type"] == "AudioApi.ExecuteGetAlbums")
            {
                //// 15:Access denied: group audio is disabled
                try
                {
                    AudioApi.ExecuteGetAlbums(new Dictionary <string, string>()
                    {
                        { "owner_id", "-" + file.Property["gid"] }
                    }, file.Childs);
                }
                catch (Exception e)
                {
                    if (e.Data.Contains("code") && e.Data["code"].ToString() == "15")
                    {
                        // 15:Access denied: group photos are disabled

                        var readmePlainText = new PlainText("Аудиозаписи отключены.txt");
                        readmePlainText.SetText(PlainText.GetSubscript());
                        file.ChildsAdd(readmePlainText);
                        return(true);
                    }
                    return(false);
                }
            }
            else if (file.Property["type"] == "audio.getInAlbum")
            {
                AudioApi.LoadMp3(new Dictionary <string, string>()
                {
                    { "gid", file.Property["gid"] },
                    { "album_id", file.Property["album_id"] }
                }, file.Childs);
            }
            else if (file.Property["type"] == "wait")
            {
                // Он там грузится в паралельном потоке. Подождать нужно
                int i = 0;
                while (!file.IsLoaded && i < 20) // 2 сек максимум
                {
                    i++;
                    // todo сделать перехват фатала.
                    System.Threading.Thread.Sleep(100);
                }
                // Подождать не вышло, выводим что есть
            }

            return(true);
        }