Exemple #1
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (e.Url.AbsoluteUri.StartsWith("https://oauth.vk.com/blank.html#"))
            {
                try
                {
                    var uri = e.Url.AbsoluteUri;
                    uri = uri.Replace("#", "?");
                    var args = Tools.GetParams(uri);
                    store.userID       = Int32.Parse(args["user_id"]);
                    store.accountToken = args["access_token"];

                    webBrowser1.Hide();
                    mainPanel.Show();
                    var username = VKTools.GetUsername(store.accountToken);
                    LogThis("User Profile Loaded");
                    welcomeLabel.Text = "Привет, " + username;

                    conversations = VKTools.GetAllConversations(store.accountToken);
                    LogThis("Total Conversations:" + conversations.Total);
                    SetStatus("У вас " + conversations.Total + " чатов. Укажите папку куда их скачать и нажмите Download.");

                    /*for (var a = 0; a < convos.Conversations.Count; a++)
                     * {
                     *  LogThis("   " + convos.Conversations[a].type + " (" + convos.Conversations[a].id + ") " + convos.Conversations[a].title);
                     * }*/
                } catch (Exception ex)
                {
                    LogThis(ex.Message);
                    LogThis(ex.StackTrace);
                }
            }
        }
        public string GenerateTextline()
        {
            string msg = "[" + Date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "]";

            msg += " " + VKTools.GetProfile("", FromID).name;
            var MsgText = Text.Replace("\n", "\t");

            msg += ": " + MsgText;
            if (Attachments.Count > 0)
            {
                msg += " [" + Attachments.Count + " attachments: ";
                for (var a = 0; a < Attachments.Count; a++)
                {
                    if (a > 0)
                    {
                        msg += ",";
                    }
                    msg += Attachments[a].Type;
                    if (!string.IsNullOrEmpty(Attachments[a].Filename))
                    {
                        msg += " '" + Attachments[a].Filename + "'";
                    }
                }
                msg += "]";
            }
            return(msg);
        }
Exemple #3
0
        public void Download(Conversation convo, string dirPath)
        {
            var convoName = "";

            if (convo.type == "user")
            {
                var profile = VKTools.GetProfile(token, convo.id);
                convoName = profile.name;
            }
            else if (!string.IsNullOrEmpty(convo.title))
            {
                convoName = convo.title;
            }
            if (string.IsNullOrEmpty(convoName))
            {
                convoName = "" + convo.id;
            }
            else
            {
                convoName += " - " + convo.id;
            }
            convoName = CleanFileName(convoName);
            var convoFilename = convoName + ".txt";

            form.LogThis("  Filename: " + convoFilename);

            var filePath  = Path.Combine(dir, convoFilename);
            int lineCount = 0;

            if (!File.Exists(filePath))
            {
                form.LogThis("Creating new file");
                File.Create(filePath).Close();
            }
            else
            {
                lineCount = Tools.GetLineCount(filePath);
                form.LogThis("File already has " + lineCount + " lines");
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
            {
                int lastMessageCount = 0;
                do
                {
                    var response = VKTools.GetMessages(token, convo.id, lineCount);
                    lastMessageCount = response.Messages.Count;
                    form.LogThis("   " + lineCount + " / " + response.Total + " messages");
                    List <Attachment> attachments = new List <Attachment>();
                    for (var m = 0; m < response.Messages.Count; m++)
                    {
                        attachments.AddRange(response.Messages[m].Attachments);
                        file.WriteLine(response.Messages[m].GenerateTextline());
                    }
                    if (form.IsDownloadAttachmentsChecked())
                    {
                        for (var a = 0; a < attachments.Count && !stop; a++)
                        {
                            DownloadAttachment(attachments[a], convoName);
                            while (downloadCounter > MAX_DOWNLOADS && !stop)
                            {
                                Task.Delay(100);
                            }
                        }
                    }

                    lineCount += response.Messages.Count;
                } while (lastMessageCount == 200 && !stop);
            }
        }