Exemple #1
0
        public async void LoadDataBase()
        {
            //加载数据库
            SqliteInfo info = vieModel_StartUp.CurrentDatabases[listBox.SelectedIndex];
            string     path = info.Path;
            int        id   = info.ID;

            Properties.Settings.Default.DataBasePath = path;
            if (!File.Exists(Properties.Settings.Default.DataBasePath))
            {
                return;
            }
            vieModel_StartUp.InitCompleted = false;
            if (Properties.Settings.Default.ScanGivenPath)
            {
                try
                {
                    await Task.Run(() =>
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            //statusText.Text = Jvedio.Language.Resources.Status_ScanDir;
                        }), System.Windows.Threading.DispatcherPriority.Background);
                        List <string> filepaths = Scan.ScanPaths(ReadScanPathFromConfig(Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath)), ct);
                        Scan.InsertWithNfo(filepaths, ct);
                    }, cts.Token);
                }
                catch (Exception ex)
                {
                    Logger.LogF(ex);
                }
            }


            //启动主窗口
            Main main = new Main();

            //statusText.Text = Jvedio.Language.Resources.Status_InitMovie;
            try
            {
                await main.InitMovie();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogE(ex);
            }
            main.Show();

            // 次数+1
            ConfigConnection.Instance.IncreaseField("ViewCount", id);

            this.Close();
        }
Exemple #2
0
        private void SetImage(object sender, RoutedEventArgs e)
        {
            SqliteInfo info = vieModel_StartUp.CurrentDatabases[listBox.SelectedIndex];

            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Title       = "选择图片";
            dialog.Filter      = "(jpg;jpeg;png)|*.jpg;*.jpeg;*.png";
            dialog.Multiselect = false;
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filename = dialog.FileName;
                SetImage(info.ID, filename);
            }
        }
Exemple #3
0
        public bool UpdateSqliteInfoPath(SqliteInfo sqliteInfo)
        {
            if (Sqlite.IsTableExist("databases"))
            {
                SQLiteCommand cmd = Sqlite.cmd;

                cmd.CommandText = $"UPDATE databases SET Path=@Path,Name=@Name where ID=@ID";

                cmd.Parameters.Add("ID", DbType.Int64).Value    = sqliteInfo.ID;
                cmd.Parameters.Add("Path", DbType.String).Value = sqliteInfo.Path;
                cmd.Parameters.Add("Name", DbType.String).Value = sqliteInfo.Name;
                int result = cmd.ExecuteNonQuery();
                return(result > 0);
            }
            return(false);
        }
Exemple #4
0
 public void LoadDatabase(string[] files)
 {
     if (files != null && files.Length > 0)
     {
         foreach (var item in files)
         {
             SqliteInfo sqliteInfo = ParseInfo(item);
             if (sqliteInfo != null && !Databases.Contains(sqliteInfo))
             {
                 Databases.Add(sqliteInfo);
             }
         }
     }
     JoinInfo();
     Search();
 }
Exemple #5
0
        public SqliteInfo ParseInfo(string path)
        {
            string name = Path.GetFileNameWithoutExtension(path);

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            System.IO.FileInfo fileInfo   = new System.IO.FileInfo(path);
            SqliteInfo         sqliteInfo = new SqliteInfo();

            sqliteInfo.Name       = name;
            sqliteInfo.Path       = path;
            sqliteInfo.Size       = fileInfo.Length;
            sqliteInfo.CreateDate = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss");
            return(sqliteInfo);
        }
Exemple #6
0
        public List <SqliteInfo> SelectSqliteInfo()
        {
            InfoType          type   = GlobalVariable.CurrentInfoType;
            List <SqliteInfo> result = new List <SqliteInfo>();

            if (!Sqlite.IsTableExist("databases"))
            {
                return(result);
            }
            Sqlite.cmd.CommandText = $"select * from databases where type='{type.ToString()}'";
            using (SQLiteDataReader sr = Sqlite.cmd.ExecuteReader())
            {
                while (sr.Read())
                {
                    if (sr == null || sr["ID"] == null)
                    {
                        continue;
                    }
                    double.TryParse(sr["Size"].ToString(), out double Size);
                    int.TryParse(sr["ID"].ToString(), out int ID);
                    int.TryParse(sr["Count"].ToString(), out int Count);
                    int.TryParse(sr["ViewCount"].ToString(), out int ViewCount);

                    SqliteInfo info = new SqliteInfo()
                    {
                        ID         = ID,
                        Path       = sr["Path"].ToString(),
                        Name       = sr["Name"].ToString(),
                        ImagePath  = sr["ImagePath"].ToString(),
                        CreateDate = sr["CreateDate"].ToString(),
                        Type       = type,
                        Size       = Size,
                        Count      = Count,
                        ViewCount  = ViewCount
                    };
                    result.Add(info);
                }
            }
            return(result);
        }
