Beispiel #1
0
        public bool Save_supplier_configs(UInt32 numcon, String filename)
        {
            FileStream     _fs = null;
            Container_file f;
            TableFile      tf;

            if (numcon >= Supplier_configs.Capacity)
            {
                return(false);
            }

            tf = Supplier_configs[(int)numcon].File;

            f = new Container_file(tf, tf.Name);
            if (!f.open())
            {
                //f = null;
                return(false);
            }

            try
            {
                _fs = new FileStream(filename, FileMode.OpenOrCreate);
            }
            catch
            {
                return(false);
            }

            MemoryTributary out_fs = new MemoryTributary();

            try
            {
                Inflate((MemoryTributary)f.Stream, out out_fs);
                out_fs.CopyTo(_fs);
            }
            catch
            {
                /*
                 * msreg_m.AddError("Ошибка распаковки файла конфигурации поставщика",
                 *  "Имя файла", _filename);
                 */

                _fs.Dispose();;
                return(false);
            }

            _fs.Dispose();

            return(true);
        }
Beispiel #2
0
        public ConfigStorageTableConfigSave(TableFiles tabc, TableFiles tabcs, Tools1CD _base = null)
        {
            int            m;
            string         s;
            string         name, ext;
            TableFile      tf;
            TableFile      _DynamicallyUpdated;
            TableFile      _deleted;
            Container_file pcf;
            Container_file DynamicallyUpdated;
            Container_file deleted;
            Tree           tt;
            Tree           ct;

            Guid[]           dynup;
            int              ndynup = 0;
            Guid             g      = EmptyUID;
            V8Table          tab;
            int              dynno;
            HashSet <string> del = null;

            ready = tabc.getready();
            if (!ready)
            {
                return;
            }
            ready = tabcs.getready();
            if (!ready)
            {
                return;
            }

            present = tabc.gettable().Getbase().Getfilename() + "\\CONFIGSAVE";

            tab      = tabcs.gettable();
            _deleted = tabcs.getfile("deleted");

            if (_deleted != null)
            {
                deleted = new Container_file(_deleted, _deleted.Name);
                deleted.open();
                s  = tab.Getbase().Getfilename() + "\\" + tab.Getname() + "\\" + deleted.Name;
                tt = Tree.Parse_1Cstream(deleted.stream, "", s);
                if (tt is null)
                {
                    // error(L"Ошибка разбора файла deleted"
                    //     , L"Путь", s);
                }
                else
                {
                    ct = tt.Get_First();
                    if (ct is null)
                    {
                        // error(L"Ошибка разбора файла DynamicallyUpdated"
                        //     , L"Путь", s);
                    }
                    else
                    {
                        for (m = Convert.ToInt32(ct.Get_Value()); m != 0; --m)
                        {
                            ct = ct.Get_Next();
                            if (ct is null)
                            {
                                // error(L"Ошибка разбора файла DynamicallyUpdated"
                                //     , L"Путь", s);
                                break;
                            }
                            del.Add(ct.Get_Value().ToUpper());
                            ct = ct.Get_Next();
                            if (ct is null)
                            {
                                // error(L"Ошибка разбора файла DynamicallyUpdated"
                                //     , L"Путь", s);
                                break;
                            }
                        }
                    }
                }
            }

            tab = tabc.gettable();
            _DynamicallyUpdated = tabc.getfile("DynamicallyUpdated");
            dynup = null;
            if (_DynamicallyUpdated != null)
            {
                DynamicallyUpdated = new Container_file(_DynamicallyUpdated, _DynamicallyUpdated.Name);
                DynamicallyUpdated.open();
                s  = tab.Getbase().Getfilename() + "\\" + tab.Getname() + "\\" + DynamicallyUpdated.Name;
                tt = Tree.Parse_1Cstream(DynamicallyUpdated.stream, "", s);
                if (tt is null)
                {
                    // error(L"Ошибка разбора файла DynamicallyUpdated"
                    //     , L"Путь", s);
                }
                else
                {
                    ct = tt.Get_First();
                    if (ct is null)
                    {
                        // error(L"Ошибка разбора файла DynamicallyUpdated"
                        //     , L"Путь", s);
                    }
                    else
                    {
                        ct = tt.Get_First();
                        if (ct is null)
                        {
                            // error(L"Ошибка разбора файла DynamicallyUpdated"
                            //     , L"Путь", s);
                        }
                        else
                        {
                            ct = ct.Get_Next();
                            if (ct is null)
                            {
                                // error(L"Ошибка разбора файла DynamicallyUpdated"
                                //     , L"Путь", s);
                            }
                            else
                            {
                                if (ct.Get_Type() != Node_Type.nd_number)
                                {
                                    // error(L"Ошибка разбора файла DynamicallyUpdated"
                                    //     , L"Путь", s);
                                }
                                else
                                {
                                    ndynup = Convert.ToInt32(ct.Get_Value());
                                    if (ndynup > 0)
                                    {
                                        dynup = new Guid[ndynup];
                                        for (m = 0; m < ndynup; ++m)
                                        {
                                            ct = ct.Get_Next();
                                            string_to_GUID(ct.Get_Value(), ref dynup[m]);
                                        }
                                    }
                                    else
                                    {
                                        ndynup = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            m = ndynup + 2;

            int index = 0;

            foreach (var item_files in tabcs.files)
            {
                tf = item_files.Value;
                if (tf == _deleted)
                {
                    continue;
                }
                if (tf.addr[index].Blob_length == 0)
                {
                    continue;
                }

                name = tf.Name;
                s    = name.ToUpper();

                if (files.TryGetValue(s, out Container_file val))
                {
                    // error(L"Ошибка чтения CONFIGSAVE. Повторяющееся имя файла"
                    // , L"Имя файла", s);
                }
                else
                {
                    pcf       = new Container_file(tf, name);
                    files[s]  = pcf;
                    pcf.Dynno = m;
                }
                ++index;
            }

            index = 0;
            foreach (var item_files in tabc.files)
            {
                tf = item_files.Value;
                if (tf == _DynamicallyUpdated)
                {
                    continue;
                }
                if (tf.addr[index].Blob_length == 0)
                {
                    continue;
                }
                s = tf.Name;

                if (del.Contains(s.ToUpper()))
                {
                    continue;
                }

                m = s.LastIndexOfAny(".".ToCharArray());
                if (m != -1)
                {
                    name = s.Substring(1, m - 1);
                    ext  = s.Substring(m + 1, s.Length - m);
                }
                else
                {
                    name = s;
                    ext  = "";
                }
                if (ext.CompareTo("new") == 0)
                {
                    ext   = "";
                    dynno = ndynup + 1;
                }
                else
                {
                    dynno = -1;
                }
                m = name.IndexOf("_dynupdate_");
                if (m != -1)
                {
                    s    = name.Substring(m + "_dynupdate_".Length, name.Length - m - "_dynupdate_".Length + 1);
                    name = name.Substring(1, m - 1);
                    string_to_GUID(s, ref g);
                    if (dynup != null)
                    {
                        for (m = 0; m < ndynup; ++m)
                        {
                            if (g == dynup[m])
                            {
                                break;
                            }
                        }

                        dynno = (m >= ndynup) ? -2 : m;
                    }
                    else
                    {
                        dynno = -2;
                    }
                }

                if (!string.IsNullOrEmpty(ext))
                {
                    name = name + "." + ext;
                }
                s = name.ToUpper();
                if (files.TryGetValue(s, out Container_file val))
                {
                    pcf = val;
                    if (pcf.Dynno < dynno)
                    {
                        pcf.File  = tf;
                        pcf.Dynno = dynno;
                    }
                }
                else
                {
                    pcf       = new Container_file(tf, name);
                    files[s]  = pcf;
                    pcf.Dynno = dynno;
                }
                ++index;
            }
        }
Beispiel #3
0
        public ConfigStorageTableConfig(TableFiles tabf, Tools1CD _base = null)
        {
            int    m;
            string s;
            string name, ext;
            string spoint      = ".";
            string sdynupdate  = "_dynupdate_";
            int    lsdynupdate = sdynupdate.Length;

            TableFile tf;
            //std::map<String, table_file*>::iterator pfilesmap;
            //std::map<String, container_file*>::iterator pfiles;
            TableFile      _DynamicallyUpdated;
            Container_file DynamicallyUpdated;
            Tree           tt;
            Tree           ct;

            Guid[]         dynup;
            int            ndynup = 0;
            Guid           g      = EmptyUID;
            V8Table        tab;
            int            dynno;
            Container_file pcf;

            ready = tabf.getready();
            if (!ready)
            {
                return;
            }
            present = tabf.gettable().Getbase().Getfilename() + "\\CONFIG";
            tab     = tabf.gettable();

            _DynamicallyUpdated = tabf.getfile("DynamicallyUpdated");
            dynup = null;

            if (_DynamicallyUpdated != null)
            {
                DynamicallyUpdated = new Container_file(_DynamicallyUpdated, _DynamicallyUpdated.Name);
                DynamicallyUpdated.open();
                s = tab.Getbase().Getfilename() + "\\" + tab.Getname() + "\\" + DynamicallyUpdated.Name;
                //tt = parse_1Cstream()
                tt = Tree.Parse_1Cstream(DynamicallyUpdated.Stream, "", s);
                if (tt is null)
                {
                    // error(L"Ошибка разбора файла DynamicallyUpdated"
                    //     , L"Путь", s);
                }
                else
                {
                    ct = tt.Get_First();
                    if (ct is null)
                    {
                        // error(L"Ошибка разбора файла DynamicallyUpdated"
                        //     , L"Путь", s);
                    }
                    else
                    {
                        ct = tt.Get_First();
                        if (ct is null)
                        {
                            // error(L"Ошибка разбора файла DynamicallyUpdated"
                            //     , L"Путь", s);
                        }
                        else
                        {
                            ndynup = Convert.ToInt32(ct.Get_Value());
                            if (ndynup > 0)
                            {
                                dynup = new Guid[ndynup];
                                for (m = 0; m < ndynup; ++m)
                                {
                                    ct = ct.Get_Next();
                                    string_to_GUID(ct.Get_Value(), ref dynup[m]);
                                }
                            }
                            else
                            {
                                ndynup = 0;
                            }
                        }
                    }
                }
            }

            int index = 0;

            foreach (var item_files in tabf.files)
            {
                tf = item_files.Value;
                if (tf == _DynamicallyUpdated)
                {
                    continue;
                }
                if (tf.addr[index].Blob_length == 0)
                {
                    continue;
                }
                s = tf.Name;

                m = s.LastIndexOfAny(spoint.ToCharArray());

                if (m != -1)
                {
                    name = s.Substring(1, m - 1);
                    ext  = s.Substring(m + 1, s.Length - m);
                }
                else
                {
                    name = s;
                    ext  = "";
                }

                if (ext.CompareTo("new") == 0)
                {
                    ext   = "";
                    dynno = -2;
                }
                else
                {
                    dynno = -1;
                }


                m = name.IndexOf(sdynupdate);
                if (m != -1)
                {
                    s    = name.Substring(m + lsdynupdate, name.Length - m - lsdynupdate + 1);
                    name = name.Substring(1, m - 1);
                    string_to_GUID(s, ref g);
                    if (dynup != null)
                    {
                        for (m = 0; m < ndynup; ++m)
                        {
                            if (g == dynup[m])
                            {
                                break;
                            }
                            if (m >= ndynup)
                            {
                                dynno = -2;
                            }
                            else
                            {
                                dynno = m;
                            }
                        }
                    }
                    else
                    {
                        dynno = -2;
                    }
                }
                if (string.IsNullOrEmpty(ext))
                {
                    name = name + spoint + ext;
                }
                s = name.ToUpper();

                if (files.TryGetValue(s, out Container_file val))
                {
                    pcf = val;
                    if (pcf.Dynno < dynno)
                    {
                        pcf.File  = tf;
                        pcf.Dynno = dynno;
                    }
                }
                else
                {
                    pcf       = new Container_file(tf, name);
                    files[s]  = pcf;
                    pcf.Dynno = dynno;
                }
                ++index;
            }
        }
Beispiel #4
0
        public override ConfigFile readfile(String path)
        {
            Container_file           tf = null;
            V8Catalog                c;
            V8File                   f;
            int                      i;
            string                   fname;
            string                   r_name;
            ConfigFile               cf;
            ConfigStorageTable_addin cfa;

            if (!ready)
            {
                return(null);
            }

            fname = new StringBuilder(path).Replace('/', '\\').ToString();
            i     = fname.IndexOf("\\");
            if (i != -1)
            {
                r_name = fname.Substring(1, i - 1);
                fname  = fname.Substring(i + 1, fname.Length - i);
            }
            else
            {
                r_name = fname;
                fname  = "";
            }

            tf = (files.TryGetValue(r_name.ToUpper(), out Container_file val)) ? val : null;
            tf.open();

            if (!string.IsNullOrEmpty(fname))
            {
                if (tf.Cat is null)
                {
                    tf.Cat = new V8Catalog(tf.Stream, false, true);
                }
                c = tf.Cat;
                for (i = fname.IndexOf("\\"); i != -1; i = fname.IndexOf("\\"))
                {
                    f = c.GetFile(fname.Substring(1, i - 1));
                    if (f is null)
                    {
                        return(null);
                    }
                    c = f.GetCatalog();
                    if (c is null)
                    {
                        return(null);
                    }
                    fname = fname.Substring(i + 1, fname.Length - i);
                }
                f = c.GetFile(fname);
                if (f is null)
                {
                    return(null);
                }
                if (!f.Open())
                {
                    return(null);
                }
                cf          = new ConfigFile();
                cfa         = new ConfigStorageTable_addin();
                cfa.variant = ConfigStorageTableAddinVariant.cstav_v8file;
                cfa.f       = f;
                cf.str      = f.GetData();
                cf.str.Seek(0, SeekOrigin.Begin);
                cf.addin = cfa;
            }
            else
            {
                cf          = new ConfigFile();
                cfa         = new ConfigStorageTable_addin();
                cfa.variant = ConfigStorageTableAddinVariant.cstav_container_file;
                cfa.tf      = tf;
                cf.str      = tf.Stream;
                cf.str.Seek(0, SeekOrigin.Begin);
                cf.addin = cfa;
            }
            return(cf);
        }
Beispiel #5
0
        public ConfigStorageTableConfigCasSave(TableFiles tabc, TableFiles tabcs, Guid uid, String configver, Tools1CD _base = null)
        {
            int            m;
            String         s, name, hashname;
            TableFile      _configinfo;
            Container_file configinfo;
            Tree           tt;
            Tree           ct;
            TableFile      tf;
            Container_file pcf;
            MemoryStream   stream;
            string         g;
            int            gl;

            //std::map<String, table_file*>::iterator ptf;


            ready = tabc.getready();
            if (!ready)
            {
                return;
            }
            ready = tabcs.getready();
            if (!ready)
            {
                return;
            }

            configinfo = null;
            present    = tabcs.gettable().Getbase().Getfilename() + "\\CONFIGCASSAVE";

            //g = GUID_to_string(uid) + L"__";
            g  = uid.ToString() + "__";
            gl = g.Length;

            foreach (var item_files in tabcs.files)
            {
                if (item_files.Key.Substring(1, gl).CompareTo(g) == 0)
                {
                    tf  = item_files.Value;
                    pcf = new Container_file(tf, tf.Name.Substring(gl + 1, tf.Name.Length - gl));
                    if (pcf.Name.CompareTo("configinfo") == 0)
                    {
                        configinfo = pcf;
                    }
                    files[pcf.Name.ToUpper()] = pcf;
                }
            }

            if (configinfo is null)
            {
                if (files.Count == 0)
                {
                    //error(L"Ошибка поиска файла"
                    //    , L"Путь", present
                    //    , L"Имя", g + L"configinfo"
                    //    , L"Имя файла", L"configinfo");
                    return;
                }

                s           = tabc.gettable().Getbase().Getfilename() + "\\CONFIGCAS\\" + configver;
                _configinfo = tabc.getfile(configver);
                if (_configinfo is null)
                {
                    // error(L"Ошибка поиска файла"
                    //     , L"Путь", s
                    //     , L"Имя", configver
                    //     , L"Имя файла", L"configinfo");
                    return;
                }

                configinfo          = new Container_file(_configinfo, "configinfo");
                files["CONFIGINFO"] = configinfo;
            }
            else
            {
                s = present + "\\" + gl + "configinfo";
            }

            configinfo.open();
            tt = Tree.Parse_1Cstream(configinfo.stream, "", s);
            if (tt is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = tt.Get_First();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = ct.Get_Next();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = ct.Get_Next();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = ct.Get_First();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }

            stream = new MemoryStream();
            for (m = Convert.ToInt32(ct.Get_Value()); m != 0; --m)
            {
                ct = ct.Get_Next();
                if (ct is null)
                {
                    //error(L"Ошибка разбора файла configinfo"
                    //    , L"Путь", s);
                    //delete tt;
                    stream.Dispose();
                    return;
                }
                if (ct.Get_Type() != Node_Type.nd_string)
                {
                    // error(L"Ошибка разбора файла configinfo"
                    //     , L"Путь", s);
                    // delete tt;
                    stream.Dispose();
                    return;
                }
                name = ct.Get_Value();

                ct = ct.Get_Next();

                if (files.TryGetValue(name.ToUpper(), out Container_file val))
                {
                    continue;
                }

                if (ct is null)
                {
                    //error(L"Ошибка разбора файла configinfo"
                    //    , L"Путь", s);
                    //delete tt;
                    stream.Dispose();
                    return;
                }
                if (ct.Get_Type() != Node_Type.nd_binary2)
                {
                    //error(L"Ошибка разбора файла configinfo"
                    //    , L"Путь", s);
                    //delete tt;
                    stream.Dispose();
                    return;
                }
                stream.Seek(0, SeekOrigin.Begin);

                //base64_decode(ct->get_value(), stream);

                byte[] data          = Convert.FromBase64String(ct.Get_Value());
                string decodedString = Encoding.UTF8.GetString(data);
                stream.Write(data, 0, data.Length);

                stream.Seek(0, SeekOrigin.Begin);
                hashname = hexstring(stream);

                tf = tabc.getfile(hashname);
                if (tf != null)
                {
                    pcf = new Container_file(tf, name);
                    files[name.ToUpper()] = pcf;
                }
                else
                {
                    // error(L"Ошибка поиска файла"
                    //     , L"Путь", s
                    //     , L"Имя", hashname
                    //     , L"Имя файла", name);
                    // delete tt;
                    stream.Dispose();
                    return;
                }
            }
            stream.Dispose();
        }
Beispiel #6
0
        public ConfigStorageTableConfigCas(TableFiles tabc, String configver, Tools1CD _base = null)
        {
            int            m;
            String         s, name, hashname;
            TableFile      _configinfo;
            Container_file configinfo;
            Tree           tt;
            Tree           ct;
            TableFile      tf;
            Container_file pcf;
            MemoryStream   stream;

            ready = tabc.getready();
            if (!ready)
            {
                return;
            }

            present = tabc.gettable().Getbase().Getfilename() + "\\CONFIGCAS";
            s       = present + "\\" + configver;

            _configinfo = tabc.getfile(configver);
            if (_configinfo is null)
            {
                // error(L"Ошибка поиска файла"
                //     , L"Путь", s
                //     , L"Имя", configver
                //     , L"Имя файла", L"configinfo");
                return;
            }

            configinfo          = new Container_file(_configinfo, "configinfo");
            files["CONFIGINFO"] = configinfo;
            configinfo.open();
            tt = Tree.Parse_1Cstream(configinfo.stream, "", s);
            if (tt is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = tt.Get_First();
            if (ct is null)
            {
                //error(L"Ошибка разбора файла configinfo"
                //    , L"Путь", s);
                //delete tt;
                return;
            }
            ct = ct.Get_Next();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = ct.Get_Next();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }
            ct = ct.Get_First();
            if (ct is null)
            {
                // error(L"Ошибка разбора файла configinfo"
                //     , L"Путь", s);
                // delete tt;
                return;
            }

            stream = new MemoryStream();
            for (m = Convert.ToInt32(ct.Get_Value()); m != 0; --m)
            {
                ct = ct.Get_Next();
                if (ct is null)
                {
                    // error(L"Ошибка разбора файла configinfo"
                    //     , L"Путь", s);
                    // delete tt;
                    // delete stream;
                    return;
                }
                if (ct.Get_Type() != Node_Type.nd_string)
                {
                    // error(L"Ошибка разбора файла configinfo"
                    //     , L"Путь", s);
                    // delete tt;
                    // delete stream;
                    return;
                }
                name = ct.Get_Value();

                ct = ct.Get_Next();
                if (ct is null)
                {
                    // error(L"Ошибка разбора файла configinfo"
                    //     , L"Путь", s);
                    // delete tt;
                    // delete stream;
                    return;
                }
                if (ct.Get_Type() != Node_Type.nd_binary2)
                {
                    // error(L"Ошибка разбора файла configinfo"
                    //     , L"Путь", s);
                    // delete tt;
                    // delete stream;
                    return;
                }
                stream.Seek(0, SeekOrigin.Begin);

                //base64_decode(ct->get_value(), stream);

                byte[] data          = Convert.FromBase64String(ct.Get_Value());
                string decodedString = Encoding.UTF8.GetString(data);
                stream.Write(data, 0, data.Length);

                stream.Seek(0, SeekOrigin.Begin);

                hashname = hexstring(stream);

                tf = tabc.getfile(hashname);
                if (tf != null)
                {
                    pcf = new Container_file(tf, name);
                    files[name.ToUpper()] = pcf;
                }
                else
                {
                    // error(L"Ошибка поиска файла"
                    //     , L"Путь", s
                    //     , L"Имя", hashname
                    //     , L"Имя файла", name);

                    stream.Dispose();
                    return;
                }
            }


            stream.Dispose();
        }