Exemple #7
0
        public bool UpdateSqliteInfo(SqliteInfo sqliteInfo)
        {
            if (Sqlite.IsTableExist("databases"))
            {
                SQLiteCommand cmd = Sqlite.cmd;

                cmd.CommandText = $"UPDATE databases SET Path=@Path,Name=@Name," +
                                  $"Size=@Size,Count=@Count,Type=@Type," +
                                  $"ViewCount=@ViewCount where ID=@ID";

                cmd.Parameters.Add("ID", DbType.Int64).Value        = sqliteInfo.ID;
                cmd.Parameters.Add("Path", DbType.String).Value     = sqliteInfo.Path;
                cmd.Parameters.Add("Name", DbType.String).Value     = sqliteInfo.Name;
                cmd.Parameters.Add("Size", DbType.Double).Value     = sqliteInfo.Size;
                cmd.Parameters.Add("Count", DbType.Int64).Value     = sqliteInfo.Count;
                cmd.Parameters.Add("Type", DbType.String).Value     = sqliteInfo.Type;
                cmd.Parameters.Add("ViewCount", DbType.Int64).Value = sqliteInfo.ViewCount;

                int result = cmd.ExecuteNonQuery();
                return(result > 0);
            }
            return(false);
        }
Exemple #8
0
        public bool InsertSqliteInfo(SqliteInfo sqliteInfo)
        {
            if (Sqlite.IsTableExist("databases"))
            {
                SQLiteCommand cmd = Sqlite.cmd;

                cmd.CommandText = $"insert into databases (Count,Path,Name,Size,Type,ImagePath,ViewCount,CreateDate) " +
                                  $"values (@Count,@Path,@Name,@Size,@Type,@ImagePath,@ViewCount,@CreateDate)";

                cmd.Parameters.Add("Path", DbType.String).Value       = sqliteInfo.Path;
                cmd.Parameters.Add("Name", DbType.String).Value       = sqliteInfo.Name;
                cmd.Parameters.Add("Size", DbType.Double).Value       = sqliteInfo.Size;
                cmd.Parameters.Add("Count", DbType.Int64).Value       = sqliteInfo.Count;
                cmd.Parameters.Add("Type", DbType.String).Value       = sqliteInfo.Type;
                cmd.Parameters.Add("ImagePath", DbType.String).Value  = sqliteInfo.ImagePath;
                cmd.Parameters.Add("ViewCount", DbType.Int64).Value   = sqliteInfo.ViewCount;
                cmd.Parameters.Add("CreateDate", DbType.String).Value = sqliteInfo.CreateDate;

                int result = cmd.ExecuteNonQuery();
                return(result > 0);
            }
            return(false);
        }
Exemple #9
0
        // 存储到数据库中
        private void JoinInfo()
        {
            // 1. 新增 / 更新
            // 2. 删除
            List <SqliteInfo> sqliteInfos = ConfigConnection.Instance.SelectSqliteInfo();

            foreach (var item in Databases)
            {
                if (sqliteInfos.Contains(item))
                {
                    SqliteInfo data = sqliteInfos[sqliteInfos.IndexOf(item)];
                    //更新
                    item.ID        = data.ID;
                    item.Count     = data.Count;
                    item.ViewCount = data.ViewCount;
                    item.ViewCount = data.ViewCount;
                    string imagePath = Path.Combine(GlobalVariable.ProjectImagePath, data.ImagePath);
                    if (File.Exists(imagePath))
                    {
                        item.ImagePath = imagePath;
                    }

                    data.Size = item.Size;
                    ConfigConnection.Instance.UpdateSqliteInfo(data);
                }
                else
                {
                    // 新增
                    ConfigConnection.Instance.InsertSqliteInfo(item);
                }
            }

            // 删除
            List <SqliteInfo> toDelete = sqliteInfos.Except(Databases).ToList();

            ConfigConnection.Instance.DeleteByIds(toDelete.Select(item => item.ID).ToList());
        }
        public static void readSqliteInfo(string fileName)
        {
            tableName   = new List <string>();
            tableSchema = new List <string>();
            sqliteinfo  = new List <SqliteInfo>();

            StreamReader reader = new StreamReader(new FileStream(fileName, FileMode.Open));
            string       schema_CREATE_TABLE = "CREATE TABLE ";
            string       temp_read_line      = "";

            SqliteInfo    sql_unit = new SqliteInfo();
            List <string> row      = new List <string>();

            bool fuckingstart = false;

            while (reader.EndOfStream == false)
            {
                temp_read_line = reader.ReadLine();
                Match match = Regex.Match(temp_read_line, schema_CREATE_TABLE);

                int startoffset = 0;
                if (match.Success)
                {
                    if (fuckingstart == false)
                    {
                        fuckingstart = true;
                    }
                    else
                    {
                        sqliteinfo.Add(sql_unit);
                        sql_unit = new SqliteInfo();
                    }

                    tableSchema.Add(temp_read_line);

                    int    tableEnd  = temp_read_line.IndexOf('(');
                    string tablename = temp_read_line.Substring(13, tableEnd - 13);
                    sql_unit.tablename = tablename.Trim();
                    tableName.Add(tablename);

                    int  attributeCnt   = 0;
                    int  distributorCnt = 0;
                    bool startflag      = true;

                    for (int i = 0; i < temp_read_line.Length; i++)
                    {
                        if (temp_read_line[i] == '(')
                        {
                            distributorCnt++;
                            if (startflag)
                            {
                                startoffset = i;
                                startflag   = false;
                            }
                        }
                        else if (temp_read_line[i] == ')')
                        {
                            distributorCnt--;
                        }

                        if ((temp_read_line[i] == ',' || temp_read_line[i] == '(') && distributorCnt == 1)
                        {
                            attributeCnt++;

                            string temp = "";
                            int    idx  = i + 1;


                            while (idx < temp_read_line.Length)
                            {
                                if (temp_read_line[idx] != ' ' && temp_read_line[idx] != ')')
                                {
                                    temp += temp_read_line[idx];
                                }
                                else if (temp_read_line[idx] == ' ' && temp == "")
                                {
                                }
                                else
                                {
                                    break;
                                }

                                idx++;
                            }

                            Match m = Regex.Match(temp.Trim(), "unique");
                            if (!m.Success)
                            {
                                sql_unit.attributes.Add(temp.Trim());
                            }
                            else
                            {
                                attributeCnt--;
                            }
                        }
                    }
                    attributeCnt++;
                    if (attributeCnt == 1)
                    {
                        string temp = "";
                        int    idx  = startoffset + 1;

                        while (true)
                        {
                            if (temp_read_line[idx] != ' ')
                            {
                                temp += temp_read_line[idx];
                            }
                            else if (temp_read_line[idx] == ' ' && temp == "")
                            {
                            }
                            else
                            {
                                break;
                            }

                            idx++;
                        }

                        sql_unit.attributes.Add(temp.Trim());
                    }
                }
                else if (temp_read_line == "*****")
                {
                    if (row.Count < sql_unit.attributes.Count)
                    {
                        int rowCnt = row.Count;
                        for (int i = 0; i < sql_unit.attributes.Count - rowCnt; i++)
                        {
                            row.Add("Default");
                        }
                    }

                    sql_unit.rows.Add(row);
                    row = new List <string>();
                }
                else if (temp_read_line == "$$$")
                {
                    string hexValues = reader.ReadLine();
                    row.Add(hexValues);
                }
                else if (temp_read_line == "^^^")
                {
                    string hexValues = reader.ReadLine();
                    int    byteCnt   = hexValues.Trim().Length / 2;

                    if (hexValues.Length > 0)
                    {
                        hexValues = hexValues.TrimEnd();
                    }

                    byte[]   ba             = new byte[byteCnt];
                    string[] hexValuesSplit = hexValues.Split(' ');
                    int      i         = 0;
                    bool     null_flag = false;
                    foreach (String hex in hexValuesSplit)
                    {
                        if (i < byteCnt)
                        {
                            if (hex != "NULL")
                            {
                                ba[i++] = Convert.ToByte(hex, 16);
                            }
                            else
                            {
                                null_flag = true;
                                break;
                            }
                        }
                    }
                    string str = System.Text.Encoding.UTF8.GetString(ba);
                    if (!null_flag)
                    {
                        row.Add(str.TrimEnd().TrimStart());
                    }
                    else
                    {
                        row.Add("NULL");
                    }
                }
                else
                {
                    if (temp_read_line == "")
                    {
                        break;
                    }
                    row.Add(temp_read_line);
                }

                if (temp_read_line == "L*A*S*T")
                {
                    sqliteinfo.Add(sql_unit);
                    break;
                }
            }
            reader.Close();
        }